Skip to content

Automated contract update and publish #85

Automated contract update and publish

Automated contract update and publish #85

name: Automated contract update and publish
on:
schedule:
- cron: "0 0 * * *" # Runs daily at midnight
workflow_dispatch: # Allows manual trigger
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 and get the new version
pnpm version patch --no-git-tag-version
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
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: false