diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index ace637e..eec6f2a 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -8,7 +8,7 @@ on: 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();