Automate CLI releases and remove retired commands #5
Workflow file for this run
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: | |
| tags: | |
| - "v*" | |
| jobs: | |
| verify: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: actions/setup-node@v6 | |
| with: | |
| node-version: "22" | |
| cache: npm | |
| - run: npm ci | |
| - run: npm audit --audit-level=high | |
| - name: Verify release tag | |
| env: | |
| RELEASE_TAG: ${{ github.ref_name }} | |
| run: >- | |
| node -e "const { version } = require('./package.json'); | |
| if (process.env.RELEASE_TAG !== 'v' + version) | |
| throw new Error('Release tag must be v' + version);" | |
| - run: npm test | |
| - run: npm pack --dry-run | |
| build-and-release: | |
| needs: verify | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| - name: Install dependencies | |
| run: bun install | |
| - name: Build binaries for all platforms | |
| run: bun run scripts/build-binary.ts --cross | |
| - name: Create GitHub Release and upload binaries | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| if gh release view "${{ github.ref_name }}" >/dev/null 2>&1; then | |
| gh release upload "${{ github.ref_name }}" dist-bin/* --clobber | |
| else | |
| gh release create "${{ github.ref_name }}" \ | |
| dist-bin/* \ | |
| --title "${{ github.ref_name }}" \ | |
| --generate-notes | |
| fi | |
| publish-npm: | |
| needs: build-and-release | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: npm | |
| url: https://www.npmjs.com/package/search1api-cli | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: actions/setup-node@v6 | |
| with: | |
| node-version: "24" | |
| registry-url: https://registry.npmjs.org | |
| package-manager-cache: false | |
| - run: npm ci | |
| - name: Publish package | |
| run: | | |
| PACKAGE_SPEC=$(node -p "const packageJson = require('./package.json'); packageJson.name + '@' + packageJson.version") | |
| if npm view "$PACKAGE_SPEC" version >/dev/null 2>&1; then | |
| echo "$PACKAGE_SPEC is already published" | |
| else | |
| npm publish | |
| fi |