Skip to content

Commit 88e4983

Browse files
committed
update release workflow
Signed-off-by: aabidsofi19 <mailtoaabid01@gmail.com>
1 parent c06c19e commit 88e4983

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed

.github/workflows/npm-publish.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ name: Publish Node.js Package
55

66
on:
77
release:
8-
types: [created]
8+
types: ["created"]
99
workflow_dispatch:
1010
inputs:
11-
release-type:
11+
release-version:
1212
required: true
1313

1414
jobs:
@@ -21,6 +21,7 @@ jobs:
2121
node-version: 16
2222
- run: |
2323
npm install
24+
2425
publish-gpr:
2526
needs: build
2627
runs-on: ubuntu-latest
@@ -34,6 +35,19 @@ jobs:
3435
node-version: 16
3536
registry-url: "https://registry.npmjs.org"
3637
scope: "@layer5"
37-
- run: npm publish --verbose
38+
39+
- name: Run npm release
40+
run: npm run release ${{ github.event.inputs.release-version || github.event.release.tag_name }}
41+
if: github.event_name == 'workflow_dispatch' || github.event_name == 'release'
42+
3843
env:
3944
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
45+
46+
- name: Commit and push version change
47+
uses: stefanzweifel/git-auto-commit-action@v4
48+
with:
49+
commit_user_name: l5io
50+
commit_user_email: ci@layer5.io
51+
commit_author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
52+
commit_options: "--signoff"
53+
commit_message: "[Release]: Bump version to ${{ github.event.inputs.release-version || github.event.release.tag_name }}"

release.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
// for building and release the package
4+
5+
// bump version
6+
const bump = (version) => {
7+
const packagePath = path.resolve(__dirname, "package.json");
8+
const package = require(packagePath);
9+
package.version = version;
10+
fs.writeFileSync(packagePath, JSON.stringify(package, null, 2));
11+
console.log("bumped version to " + version);
12+
};
13+
14+
// build
15+
const build = () => {
16+
// nothing here yet
17+
};
18+
19+
const publish = () => {
20+
// publish to npm
21+
const execSync = require("child_process").execSync;
22+
execSync("npm publish --verbose", { stdio: [0, 1, 2] });
23+
console.log("published to npm");
24+
};
25+
26+
// main
27+
const main = () => {
28+
const args = process.argv.slice(2);
29+
const version = args[0];
30+
if (!version) {
31+
console.error("version is required");
32+
process.exit(1);
33+
}
34+
try {
35+
bump(version);
36+
build();
37+
publish();
38+
console.log("done");
39+
} catch (e) {
40+
console.error(e);
41+
process.exit(1);
42+
}
43+
};
44+
45+
main();

0 commit comments

Comments
 (0)