Build and Publish #858
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 | |
| on: | |
| schedule: | |
| - cron: '0 0 * * *' # This will run the action daily at midnight. | |
| workflow_dispatch: # This allows for manual triggering of the workflow. | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| build-and-publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # This fetches all history for all branches and tags | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| registry-url: 'https://registry.npmjs.org' | |
| cache: npm | |
| - name: Install Dependencies | |
| run: npm ci | |
| - name: Build | |
| run: npm run build | |
| env: | |
| REPLICATE_API_TOKEN: ${{ secrets.REPLICATE_API_TOKEN }} | |
| - name: Remove large JSON before commit | |
| run: rm -f models.json | |
| - name: Check for changes | |
| run: | | |
| git diff --quiet && exit 0 || echo "Changes detected!" | |
| - name: Run Tests | |
| run: npm test | |
| - name: Create build branch | |
| id: build_branch | |
| run: | | |
| BRANCH="automation/build-$(date +%Y%m%d%H%M%S)" | |
| echo "branch=$BRANCH" >> "$GITHUB_OUTPUT" | |
| git checkout -b "$BRANCH" | |
| - name: Commit build artifacts | |
| run: | | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| git add -A | |
| git commit -m "Build artifacts" || echo "No changes to commit" | |
| - name: Publish to npm | |
| run: npm version minor --force && npm publish | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Push build branch | |
| run: git push -u origin "${{ steps.build_branch.outputs.branch }}" | |
| - name: Open pull request | |
| if: success() | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| gh pr create \ | |
| --base main \ | |
| --head "${{ steps.build_branch.outputs.branch }}" \ | |
| --title "chore: update build artifacts" \ | |
| --body "This PR updates the generated build artifacts." \ | |
| --label "automation" || echo "PR already exists" | |
| - name: Enable auto-merge | |
| if: success() | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| gh pr merge --auto --merge "${{ steps.build_branch.outputs.branch }}" || echo "Auto-merge not enabled" | |