Skip to content

Commit ad6aa85

Browse files
committed
chore(ci): upgrade publish process
Signed-off-by: mttrbrts <code@rbrts.uk>
1 parent b624ebe commit ad6aa85

4 files changed

Lines changed: 112 additions & 21 deletions

File tree

.github/workflows/build.yml

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,54 @@ name: Build
22

33
on:
44
push:
5+
branches:
6+
- main
57
pull_request:
68
branches:
79
- main
810

11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: true
14+
915
jobs:
1016
build:
1117
name: Unit Tests
1218

1319
strategy:
1420
matrix:
1521
node-version:
16-
- 18.x
1722
- 20.x
23+
- 22.x
1824
os:
19-
- ubuntu-latest
2025
- windows-latest
21-
- macOS-latest
26+
- macos-latest
27+
- ubuntu-latest
2228

2329
runs-on: ${{ matrix.os }}
2430

2531
steps:
2632
- name: git checkout
27-
uses: actions/checkout@v2
33+
uses: actions/checkout@v4
2834

2935
- name: Use Node.js ${{ matrix.node-version }}
30-
uses: actions/setup-node@v1
36+
uses: actions/setup-node@v4
3137
with:
3238
node-version: ${{ matrix.node-version }}
39+
cache: 'npm'
3340

3441
- run: npm ci
3542
- run: npm run build --if-present
36-
- run: npm test
43+
- env:
44+
NODE_OPTIONS: "--max_old_space_size=4096"
45+
run: npm test
46+
47+
- name: Archive npm failure logs
48+
uses: actions/upload-artifact@v4
49+
if: failure() && runner.os == 'Windows'
50+
with:
51+
name: npm-logs
52+
path: C:\npm\cache\_logs\
3753

3854
- name: Calculate code coverage
3955
run: npm run coverage
@@ -76,15 +92,16 @@ jobs:
7692

7793
steps:
7894
- name: git checkout
79-
uses: actions/checkout@v2
95+
uses: actions/checkout@v4
8096

8197
- name: Use Node.js 18.x
82-
uses: actions/setup-node@v1
98+
uses: actions/setup-node@v4
8399
with:
84100
node-version: 18.x
85-
86-
- name: Build
87-
run: npm ci
101+
cache: 'npm'
102+
103+
- run: npm ci
104+
- run: npm run build --if-present
88105

89106
- name: timestamp
90107
id: timestamp
@@ -93,7 +110,7 @@ jobs:
93110
94111
- name: build and publish
95112
run: |
96-
export NODE_OPTIONS="--max_old_space_size=6144"
97113
npm config set //registry.npmjs.org/:_authToken ${{ secrets.NPM_TOKEN }}
114+
node ./scripts/bump_version.js ${{ steps.timestamp.outputs.stamp }}
98115
npm version --workspaces --include-workspace-root --no-git-tag-version --yes --exact ${{ steps.timestamp.outputs.stamp }}
99-
npm publish --workspaces --access public --tag=unstable 2>&1
116+
npm publish --workspaces --access public --tag=unstable 2>&1

.github/workflows/publish.yml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,31 @@ name: Publish
33
on:
44
release:
55
types:
6-
- released
6+
- published
7+
8+
permissions:
9+
id-token: write # Required for OIDC / npmjs publish
710

811
jobs:
912
publish:
1013
name: Publish to npm
1114
if: ${{ github.repository_owner == 'accordproject' }}
1215
runs-on: ubuntu-latest
16+
environment: production
1317

1418
steps:
1519
- name: git checkout
16-
uses: actions/checkout@v2
20+
uses: actions/checkout@v4
1721

18-
- name: Use Node.js 18.x
19-
uses: actions/setup-node@v1
22+
- name: Use Node.js 20.x
23+
uses: actions/setup-node@v4
2024
with:
21-
node-version: 18.x
25+
node-version: '20'
26+
registry-url: 'https://registry.npmjs.org'
27+
cache: 'npm'
28+
29+
# Ensure npm 11.5.1 or later for trusted publishing
30+
- run: npm install -g npm@latest
2231

2332
- run: npm ci
2433
- run: npm run build --if-present
@@ -30,13 +39,13 @@ jobs:
3039
3140
- name: build and publish
3241
run: |
33-
export NODE_OPTIONS="--max_old_space_size=6144"
3442
npm config set //registry.npmjs.org/:_authToken ${{ secrets.NPM_TOKEN }}
43+
node ./scripts/bump_version.js ${{ github.event.release.tag_name }}
3544
npm version --workspaces --include-workspace-root --no-git-tag-version --yes --exact ${{ github.event.release.tag_name }}
3645
npm publish --workspaces --access public ${{ steps.tag.outputs.tag }} 2>&1
3746
3847
- name: Create PR to increment version
39-
uses: peter-evans/create-pull-request@v3
48+
uses: peter-evans/create-pull-request@v7
4049
with:
4150
base: main
4251
commit-message: 'chore(actions): publish ${{ github.event.release.tag_name }} to npm'

scripts/bump_version.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env node
2+
/*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
'use strict';
17+
18+
const fs = require('fs');
19+
const glob = require('glob');
20+
21+
/**
22+
* This script updates the devDependencies and dependencies in the workspaces
23+
* to match the version specified by the given parameter.
24+
* The expected parameter should be the tag for the package.
25+
*
26+
* Example:
27+
* node ./scripts/bump_version.js <tag>
28+
*/
29+
30+
const workspacesPattern = 'packages/**/package.json'; // Adjust this pattern based on your workspace setup
31+
const packageNames = [
32+
"@accordproject/markdown-cicero",
33+
"@accordproject/markdown-cli",
34+
"@accordproject/markdown-common",
35+
"@accordproject/markdown-html",
36+
"@accordproject/markdown-it-cicero",
37+
"@accordproject/markdown-it-template",
38+
"@accordproject/markdown-template",
39+
"@accordproject/markdown-transform",
40+
];
41+
42+
function bumpDependencies() {
43+
const targetPackageVersion = process.argv[2].replace(/^v/, '');
44+
const workspacePackages = glob.sync(workspacesPattern, {
45+
ignore: ['**/node_modules/**', '**/test/**'],
46+
});
47+
48+
workspacePackages.forEach((packagePath) => {
49+
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
50+
51+
['dependencies', 'devDependencies'].forEach((depType) => {
52+
packageNames.forEach(dep => {
53+
if (packageJson[depType] && (dep in packageJson[depType])) {
54+
packageJson[depType][dep] = targetPackageVersion;
55+
}
56+
});
57+
});
58+
59+
fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2) + '\n', 'utf8');
60+
});
61+
62+
console.log('Dependencies updated successfully!');
63+
}
64+
65+
bumpDependencies();

scripts/timestamp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ dayjs.extend(utc);
2424
const timestamp = dayjs.utc().format('YYYYMMDDHHmmss');
2525

2626
const rootDirectory = path.resolve('.');
27-
const rootConfigFile = path.resolve(rootDirectory, 'lerna.json');
27+
const rootConfigFile = path.resolve(rootDirectory, 'package.json');
2828
const rootConfig = require(rootConfigFile);
2929
rootConfig.version.replace(/-.*/, '');
3030
const targetVersion = semver.inc(rootConfig.version, 'patch') + '-' + timestamp;

0 commit comments

Comments
 (0)