Skip to content

Commit

Permalink
Automate the release process using github actions (#730)
Browse files Browse the repository at this point in the history
Signed-off-by: Scott Nichols <scott@chainguard.dev>
  • Loading branch information
n3wscott committed Oct 22, 2021
1 parent 7fe4b6a commit ae0dc5a
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 73 deletions.
31 changes: 0 additions & 31 deletions .github/workflows/draft-release.yaml

This file was deleted.

105 changes: 105 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: Release Pipeline

on:
push:
branches:
- release-*

jobs:
semver:
name: Calculate Next Release
runs-on: ubuntu-latest
outputs:
next: ${{ steps.ggsv.outputs.next}}
steps:
- name: Setup Go 1.17.x
uses: actions/setup-go@v2
with:
go-version: 1.17.x

- name: Install Dependencies
run: go install tableflip.dev/ggsv@latest

- name: Look at Ref
id: ggsv
run: |
NEXT=`ggsv next-patch $GITHUB_SERVER_URL/${{ github.repository }}.git ${{ github.ref }}`
echo "::set-output name=next::$NEXT"
mainmodule:
name: Release Main Module
runs-on: ubuntu-latest
needs: semver
steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Create Release ${{ needs.semver.outputs.next }}
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ needs.semver.outputs.next }}
release_name: Release ${{ needs.semver.outputs.next }}
prerelease: false

submodules:
name: Release Sub-Modules
runs-on: ubuntu-latest
needs:
- semver
- mainmodule
env:
VERSION: ${{ needs.semver.outputs.next }}
steps:
- name: Set up Go 1.17.x
uses: actions/setup-go@v2
with:
go-version: 1.17.x

- name: Checkout Code
uses: actions/checkout@v2
- run: git pull

- name: Update Modules
run: |
./hack/tag-release.sh
- name: Commit Repoint
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git diff-index --quiet HEAD || (git commit -a -m "Repoint modules for release ${{ needs.semver.outputs.next }}." --allow-empty && git push)
- name: Tag Modules
run: ./hack/tag-release.sh --tag --push

examples:
name: Update Examples
runs-on: ubuntu-latest
needs:
- semver
- mainmodule
- submodules
env:
VERSION: ${{ needs.semver.outputs.next }}
steps:
- name: Set up Go 1.17.x
uses: actions/setup-go@v2
with:
go-version: 1.17.x

- name: Checkout Code
uses: actions/checkout@v2
- run: git pull

- name: Update Examples
run: ./hack/tag-release.sh --samples

- name: Commit Repoint
env:
tag: ${{ matrix.module }}/${{ needs.semver.outputs.next }}
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git diff-index --quiet HEAD || (git commit -a -m "Repoint examples, post release ${{ needs.semver.outputs.next }}." --allow-empty && git push)
36 changes: 31 additions & 5 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,42 @@ For v1 releases, just perform a GitHub release flow, and that is it.

## Releasing v2.+

Releasing v2 is more tricky, the project has been broken into modules and are
released independently but there is a depency chain.
_Note_: What is released is controlled by
[hack/tag-release.sh](./hack/tag-release.sh) script. Make sure the modules and
go modules are up-to-date.

Using GitHub Actions,

Steps:

1. Create a branch, in the form `release-v<major>.<minor>`, i.e:

_Note_: Any tag that matches `v*` or `protocol*` will produce a draft GitHub
release using GitHub Actions.
```shell
branch=release-v2.1
git checkout -b $branch
git push -u origin $branch
```

Or using the GitHub UI: search for `release-v2.1` and then click create
branch.

2. Update the release description.

That's it.

---

_UPDATE_: The following document is not required when using GitHub Actions. We
will keep the process documented for manual usage of the shell script or 100%
manual.

Releasing v2 is more tricky, the project has been broken into modules and are
released independently but there is a dependency chain.

_Note_: The following steps assume the repo is checked out directly. Switch to
`origin` to the remote name used if using a fork with a remote.

Steps:
Manual Steps:

1. Create a branch, in the form `release-<major>.<minor>`, i.e:

Expand Down
88 changes: 51 additions & 37 deletions hack/tag-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,62 @@ set -o pipefail

# This is run after the major release is published.

VERSION=v2.5.0
# Uncomment for manual runs.
# VERSION=v2.5.0
if [[ -z "$VERSION" ]]; then
echo "Must provide VERSION in environment" 1>&2
exit 1
fi

