Skip to content

Commit

Permalink
Merge pull request #9 from aabidsofi19/ci/release-workflow
Browse files Browse the repository at this point in the history
[CI] Update release workflow
  • Loading branch information
aabidsofi19 authored Dec 21, 2023
2 parents 0a94977 + efadee8 commit 976cf03
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
types: [created]
workflow_dispatch:
inputs:
release-type:
release-version:
required: true

jobs:
Expand All @@ -21,6 +21,7 @@ jobs:
node-version: 16
- run: |
npm install
publish-gpr:
needs: build
runs-on: ubuntu-latest
Expand All @@ -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 }}"
45 changes: 45 additions & 0 deletions release.js
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit 976cf03

Please sign in to comment.