From a91a8099d1cec7555cd51ddffa86a3785e93468d Mon Sep 17 00:00:00 2001 From: Oliver Salzburg Date: Mon, 27 May 2024 22:43:26 +0200 Subject: [PATCH] feat: Integrate new release management --- .github/workflows/release.yml | 74 +++++++++++++++++++++ .github/workflows/sync-action-inputs.yml | 57 ++++++++++++++++ .github/workflows/test.yml | 7 +- .scripts/manifest-version.cjs | 82 ++++++++++++++++++++++++ README.md | 2 + 5 files changed, 220 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/sync-action-inputs.yml create mode 100644 .scripts/manifest-version.cjs diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..71eeacd --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,74 @@ +name: Release + +on: + push: + tags: + - "v*" + +jobs: + qa-tag: + name: Call QA + uses: ./.github/workflows/test.yml + + qa-successful-tag: + needs: qa-tag + name: Evaluate QA results + if: ( success() || failure() ) + runs-on: ubuntu-22.04 + steps: + - name: Success + if: ${{ !(contains(needs.*.result, 'failure')) }} + run: exit 0 + - name: Failure + if: ${{ contains(needs.*.result, 'failure') }} + run: exit 1 + + release: + needs: qa-successful-tag + name: Publish action + runs-on: ubuntu-22.04 + concurrency: lib-publish + permissions: + contents: write + id-token: write + packages: write + pull-requests: read + + steps: + - name: Checkout + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4 + + - name: Select NodeJS version + uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4 + env: + # renovate: datasource=docker depName=node versioning=node + NODE_VERSION: "20.13.1" + with: + node-version: ${{ env.NODE_VERSION }} + registry-url: https://registry.npmjs.org + + - name: Enable Corepack + run: corepack enable + + # Yarn dependencies cannot be cached until yarn is installed + # WORKAROUND: https://github.com/actions/setup-node/issues/531 + - name: Extract cached dependencies + uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4 + with: + cache: yarn + + - name: Install dependencies + run: yarn install + + - name: Build + run: yarn build + + - name: Determine release version + run: echo "RELEASE_VERSION=$(node .scripts/manifest-version.cjs)" >> $GITHUB_ENV + + - uses: oliversalzburg/action-automatic-semantic-releases@bc429dc1af8c036b5f8c11fef7bcb0becfd5064d # v0.0.13 + with: + draft: false + prerelease: false + repo_token: ${{ secrets.GITHUB_TOKEN }} + title: v${{ env.RELEASE_VERSION }} diff --git a/.github/workflows/sync-action-inputs.yml b/.github/workflows/sync-action-inputs.yml new file mode 100644 index 0000000..6f6cb03 --- /dev/null +++ b/.github/workflows/sync-action-inputs.yml @@ -0,0 +1,57 @@ +name: Sync Action Inputs + +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + update-doc: + permissions: + contents: write + pull-requests: write + runs-on: ubuntu-22.04 + + steps: + - name: Checkout + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4 + with: + fetch-depth: 0 # otherwise, you will failed to push refs to dest repo + + - name: Run auto-doc + uses: tj-actions/auto-doc@79cbc18cd7c4b037bb2fe25199cb14fef4bbad43 # v3 + + - name: Verify Changed files + uses: tj-actions/verify-changed-files@9ed3155b72ba709881c967f75611fc5852f773b9 # v13.1 + id: verify-changed-files + with: + files: | + README.md + + - name: Select NodeJS version + uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4 + env: + # renovate: datasource=docker depName=node versioning=node + NODE_VERSION: "20.13.1" + with: + node-version: ${{ env.NODE_VERSION }} + + - name: Enable Corepack + run: corepack enable + + - name: Install dependencies + run: yarn install + + - name: Format properly + run: yarn lint:prettier --write + + - name: Create Pull Request + if: steps.verify-changed-files.outputs.files_changed == 'true' + uses: peter-evans/create-pull-request@6d6857d36972b65feb161a90e484f2984215f83e # v6 + with: + base: main + title: "docs: Synchronize `README.md` with `action.yml`" + branch: fix/auto-doc-update-readme + commit-message: "docs: Synchronize README.md with action.yml" + body: "auto-doc: Updated README.md" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 07fecff..4eaeac4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,6 +3,7 @@ name: QA on: pull_request: push: + workflow_call: jobs: qa: @@ -15,9 +16,11 @@ jobs: - name: Select NodeJS version uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4 - with: + env: # renovate: datasource=docker depName=node versioning=node - node-version: "20.12.2" + NODE_VERSION: "20.13.1" + with: + node-version: ${{ env.NODE_VERSION }} - name: Enable Corepack run: corepack enable diff --git a/.scripts/manifest-version.cjs b/.scripts/manifest-version.cjs new file mode 100644 index 0000000..a9e5259 --- /dev/null +++ b/.scripts/manifest-version.cjs @@ -0,0 +1,82 @@ +"use strict"; + +const { execSync } = require("node:child_process"); +const { resolve } = require("node:path"); + +const pkg = require(resolve("./package.json")); + +const options = process.argv.slice(2).reduce((args, arg) => { + const [key, value] = arg.split("="); + args[key.substring(2)] = value ?? true; + + return args; +}, {}); + +function getRootVersion(bump = true) { + let rootVersion = pkg.version.replace(/^(\d+\.\d+\.\d+)-?.*$/, "$1"); + + if (bump) { + const parts = rootVersion.split("."); + const inc = bump ? 1 : 0; + + switch (options.canary?.toLowerCase()) { + case "major": { + parts[0] = `${+parts[0] + inc}`; + parts[1] = 0; + parts[2] = 0; + break; + } + case "minor": { + parts[1] = `${+parts[0] + inc}`; + parts[2] = 0; + break; + } + case "patch": + default: + parts[2] = `${+parts[2] + inc}`; + } + + rootVersion = parts.join("."); + } + + return rootVersion; +} + +function getNextVersion() { + const versions = []; + + try { + const versionString = execSync(`npm show ${pkg.name} versions --json`, { + encoding: "utf8", + stdio: "pipe", + }); + const parsed = JSON.parse(versionString); + versions.push(...parsed); + } catch { + // the package might not have been published yet + } + + const version = getRootVersion(options.canary ?? false); + + if (versions.some(v => v === version)) { + console.error( + `before-deploy: A release with version ${version} already exists. Please increment version accordingly.`, + ); + process.exit(1); + } + + if (!options.canary) { + return version; + } + + const preid = options.preid ?? "dev"; + const prereleaseNumbers = versions + .filter(v => v.startsWith(`${version}-${preid}.`)) + .map(v => Number(v.match(/\.(\d+)$/)?.[1])); + const lastPrereleaseNumber = Math.max(-1, ...prereleaseNumbers); + + return `${version}-${preid}.${lastPrereleaseNumber + 1}`; +} + +const versionString = getNextVersion(); +process.stdout.write(versionString); diff --git a/README.md b/README.md index ccc3b64..76361a3 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,8 @@ repo_token: ${{ secrets.GITHUB_TOKEN }} ``` +## Inputs + ## Release Process ```shell