From ccdaa65e3895bd5ddb5aac0f8d497b73a1b8319e Mon Sep 17 00:00:00 2001 From: Liam Bigelow <40188355+bglw@users.noreply.github.com> Date: Wed, 20 Mar 2024 11:36:48 +1300 Subject: [PATCH] Upgrade rosey publishing to the new cc-oss bot --- .backstage/get_tag.cjs | 22 +++++++ .github/workflows/release.yml | 113 ++++++++++++++++++++++++++-------- 2 files changed, 110 insertions(+), 25 deletions(-) create mode 100644 .backstage/get_tag.cjs diff --git a/.backstage/get_tag.cjs b/.backstage/get_tag.cjs new file mode 100644 index 0000000..35981c0 --- /dev/null +++ b/.backstage/get_tag.cjs @@ -0,0 +1,22 @@ +const version = process.env.GIT_VERSION; + +if (!version) { + console.error("Script expected a GIT_VERSION environment variable"); + process.exit(1); +} + +// Only allow latest tag if we are releasing a major/minor/patch +if (/^\d+\.\d+\.\d+$/.test(version)) { + console.log("latest"); + process.exit(0); +} + +// Use the suffix as the tag. i.e. `0.11.0-rc5` -> `rc` +const suffix = version.match(/^\d+\.\d+\.\d+-([a-z]+)/i)?.[1]; +if (suffix) { + console.log(suffix.toLowerCase()); + process.exit(0); +} + +// Fall back to an unknown tag for safety +console.log("unknown"); \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e167150..83d5fd3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,9 +18,9 @@ jobs: needs: publish-github-release steps: - name: Clone - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Cache - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: | ~/.cargo/registry @@ -67,7 +67,7 @@ jobs: working-directory: ./wrappers/node steps: - name: Clone - uses: actions/checkout@v2 + uses: actions/checkout@v3 - uses: actions/download-artifact@v3 with: name: release-checksums @@ -89,39 +89,95 @@ jobs: run: working-directory: ./ steps: + - name: Get Token + id: get_workflow_token + uses: peter-murray/workflow-application-token-action@v2 + with: + application_id: ${{ secrets.CC_OSS_BOT_ID }} + application_private_key: ${{ secrets.CC_OSS_BOT_PEM }} - name: Clone - uses: actions/checkout@v2 - - name: Get Version - run: echo GIT_VERSION="$(git describe --tags | sed 's/^v\(.*\)$/\1/')" >> $GITHUB_ENV + uses: actions/checkout@v3 + with: + token: ${{ steps.get_workflow_token.outputs.token }} - name: Swap to main - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: ref: main fetch-depth: 0 # Full fetch + token: ${{ steps.get_workflow_token.outputs.token }} + + - name: Get Version + run: echo GIT_VERSION="$(git describe --tags | sed 's/^v\(.*\)$/\1/')" >> $GITHUB_ENV + - name: Get Tag + run: echo GIT_TAG="$(node ./.backstage/get_tag.cjs)" >> $GITHUB_ENV + - uses: actions/download-artifact@v3 with: name: release path: build-artifacts - - name: Build Changelog + + - name: Build CHANGELOG + if: env.GIT_TAG == 'latest' run: | node ./.backstage/changelog.cjs write - git config user.email "github-actions[bot]@users.noreply.github.com" - git config user.name "github-actions[bot]" - git add ./CHANGELOG.md - git commit -m "Changelog for $GIT_VERSION" - git push - git checkout production-docs - git merge --no-ff main -m "Release documentation for $GIT_VERSION" - git push + echo CHANGELOG=\"$(base64 -w 0 -i CHANGELOG.md)\" >> $GITHUB_ENV + echo SHA=\"$( git rev-parse main:CHANGELOG.md )\" >> $GITHUB_ENV + - name: Build CHANGELOG + if: env.GIT_TAG != 'latest' + run: | + echo "## Prerelease" > RELEASE.md + node ./.backstage/changelog.cjs write || true + + - name: Commit new CHANGELOG + uses: octokit/request-action@v2.x + if: env.GIT_TAG == 'latest' + id: push_changes + with: + route: PUT /repos/{owner}/{repo}/contents/CHANGELOG.md + owner: cloudcannon + repo: rosey + branch: main + message: Changelog for ${{ env.GIT_VERSION }} + sha: ${{ env.SHA }} + content: ${{ env.CHANGELOG }} + env: + GITHUB_TOKEN: ${{ steps.get_workflow_token.outputs.token }} + - name: Release documentation branch + uses: octokit/request-action@v2.x + if: env.GIT_TAG == 'latest' + id: merge_docs + with: + route: POST /repos/{owner}/{repo}/merges + owner: cloudcannon + repo: rosey + base: production-docs + head: main + commit_message: Release documentation for ${{ env.GIT_VERSION }} + env: + GITHUB_TOKEN: ${{ steps.get_workflow_token.outputs.token }} + - name: Release uses: softprops/action-gh-release@v1 - if: startsWith(github.ref, 'refs/tags/') + if: startsWith(github.ref, 'refs/tags/') && env.GIT_TAG == 'latest' with: + repository: cloudcannon/rosey + prerelease: false body_path: RELEASE.md files: | build-artifacts/* env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ steps.get_workflow_token.outputs.token }} + - name: Release + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') && env.GIT_TAG != 'latest' + with: + repository: cloudcannon/rosey + prerelease: true + body_path: RELEASE.md + files: | + build-artifacts/* + env: + GITHUB_TOKEN: ${{ steps.get_workflow_token.outputs.token }} test-and-build: name: Test and Build @@ -152,12 +208,12 @@ jobs: musl: false steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 1 - name: Cache - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: | ~/.cargo/registry @@ -174,8 +230,11 @@ jobs: # From https://github.com/Emoun/duplicate/blob/master/.github/workflows/rust.yml - name: Get Version run: echo GIT_VERSION="$(git describe --tags | sed 's/^v\(.*\)$/\1/')" >> $GITHUB_ENV + - name: Get Tag + run: echo GIT_TAG="$(node ./.backstage/get_tag.cjs)" >> $GITHUB_ENV - name: Verify Changelog + if: env.GIT_TAG == 'latest' run: | node ./.backstage/changelog.cjs @@ -189,12 +248,16 @@ jobs: run: | sudo apt update sudo apt install -y musl-tools musl-dev - - name: Install Rust - run: | - rustup install ${{ matrix.rust }} - rustup target add ${{ matrix.target }} - rustup show + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + target: ${{ matrix.target }} + override: true + default: true + components: rustfmt, clippy + - name: Install humane uses: supplypike/setup-bin@v1 with: