Automated contract update and publish #87
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: Automated contract update and publish | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| release_type: | |
| description: "Version increment type" | |
| required: true | |
| type: choice | |
| default: patch | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| - prerelease | |
| preid: | |
| description: "Pre-release identifier (e.g., rc, beta) — used only when release_type=prerelease" | |
| required: false | |
| type: string | |
| permissions: | |
| contents: write | |
| packages: write | |
| jobs: | |
| update-and-publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.PAT }} | |
| - name: Install pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: 10 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| registry-url: "https://registry.npmjs.org/" | |
| cache: 'pnpm' | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| - name: Install Dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Update Contracts | |
| run: pnpm run generate-contracts | |
| - name: Check for changes | |
| id: git-check | |
| run: | | |
| git diff --quiet && git diff --staged --quiet || echo "changes_detected=true" >> $GITHUB_OUTPUT | |
| - name: Configure Git | |
| if: steps.git-check.outputs.changes_detected == 'true' | |
| run: | | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| - name: Increment package version and commit | |
| if: steps.git-check.outputs.changes_detected == 'true' | |
| run: | | |
| # Increment version based on selected bump type and get the new version | |
| BUMP_TYPE="${{ github.event.inputs.release_type }}" | |
| PREID="${{ github.event.inputs.preid }}" | |
| echo "Selected version bump: $BUMP_TYPE" | |
| if [ "$BUMP_TYPE" = "prerelease" ] && [ -n "$PREID" ]; then | |
| echo "Using preid: $PREID" | |
| pnpm version "$BUMP_TYPE" --preid "$PREID" --no-git-tag-version | |
| else | |
| pnpm version "$BUMP_TYPE" --no-git-tag-version | |
| fi | |
| NEW_VERSION=$(node -p "require('./package.json').version") | |
| echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV | |
| # Commit all changes | |
| git add . | |
| git commit -m "chore: update contracts to v$NEW_VERSION" | |
| git push origin main | |
| - name: Build | |
| if: steps.git-check.outputs.changes_detected == 'true' | |
| run: pnpm build | |
| - name: Publish to npm | |
| if: steps.git-check.outputs.changes_detected == 'true' | |
| run: | | |
| echo "//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}" > ~/.npmrc | |
| pnpm publish --no-git-checks | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Setup Node.js for GitHub Packages | |
| if: steps.git-check.outputs.changes_detected == 'true' | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| registry-url: "https://npm.pkg.github.com" | |
| scope: "@roninbuilders" | |
| - name: Publish to GitHub Packages | |
| if: steps.git-check.outputs.changes_detected == 'true' | |
| run: pnpm publish --registry https://npm.pkg.github.com --no-git-checks | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create and push tag | |
| if: steps.git-check.outputs.changes_detected == 'true' | |
| run: | | |
| # Create and push tag only after successful npm publish | |
| echo "Preparing to tag version v$NEW_VERSION" | |
| if git rev-parse "v$NEW_VERSION" >/dev/null 2>&1; then | |
| echo "Tag v$NEW_VERSION already exists, skipping tag creation" | |
| else | |
| git tag "v$NEW_VERSION" | |
| git push origin "v$NEW_VERSION" | |
| fi | |
| - name: Create GitHub Release | |
| if: steps.git-check.outputs.changes_detected == 'true' | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.PAT }} | |
| with: | |
| tag_name: "v${{ env.NEW_VERSION }}" | |
| release_name: "Release v${{ env.NEW_VERSION }}" | |
| body: | | |
| Automated release with updated contracts. | |
| ## Changes | |
| - Synchronized with latest contract deployments | |
| draft: false | |
| prerelease: ${{ github.event.inputs.release_type == 'prerelease' }} |