generated from oliversalzburg/nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Integrate new release management
- Loading branch information
1 parent
a2ec783
commit a91a809
Showing
5 changed files
with
220 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,8 @@ | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | ||
``` | ||
## Inputs | ||
## Release Process | ||
```shell | ||
|