Skip to content

Commit

Permalink
feat: Integrate new release management
Browse files Browse the repository at this point in the history
  • Loading branch information
oliversalzburg committed May 27, 2024
1 parent a2ec783 commit a91a809
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 2 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
57 changes: 57 additions & 0 deletions .github/workflows/sync-action-inputs.yml
Original file line number Diff line number Diff line change
@@ -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"
7 changes: 5 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: QA
on:
pull_request:
push:
workflow_call:

jobs:
qa:
Expand All @@ -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
Expand Down
82 changes: 82 additions & 0 deletions .scripts/manifest-version.cjs
Original file line number Diff line number Diff line change
@@ -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);
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
repo_token: ${{ secrets.GITHUB_TOKEN }}
```
## Inputs
## Release Process
```shell
Expand Down

0 comments on commit a91a809

Please sign in to comment.