Publish New Package Version #10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| name: Build And Publish Package Update | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| package: | |
| type: choice | |
| description: Package name | |
| options: | |
| - offchain-manager | |
| - addresses | |
| - indexer | |
| - mint-manager | |
| jobs: | |
| build-and-publish: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Use Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 24 | |
| registry-url: 'https://registry.npmjs.org/' | |
| # - name: Authenticate with NmpJS | |
| # run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc | |
| - name: Install dependencies (root) | |
| run: yarn install --frozen-lockfile | |
| - name: Build selected package | |
| run: yarn workspace @thenamespace/${{ inputs.package }} build | |
| - name: Determine new version | |
| id: versioning | |
| run: | | |
| PACKAGE="${{ inputs.package }}" | |
| LATEST_TAG=$(git tag --list "*-${PACKAGE}" --sort=-v:refname | head -n 1) | |
| if [ -z "$LATEST_TAG" ]; then | |
| NEW_VERSION="1.0.0-$PACKAGE" | |
| else | |
| BASE_VERSION=${LATEST_TAG%-*} | |
| IFS='.' read -r MAJOR MINOR PATCH <<< "$BASE_VERSION" | |
| PATCH=$((PATCH + 1)) | |
| NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}-$PACKAGE" | |
| fi | |
| echo "New version: $NEW_VERSION" | |
| # Set the version as output | |
| echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
| - name: Update package version in package.json | |
| working-directory: packages/${{ inputs.package }} | |
| env: | |
| version: ${{ steps.versioning.outputs.version }} | |
| run: npm version $version --no-git-tag-version | |
| - name: Publish package to npm registry | |
| working-directory: packages/${{ inputs.package }} | |
| run: npm publish | |
| - name: Commit and push version bump and tag | |
| env: | |
| version: ${{ steps.versioning.outputs.version }} | |
| package: ${{ inputs.package }} | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| # Commit the updated package.json with new version | |
| git add packages/$package/package.json | |
| git commit -m "chore($package): bump version to $version" | |
| # Create a tag with the version | |
| git tag -a "$version" -m "Release $version" | |
| # Push commit and tag | |
| git push origin HEAD | |
| git push origin "$version" |