docs(changeset): test #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: Main | |
| on: | |
| push: | |
| branches: [ main ] | |
| workflow_dispatch: | |
| concurrency: ${{ github.workflow }}-${{ github.ref }} | |
| jobs: | |
| ci: | |
| name: CI | |
| uses: ./.github/workflows/shared-ci.yml | |
| publish: | |
| name: Publish | |
| runs-on: macos-latest | |
| needs: ci | |
| steps: | |
| - name: Checkout Repo | |
| uses: actions/checkout@v4 | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v1 | |
| with: | |
| bun-version: latest | |
| - name: Cache Bun dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.bun/install/cache | |
| key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-bun- | |
| - name: Install Dependencies | |
| run: bun install | |
| - name: Build | |
| run: bun run build | |
| - name: Setup Node.js for NPM | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '24' | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Create Release Pull Request or Publish to NPM | |
| id: changesets | |
| uses: changesets/action@v1 | |
| with: | |
| publish: bun run release | |
| version: bun run version | |
| commit: "chore: release package" | |
| title: "chore: release package" | |
| createGithubReleases: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} | |
| - name: Get version | |
| if: steps.changesets.outputs.published == 'true' | |
| run: echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV | |
| - name: Build executables | |
| if: steps.changesets.outputs.published == 'true' | |
| run: | | |
| # macOS (Intel) | |
| bun build src/cli.ts --compile --outfile dependency-optimizer-macos-x64 | |
| # macOS (Apple Silicon) | |
| bun build src/cli.ts --compile --outfile dependency-optimizer-macos-arm64 --target=bun-darwin-arm64 | |
| # Linux | |
| bun build src/cli.ts --compile --outfile dependency-optimizer-linux-x64 --target=bun-linux-x64 | |
| # Windows | |
| bun build src/cli.ts --compile --outfile dependency-optimizer-windows-x64.exe --target=bun-windows-x64 | |
| - name: Upload executables to release | |
| if: steps.changesets.outputs.published == 'true' | |
| uses: actions/github-script@v7 | |
| env: | |
| VERSION: ${{ env.VERSION }} | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const fs = require('fs'); | |
| const tag = `v${process.env.VERSION}`; | |
| const release = await octokit.rest.repos.getReleaseByTag({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| tag: tag | |
| }); | |
| const executables = [ | |
| { name: 'dependency-optimizer-macos-x64', path: 'dependency-optimizer-macos-x64' }, | |
| { name: 'dependency-optimizer-macos-arm64', path: 'dependency-optimizer-macos-arm64' }, | |
| { name: 'dependency-optimizer-linux-x64', path: 'dependency-optimizer-linux-x64' }, | |
| { name: 'dependency-optimizer-windows-x64.exe', path: 'dependency-optimizer-windows-x64.exe' } | |
| ]; | |
| for (const exe of executables) { | |
| if (fs.existsSync(exe.path)) { | |
| const file = fs.readFileSync(exe.path); | |
| await octokit.rest.repos.uploadReleaseAsset({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| release_id: release.data.id, | |
| name: exe.name, | |
| data: file | |
| }); | |
| } | |
| } |