From 448fab9e8a8e068c81873f06f674915ec08d8dc5 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 1 Nov 2023 08:40:43 +0000 Subject: [PATCH] New release automations (#3813) --- .github/release-drafter.yml | 26 +++++ .github/workflows/release-drafter.yml | 14 +++ .github/workflows/release-master.yml | 56 ++++++++++ .github/workflows/release-npm.yml | 3 +- .github/workflows/release.yml | 152 +++++++++++++++++++++++++- docs/SUMMARY.md | 1 + docs/release.md | 24 ++++ 7 files changed, 269 insertions(+), 7 deletions(-) create mode 100644 .github/release-drafter.yml create mode 100644 .github/workflows/release-drafter.yml create mode 100644 .github/workflows/release-master.yml create mode 100644 docs/release.md diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 00000000000..462af3942ca --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,26 @@ +name-template: "v$RESOLVED_VERSION" +tag-template: "v$RESOLVED_VERSION" +change-template: "* $TITLE ([#$NUMBER]($URL)). Contributed by @$AUTHOR." +categories: + - title: "🚨 BREAKING CHANGES" + label: "X-Breaking-Change" + - title: "🦖 Deprecations" + label: "T-Deprecation" + - title: "✨ Features" + label: "T-Enhancement" + - title: "🐛 Bug Fixes" + label: "T-Defect" + - title: "🧰 Maintenance" + label: "Dependencies" + collapse-after: 5 +change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks. +version-resolver: + major: + labels: + - "X-Breaking-Change" + default: minor +template: | + $CHANGES +prerelease: true +prerelease-identifier: rc +include-pre-releases: false diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml new file mode 100644 index 00000000000..3ce2b5a2af1 --- /dev/null +++ b/.github/workflows/release-drafter.yml @@ -0,0 +1,14 @@ +name: Release Drafter +on: + push: + branches: [staging] +concurrency: ${{ github.workflow }} +jobs: + draft: + runs-on: ubuntu-latest + steps: + - uses: release-drafter/release-drafter@dabcf3767562210392d862070ed2ef6434b9bc6f # v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + disable-autolabeler: true diff --git a/.github/workflows/release-master.yml b/.github/workflows/release-master.yml new file mode 100644 index 00000000000..b328af07093 --- /dev/null +++ b/.github/workflows/release-master.yml @@ -0,0 +1,56 @@ +# Gitflow merge-back master->develop +name: Merge master -> develop +on: + push: + branches: [master] +concurrency: ${{ github.workflow }} +jobs: + merge: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + token: ${{ secrets.ELEMENT_BOT_TOKEN }} + fetch-depth: 0 + + - uses: actions/setup-node@v3 + with: + cache: "yarn" + + - name: Install Deps + run: "yarn install --frozen-lockfile" + + - name: Set up git + run: | + git config --global user.email "releases@riot.im" + git config --global user.name "RiotRobot" + + - name: Merge to develop + run: | + git checkout develop + git merge -X ours master + + - name: Update package.json fields + run: | + # When merging to develop, we need revert the `main` and `typings` fields if we adjusted them previously. + for i in main typings browser + do + # If a `lib` prefixed value is present, it means we adjusted the field + # earlier at publish time, so we should revert it now. + if [ "$(jq -r ".matrix_lib_$i" package.json)" != "null" ]; then + # If there's a `src` prefixed value, use that, otherwise delete. + # This is used to delete the `typings` field and reset `main` back to the TypeScript source. + src_value=$(jq -r ".matrix_src_$i" package.json) + if [ "$src_value" != "null" ]; then + jq ".$i = .matrix_src_$i" package.json > package.json.new && mv package.json.new package.json && yarn prettier --write package.json + else + jq "del(.$i)" package.json > package.json.new && mv package.json.new package.json && yarn prettier --write package.json + fi + fi + done + + - name: Commit and push changes + run: | + git add package.json + git commit -m "Resetting package fields for development" + git push origin develop diff --git a/.github/workflows/release-npm.yml b/.github/workflows/release-npm.yml index ea05fb27973..3c091537eb1 100644 --- a/.github/workflows/release-npm.yml +++ b/.github/workflows/release-npm.yml @@ -1,4 +1,3 @@ -# Must only be called from `release#published` triggers name: Publish to npm on: workflow_call: @@ -32,7 +31,7 @@ jobs: ignore-scripts: false - name: 🎖️ Add `latest` dist-tag to final releases - if: github.event.release.prerelease == false && steps.npm-publish.outputs.id + if: steps.npm-publish.outputs.id && !contains(steps.npm-publish.outputs.id, '-rc.') run: npm dist-tag add "$release" latest env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 01e66783ae9..ad2de269a36 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,11 +1,148 @@ name: Release Process on: - release: - types: [published] -concurrency: ${{ github.workflow }}-${{ github.ref }} + workflow_dispatch: + inputs: + mode: + description: What type of release + required: true + default: rc + type: choice + options: + - rc + - final + docs: + description: Publish docs + required: true + type: boolean + default: true + npm: + description: Publish to npm + required: true + type: boolean + default: true +concurrency: ${{ github.workflow }} jobs: - jsdoc: + release: + runs-on: ubuntu-latest + steps: + - name: Get draft release + id: release + uses: cardinalby/git-get-release-action@cedef2faf69cb7c55b285bad07688d04430b7ada # v1 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + draft: true + latest: true + + - uses: actions/checkout@v4 + with: + ref: staging + token: ${{ secrets.ELEMENT_BOT_TOKEN }} + fetch-depth: 0 + + - uses: actions/setup-node@v3 + with: + cache: "yarn" + + - name: Install Deps + run: "yarn install --frozen-lockfile" + + - name: Load version + run: echo "VERSION=$VERSION" >> $GITHUB_ENV + env: + VERSION: ${{ steps.release.outputs.tag_name }} + + - name: Finalise version + if: inputs.mode == 'final' + run: echo "VERSION=$(echo $VERSION | cut -d- -f1)" >> $GITHUB_ENV + + - name: Bump package.json version + run: yarn version --no-git-tag-version --new-version "$VERSION" + + - name: Add to CHANGELOG.md + if: inputs.mode == 'final' + run: | + mv CHANGELOG.md CHANGELOG.md.old + HEADER="Changes in [${VERSION#v}](https://github.com/${{ github.repository }}/releases/tag/$VERSION) ($(date '+%Y-%m-%d'))" + + { + echo "$HEADER" + printf '=%.0s' $(seq ${#HEADER}) + echo "" + echo "$BODY" + echo "" + } > CHANGELOG.md + + cat CHANGELOG.md.old >> CHANGELOG.md + rm CHANGELOG.md.old + env: + BODY: ${{ steps.release.outputs.body }} + + # For the published and dist versions of the package, + # we copy the `matrix_lib_main` and `matrix_lib_typings` fields to `main` and `typings` (if they exist). + # This small bit of gymnastics allows us to use the TypeScript source directly for development without + # needing to build before linting or testing. + - name: Update package.json fields + run: | + for i in main typings browser + do + lib_value=$(jq -r ".matrix_lib_$i" package.json) + if [ "$lib_value" != "null" ]; then + jq ".$i = .matrix_lib_$i" package.json > package.json.new && mv package.json.new package.json && yarn prettier --write package.json + fi + done + + - name: Set up git + run: | + git config --global user.email "releases@riot.im" + git config --global user.name "RiotRobot" + + - name: Commit and push changes + run: | + git add package.json CHANGELOG.md + git commit -m "$VERSION" + git push origin staging + + - name: Merge to master + if: inputs.mode == 'final' + run: | + git checkout master + git merge -X theirs staging + git push origin master + + - name: Publish release + uses: actions/github-script@v6 + id: my-script + env: + RELEASE_ID: ${{ steps.release.outputs.id }} + MODE: ${{ inputs.mode }} + with: + result-encoding: string + retries: 3 + script: | + let { RELEASE_ID: release_id, VERSION, MODE } = process.env; + const { owner, repo } = context.repo; + + const opts = { + owner, + repo, + release_id, + tag_name: VERSION, + name: VERSION, + draft: false, + }; + + if (MODE === "final") { + opts.prerelease = false; + opts.make_latest = true; + } + + github.rest.repos.updateRelease(opts); + + docs: name: Publish Documentation + needs: release + if: inputs.docs runs-on: ubuntu-latest steps: - name: 🧮 Checkout code @@ -36,10 +173,13 @@ jobs: yarn gendoc symlinks -rc _docs - - name: 🚀 Deploy + - name: 🔨 Set up git run: | git config --global user.email "releases@riot.im" git config --global user.name "RiotRobot" + + - name: 🚀 Deploy + run: | git add . --all git commit -m "Update docs" git push @@ -47,6 +187,8 @@ jobs: npm: name: Publish + needs: release + if: inputs.npm uses: matrix-org/matrix-js-sdk/.github/workflows/release-npm.yml@develop secrets: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index e19198e62d0..8a1d7686eb2 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -4,5 +4,6 @@ # Deep dive +- [Release Process](release.md) - [Storage notes](storage-notes.md) - [Unverified devices](warning-on-unverified-devices.md) diff --git a/docs/release.md b/docs/release.md new file mode 100644 index 00000000000..7520abdc6e2 --- /dev/null +++ b/docs/release.md @@ -0,0 +1,24 @@ +# Release Process + +## Hotfix and off-cycle releases + +1. Prepare the `staging` branch by using the backport automation and manually merging +2. Go to [Releasing](#Releasing) + +## Release candidates + +1. Prepare the `staging` branch by running the [branch cut automation](https://github.com/vector-im/element-web/actions/workflows/release_prepare.yml) +2. Go to [Releasing](#Releasing) + +## Releasing + +1. Open the [Releases page](https://github.com/matrix-org/matrix-js-sdk/releases) and inspect the draft release there +2. Make any modifications to the release notes and tag/version as required +3. Run [workflow](https://github.com/matrix-org/matrix-js-sdk/actions/workflows/release.yml) with the type set appropriately + +## Artifacts + +Releasing the Matrix JS SDK has just two artifacts: + +- Package published to [npm](https://github.com/matrix-org/matrix-js-sdk) +- Docs published to [Github Pages](https://matrix-org.github.io/matrix-js-sdk/)