From 00e362ca7260de2d919a6bcf217ac65203d71a81 Mon Sep 17 00:00:00 2001 From: Rohit Durvasula <88731568+drohit-cb@users.noreply.github.com> Date: Thu, 2 May 2024 13:29:40 -0700 Subject: [PATCH] Add logic to do automated Github releases (#21) Add logic to create a new automated GH release whenever the version in package.json is bumped and merged into mainline. --- .github/workflows/release.yaml | 60 ++++++++++++++++++++++++++-------- package-lock.json | 4 +-- package.json | 2 +- 3 files changed, 50 insertions(+), 16 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index bce32b1..b08f1e4 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,27 +1,61 @@ name: Version 🔖 on: - release: - types: [created] + push: + branches: + - main + paths: + - 'package.json' concurrency: ${{ github.workflow }}-${{ github.ref }} jobs: - version: - name: Release + release: runs-on: ubuntu-latest environment: release permissions: - contents: read + contents: write id-token: write + steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Get version from package.json + id: package_version + run: echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT + + - name: Check if tag exists + id: check_tag + run: | + git fetch --tags + if git rev-parse "v${{ steps.package_version.outputs.VERSION }}" >/dev/null 2>&1; then + echo "::set-output name=EXISTS::true" + fi + + - name: Create Release + if: steps.check_tag.outputs.EXISTS != 'true' + uses: softprops/action-gh-release@v2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: v${{ steps.package_version.outputs.VERSION }} + name: Release v${{ steps.package_version.outputs.VERSION }} + draft: false + prerelease: false + generate_release_notes: true + make_latest: true + + - name: Setup node + uses: actions/setup-node@v4 + with: node-version: "20.x" registry-url: "https://registry.npmjs.org" - - run: npm install -g npm@^9.5.0 - - run: npm ci - - run: npm publish --provenance --access public - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Publish to NPM + run: | + npm install -g npm@^9.5.0 + npm ci + npm publish --provenance --access public + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/package-lock.json b/package-lock.json index 9102749..f932571 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@coinbase/staking-client-library-ts", - "version": "0.6.0", + "version": "0.7.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@coinbase/staking-client-library-ts", - "version": "0.6.0", + "version": "0.7.0", "license": "Apache-2.0", "dependencies": { "@ethereumjs/tx": "^5.1.0", diff --git a/package.json b/package.json index 23b9bae..fd5138a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@coinbase/staking-client-library-ts", - "version": "0.6.0", + "version": "0.7.0", "description": "Coinbase Staking API Typescript Library", "repository": "https://github.com/coinbase/staking-client-library-ts.git", "license": "Apache-2.0",