Skip to content

Commit 5dd5ad1

Browse files
ci: Rebuild pipelines
1 parent 9a7472e commit 5dd5ad1

File tree

4 files changed

+188
-95
lines changed

4 files changed

+188
-95
lines changed

.github/workflows/pull-request.yml

Lines changed: 0 additions & 89 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
jobs:
9+
qa-tag:
10+
name: Call QA
11+
uses: ./.github/workflows/test.yml
12+
13+
qa-successful-tag:
14+
needs: qa-tag
15+
name: Evaluate QA results
16+
if: ( success() || failure() )
17+
runs-on: ubuntu-22.04
18+
steps:
19+
- name: Success
20+
if: ${{ !(contains(needs.*.result, 'failure')) }}
21+
run: exit 0
22+
- name: Failure
23+
if: ${{ contains(needs.*.result, 'failure') }}
24+
run: exit 1
25+
26+
release:
27+
needs: qa-successful-tag
28+
name: Publish action
29+
runs-on: ubuntu-22.04
30+
concurrency: lib-publish
31+
permissions:
32+
contents: write
33+
id-token: write
34+
packages: write
35+
pull-requests: read
36+
37+
steps:
38+
- name: Checkout
39+
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4
40+
41+
- name: Select NodeJS version
42+
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4
43+
env:
44+
# renovate: datasource=docker depName=node versioning=node
45+
NODE_VERSION: "20.13.1"
46+
with:
47+
node-version: ${{ env.NODE_VERSION }}
48+
registry-url: https://registry.npmjs.org
49+
50+
- name: Enable Corepack
51+
run: corepack enable
52+
53+
# Yarn dependencies cannot be cached until yarn is installed
54+
# WORKAROUND: https://github.com/actions/setup-node/issues/531
55+
- name: Extract cached dependencies
56+
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4
57+
with:
58+
cache: yarn
59+
60+
- name: Install dependencies
61+
run: yarn install
62+
63+
- name: Build
64+
run: yarn build
65+
66+
- name: Determine release version
67+
run: echo "RELEASE_VERSION=$(node .scripts/manifest-version.cjs)" >> $GITHUB_ENV
68+
69+
- uses: oliversalzburg/action-automatic-semantic-releases@bc429dc1af8c036b5f8c11fef7bcb0becfd5064d # v0.0.13
70+
with:
71+
draft: false
72+
prerelease: false
73+
repo_token: ${{ secrets.GITHUB_TOKEN }}
74+
title: v${{ env.RELEASE_VERSION }}

.github/workflows/test.yml

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
name: Node.JS Tests
1+
name: QA
22

33
on:
4+
pull_request:
45
push:
5-
branches:
6-
- "main"
6+
workflow_call:
77

88
jobs:
9-
qa-main:
9+
qa-branch:
1010
name: Run QA
1111
strategy:
1212
matrix:
@@ -18,6 +18,7 @@ jobs:
1818
- ubuntu-latest
1919
- windows-latest
2020
runs-on: ${{ matrix.os-release }}
21+
2122
steps:
2223
- name: Checkout
2324
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4
@@ -35,14 +36,39 @@ jobs:
3536

3637
- name: Lint
3738
run: yarn lint
39+
- name: Build
40+
run: yarn build
3841
- name: Test
3942
run: yarn test
4043

41-
qa-successful-main:
44+
qa-docs:
45+
name: QA Documentation
4246
runs-on: ubuntu-22.04
47+
steps:
48+
- name: Checkout
49+
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4
50+
51+
- name: Select Python version
52+
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5
53+
env:
54+
# renovate: datasource=docker depName=python versioning=semver
55+
PYTHON_VERSION: "3.x"
56+
with:
57+
python-version: ${{ env.PYTHON_VERSION }}
58+
59+
- name: Install mkdocs-material
60+
run: pip install mkdocs-material
61+
62+
- name: Build documentation
63+
run: mkdocs build
64+
65+
qa-successful:
4366
needs:
44-
- qa-main
67+
- qa-branch
68+
- qa-docs
69+
name: Evaluate QA results
4570
if: always()
71+
runs-on: ubuntu-22.04
4672
steps:
4773
- name: Success
4874
if: ${{ !(contains(needs.*.result, 'failure')) }}

.scripts/manifest-version.cjs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
"use strict";
2+
3+
const { execSync } = require("node:child_process");
4+
const { resolve } = require("node:path");
5+
6+
const pkg = require(resolve("./package.json"));
7+
8+
const options = process.argv.slice(2).reduce((args, arg) => {
9+
const [key, value] = arg.split("=");
10+
args[key.substring(2)] = value ?? true;
11+
12+
return args;
13+
}, {});
14+
15+
function getRootVersion(bump = true) {
16+
let rootVersion = pkg.version.replace(/^(\d+\.\d+\.\d+)-?.*$/, "$1");
17+
18+
if (bump) {
19+
const parts = rootVersion.split(".");
20+
const inc = bump ? 1 : 0;
21+
22+
switch (options.canary?.toLowerCase()) {
23+
case "major": {
24+
parts[0] = `${+parts[0] + inc}`;
25+
parts[1] = 0;
26+
parts[2] = 0;
27+
break;
28+
}
29+
case "minor": {
30+
parts[1] = `${+parts[0] + inc}`;
31+
parts[2] = 0;
32+
break;
33+
}
34+
case "patch":
35+
default:
36+
parts[2] = `${+parts[2] + inc}`;
37+
}
38+
39+
rootVersion = parts.join(".");
40+
}
41+
42+
return rootVersion;
43+
}
44+
45+
function getNextVersion() {
46+
const versions = [];
47+
48+
try {
49+
const versionString = execSync(`npm show ${pkg.name} versions --json`, {
50+
encoding: "utf8",
51+
stdio: "pipe",
52+
});
53+
const parsed = JSON.parse(versionString);
54+
versions.push(...parsed);
55+
} catch {
56+
// the package might not have been published yet
57+
}
58+
59+
const version = getRootVersion(options.canary ?? false);
60+
61+
if (versions.some(v => v === version)) {
62+
console.error(
63+
`before-deploy: A release with version ${version} already exists. Please increment version accordingly.`,
64+
);
65+
process.exit(1);
66+
}
67+
68+
if (!options.canary) {
69+
return version;
70+
}
71+
72+
const preid = options.preid ?? "dev";
73+
const prereleaseNumbers = versions
74+
.filter(v => v.startsWith(`${version}-${preid}.`))
75+
.map(v => Number(v.match(/\.(\d+)$/)?.[1]));
76+
const lastPrereleaseNumber = Math.max(-1, ...prereleaseNumbers);
77+
78+
return `${version}-${preid}.${lastPrereleaseNumber + 1}`;
79+
}
80+
81+
const versionString = getNextVersion();
82+
process.stdout.write(versionString);

0 commit comments

Comments
 (0)