From ae0dc5aae6328d8a4cdeef43aa72fffb0d692dec Mon Sep 17 00:00:00 2001 From: Scott Nichols Date: Thu, 21 Oct 2021 21:03:08 -0700 Subject: [PATCH] Automate the release process using github actions (#730) Signed-off-by: Scott Nichols --- .github/workflows/draft-release.yaml | 31 -------- .github/workflows/release.yaml | 105 +++++++++++++++++++++++++++ RELEASING.md | 36 +++++++-- hack/tag-release.sh | 88 ++++++++++++---------- 4 files changed, 187 insertions(+), 73 deletions(-) delete mode 100644 .github/workflows/draft-release.yaml create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/draft-release.yaml b/.github/workflows/draft-release.yaml deleted file mode 100644 index a53fb31d7..000000000 --- a/.github/workflows/draft-release.yaml +++ /dev/null @@ -1,31 +0,0 @@ -on: - push: - # Sequence of patterns matched against refs/tags - tags: - - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 - - 'protocol/**' # Push events to matching protocol/foo/bar/v*, i.e. protocol/foo/bar/v1.0, protocol/foo/bar/v20.15.10 - - 'observability/**' # Push events to matching observability/foo/bar/v* - - 'sql/**' # Push events to matching sql/v* - - 'binding/**' # Push events to matching binding/foo/bar/v* - -name: Create Draft Releases - -jobs: - - release-tags: - name: draft-release - - runs-on: ubuntu-latest - - steps: - - - name: Create Draft Release - id: create_draft_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ github.ref }} - release_name: Release ${{ github.ref }} - draft: true - prerelease: false diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 000000000..de710cd8a --- /dev/null +++ b/.github/workflows/release.yaml @@ -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) diff --git a/RELEASING.md b/RELEASING.md index 6b5aac201..edba7c2e1 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -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.`, 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-.`, i.e: diff --git a/hack/tag-release.sh b/hack/tag-release.sh index 9a7058b8c..ca5e9b03c 100755 --- a/hack/tag-release.sh +++ b/hack/tag-release.sh @@ -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 "$@" @@ -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 @@ -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 @@ -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