# It is intended that this file is run locally. For a full release tag, confirm the version is correct, and then:
# ./hack/tag-release.sh --tag --push
# TODO: we could do this dynamically in the future.
MODULES=(
"protocol/amqp"
"protocol/stan"
"protocol/nats"
"protocol/nats_jetstream"
"protocol/pubsub"
"protocol/kafka_sarama"
"protocol/ws"
"observability/opencensus"
"observability/opentelemetry"
"sql"
"binding/format/protobuf"
)

CREATE_TAGS=0 # default is a dry run
PUSH_TAGS=0 # Assumes `upstream` is the remote name for sdk-go.
SAMPLES=0
REPOINT=(
"github.com/cloudevents/sdk-go/v2"
)

# TODO: we could do this dynamically in the future.
REPOINT_SAMPLES=(
"github.com/cloudevents/sdk-go/protocol/amqp/v2"
"github.com/cloudevents/sdk-go/protocol/stan/v2"
"github.com/cloudevents/sdk-go/protocol/nats/v2"
"github.com/cloudevents/sdk-go/protocol/nats_jetstream/v2"
"github.com/cloudevents/sdk-go/protocol/pubsub/v2"
"github.com/cloudevents/sdk-go/protocol/kafka_sarama/v2"
"github.com/cloudevents/sdk-go/protocol/ws/v2"
"github.com/cloudevents/sdk-go/observability/opencensus/v2"
"github.com/cloudevents/sdk-go/observability/opentelemetry/v2"
"github.com/cloudevents/sdk-go/sql/v2"
"github.com/cloudevents/sdk-go/binding/format/protobuf/v2"
"github.com/cloudevents/sdk-go/v2" # NOTE: this needs to be last.
)

# Pick one:
REMOTE="origin" # if checked out directly
#REMOTE="upstream" # if checked out with a fork

REPOINT=(
"github.com/cloudevents/sdk-go/v2"
)
# It is intended that this file is run locally. For a full release tag, confirm the version is correct, and then:
# ./hack/tag-release.sh --tag --push

# ------------------------------------------------------------------------------
# After this point it is script.
# ------------------------------------------------------------------------------
#
CREATE_TAGS=0 # default is a dry run
PUSH_TAGS=0 # Assumes `upstream` is the remote name for sdk-go.
SAMPLES=0

# Loop through arguments and process them
for arg in "$@"
Expand All @@ -41,20 +81,7 @@ do
# --samples is used to repoint the dep used for samples to the newly released submodules
--samples)
SAMPLES=1
REPOINT=(
"github.com/cloudevents/sdk-go/protocol/amqp/v2"
"github.com/cloudevents/sdk-go/protocol/stan/v2"
"github.com/cloudevents/sdk-go/protocol/nats/v2"
"github.com/cloudevents/sdk-go/protocol/nats_jetstream/v2"
"github.com/cloudevents/sdk-go/protocol/pubsub/v2"
"github.com/cloudevents/sdk-go/protocol/kafka_sarama/v2"
"github.com/cloudevents/sdk-go/protocol/ws/v2"
"github.com/cloudevents/sdk-go/observability/opencensus/v2"
"github.com/cloudevents/sdk-go/observability/opentelemetry/v2"
"github.com/cloudevents/sdk-go/sql/v2"
"github.com/cloudevents/sdk-go/binding/format/protobuf/v2"
"github.com/cloudevents/sdk-go/v2" # NOTE: this needs to be last.
)
REPOINT=$REPOINT_SAMPLES
shift
;;
esac
Expand Down Expand Up @@ -91,8 +118,8 @@ do
then
tag="$VERSION"
echo " repointing dep on $repoint@$tag"
go mod edit -dropreplace $repoint
go get -d $repoint@$tag
go mod edit -dropreplace $repoint
fi
go mod tidy
done
Expand All @@ -107,19 +134,6 @@ fi

echo --- Tagging ---

MODULES=(
"protocol/amqp"
"protocol/stan"
"protocol/nats"
"protocol/nats_jetstream"
"protocol/pubsub"
"protocol/kafka_sarama"
"protocol/ws"
"observability/opencensus"
"sql"
"binding/format/protobuf"
)

for i in "${MODULES[@]}"; do
tag=""
if [ "$i" = "" ]; then
Expand Down

0 comments on commit ae0dc5a

Please sign in to comment.