examples #11
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: Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| concurrency: ${{ github.workflow }}-${{ github.ref }} | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| changesets: | |
| name: Changesets | |
| runs-on: ubuntu-latest | |
| outputs: | |
| hasChangesets: ${{ steps.changesets-action.outputs.hasChangesets }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: oven-sh/setup-bun@v2 | |
| - run: bun install | |
| - name: Create Release Pull Request | |
| id: changesets-action | |
| uses: changesets/action@v1 | |
| with: | |
| version: bun run version | |
| title: "Release" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| version: | |
| name: Check version | |
| runs-on: ubuntu-latest | |
| needs: changesets | |
| if: needs.changesets.outputs.hasChangesets == 'false' | |
| outputs: | |
| cli-version: ${{ steps.check.outputs.version }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Check CLI version | |
| id: check | |
| run: | | |
| VERSION=$(node -p "require('./packages/cli/package.json').version") | |
| PUBLISHED=$(npm view @bunny.net/cli version 2>/dev/null || echo "0.0.0") | |
| if [ "$VERSION" != "$PUBLISHED" ]; then | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "New version detected: $VERSION (published: $PUBLISHED)" | |
| else | |
| echo "No version change: $VERSION" | |
| fi | |
| build-binaries: | |
| name: Build ${{ matrix.npm-pkg }} | |
| needs: version | |
| if: needs.version.outputs.cli-version | |
| strategy: | |
| matrix: | |
| include: | |
| - target: bun-linux-x64 | |
| os: ubuntu-latest | |
| npm-pkg: cli-linux-x64 | |
| binary: bunny | |
| - target: bun-linux-arm64 | |
| os: ubuntu-latest | |
| npm-pkg: cli-linux-arm64 | |
| binary: bunny | |
| - target: bun-darwin-x64 | |
| os: macos-latest | |
| npm-pkg: cli-darwin-x64 | |
| binary: bunny | |
| - target: bun-darwin-arm64 | |
| os: macos-latest | |
| npm-pkg: cli-darwin-arm64 | |
| binary: bunny | |
| - target: bun-windows-x64 | |
| os: ubuntu-latest | |
| npm-pkg: cli-windows-x64 | |
| binary: bunny.exe | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: oven-sh/setup-bun@v2 | |
| - run: bun install | |
| - name: Build binary | |
| run: bun build packages/cli/src/index.ts --compile --target=${{ matrix.target }} --outfile ${{ matrix.binary }} | |
| - name: Prepare npm package | |
| run: cp ${{ matrix.binary }} packages/${{ matrix.npm-pkg }}/ | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.npm-pkg }} | |
| path: packages/${{ matrix.npm-pkg }}/ | |
| if-no-files-found: error | |
| publish: | |
| name: Publish | |
| runs-on: ubuntu-latest | |
| needs: | |
| - version | |
| - build-binaries | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| registry-url: "https://registry.npmjs.org" | |
| - name: Download all platform artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: npm-artifacts | |
| - name: Copy binaries into npm packages | |
| run: | | |
| for pkg in cli-linux-x64 cli-linux-arm64 cli-darwin-x64 cli-darwin-arm64 cli-windows-x64; do | |
| cp -r npm-artifacts/$pkg/* packages/$pkg/ | |
| done | |
| - name: Publish platform packages | |
| run: | | |
| for pkg in cli-linux-x64 cli-linux-arm64 cli-darwin-x64 cli-darwin-arm64 cli-windows-x64; do | |
| cd packages/$pkg | |
| npm publish --access public | |
| cd ../.. | |
| done | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Publish @bunny.net/cli | |
| run: | | |
| cd packages/cli | |
| npm publish --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Create GitHub release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ needs.version.outputs.cli-version }} | |
| name: v${{ needs.version.outputs.cli-version }} | |
| generate_release_notes: true | |
| - name: Upload binaries to release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ needs.version.outputs.cli-version }} | |
| files: | | |
| npm-artifacts/cli-linux-x64/bunny | |
| npm-artifacts/cli-linux-arm64/bunny | |
| npm-artifacts/cli-darwin-x64/bunny | |
| npm-artifacts/cli-darwin-arm64/bunny | |
| npm-artifacts/cli-windows-x64/bunny.exe | |
| fail_on_unmatched_files: true |