From 88e498313830b8ee20bdf9f5fb1d9f0e1274b925 Mon Sep 17 00:00:00 2001 From: aabidsofi19 Date: Thu, 21 Dec 2023 12:49:48 +0530 Subject: [PATCH 1/2] update release workflow Signed-off-by: aabidsofi19 --- .github/workflows/npm-publish.yml | 20 +++++++++++--- release.js | 45 +++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 release.js diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index ace637e..e8e28b9 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -5,10 +5,10 @@ name: Publish Node.js Package on: release: - types: [created] + types: ["created"] workflow_dispatch: inputs: - release-type: + release-version: required: true jobs: @@ -21,6 +21,7 @@ jobs: node-version: 16 - run: | npm install + publish-gpr: needs: build runs-on: ubuntu-latest @@ -34,6 +35,19 @@ jobs: node-version: 16 registry-url: "https://registry.npmjs.org" scope: "@layer5" - - run: npm publish --verbose + + - name: Run npm release + run: npm run release ${{ github.event.inputs.release-version || github.event.release.tag_name }} + if: github.event_name == 'workflow_dispatch' || github.event_name == 'release' + env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Commit and push version change + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_user_name: l5io + commit_user_email: ci@layer5.io + commit_author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> + commit_options: "--signoff" + commit_message: "[Release]: Bump version to ${{ github.event.inputs.release-version || github.event.release.tag_name }}" diff --git a/release.js b/release.js new file mode 100644 index 0000000..c8806b5 --- /dev/null +++ b/release.js @@ -0,0 +1,45 @@ +const fs = require("fs"); +const path = require("path"); +// for building and release the package + +// bump version +const bump = (version) => { + const packagePath = path.resolve(__dirname, "package.json"); + const package = require(packagePath); + package.version = version; + fs.writeFileSync(packagePath, JSON.stringify(package, null, 2)); + console.log("bumped version to " + version); +}; + +// build +const build = () => { + // nothing here yet +}; + +const publish = () => { + // publish to npm + const execSync = require("child_process").execSync; + execSync("npm publish --verbose", { stdio: [0, 1, 2] }); + console.log("published to npm"); +}; + +// main +const main = () => { + const args = process.argv.slice(2); + const version = args[0]; + if (!version) { + console.error("version is required"); + process.exit(1); + } + try { + bump(version); + build(); + publish(); + console.log("done"); + } catch (e) { + console.error(e); + process.exit(1); + } +}; + +main(); From efadee81c000e29bdbd91a2333403bb8acb3433d Mon Sep 17 00:00:00 2001 From: aabidsofi19 Date: Thu, 21 Dec 2023 12:53:28 +0530 Subject: [PATCH 2/2] fix trigger Signed-off-by: aabidsofi19 --- .github/workflows/npm-publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index e8e28b9..eec6f2a 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -5,7 +5,7 @@ name: Publish Node.js Package on: release: - types: ["created"] + types: [created] workflow_dispatch: inputs: release-version: