Allow npm release recovery branches #275
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: CI | |
| on: | |
| push: | |
| workflow_call: | |
| workflow_dispatch: | |
| inputs: | |
| release_version: | |
| description: Version to publish to npm and GitHub Packages | |
| required: true | |
| type: string | |
| jobs: | |
| lint: | |
| runs-on: ubuntu-24.04 | |
| outputs: | |
| version: ${{ steps.version.outputs.version }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v7 | |
| with: | |
| fetch-depth: 0 | |
| - name: Build Reason | |
| run: "echo ref: ${{github.ref}} event: ${{github.event_name}}" | |
| - name: Build Version | |
| id: version | |
| env: | |
| GIT_REF: ${{ github.ref }} | |
| VERSION_OVERRIDE: ${{ inputs.release_version }} | |
| run: | | |
| if [ -n "$VERSION_OVERRIDE" ]; then | |
| version="$VERSION_OVERRIDE" | |
| elif [[ "$GIT_REF" == refs/heads/release/npm/* ]]; then | |
| version="${GIT_REF#refs/heads/release/npm/}" | |
| else | |
| dotnet tool install --global minver-cli --version 7.0.0 | |
| version=$(minver --tag-prefix v) | |
| fi | |
| echo "version=$version" >> $GITHUB_OUTPUT | |
| echo "### Version: $version" >> $GITHUB_STEP_SUMMARY | |
| - name: Setup Deno | |
| uses: denoland/setup-deno@v2 | |
| with: | |
| deno-version: v2.x | |
| - name: Code Style | |
| run: deno fmt --check | |
| - name: Linting | |
| run: deno lint | |
| - name: Type Check | |
| run: deno task check | |
| deno: | |
| runs-on: ubuntu-24.04 | |
| needs: lint | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v7 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Deno | |
| uses: denoland/setup-deno@v2 | |
| with: | |
| deno-version: v2.x | |
| - name: Tests | |
| run: | | |
| deno test --allow-net --coverage=cov/ src/tests | |
| deno coverage cov/ | |
| - name: Publish Release Package | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| run: deno publish --set-version ${{ needs.lint.outputs.version }} | |
| npm: | |
| runs-on: ubuntu-24.04 | |
| needs: lint | |
| permissions: | |
| contents: read | |
| packages: write | |
| id-token: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v7 | |
| with: | |
| fetch-depth: 0 | |
| - uses: denoland/setup-deno@v2 | |
| with: | |
| deno-version: v2.x | |
| - name: Build NPM Package | |
| run: deno task build --set-version ${{ needs.lint.outputs.version }} | |
| - name: Add NPM Package Metadata | |
| env: | |
| REPOSITORY_URL: https://github.com/${{ github.repository }} | |
| run: | | |
| package_dir=$(mktemp -d) | |
| tar -xzf fetchclient.tgz -C "$package_dir" | |
| PACKAGE_JSON="$package_dir/package/package.json" deno eval ' | |
| const path = Deno.env.get("PACKAGE_JSON"); | |
| const repositoryUrl = Deno.env.get("REPOSITORY_URL"); | |
| const packageJson = JSON.parse(await Deno.readTextFile(path)); | |
| packageJson.repository = { type: "git", url: repositoryUrl }; | |
| await Deno.writeTextFile(path, `${JSON.stringify(packageJson, null, 2)}\n`); | |
| ' | |
| tar -czf fetchclient.tgz -C "$package_dir" package | |
| - name: Show NPM Package | |
| run: tar -xOf fetchclient.tgz package/package.json | |
| - name: Setup Node.js environment | |
| uses: actions/setup-node@v7 | |
| with: | |
| node-version: "24.x" | |
| registry-url: "https://registry.npmjs.org" | |
| scope: "@foundatiofx" | |
| - name: Publish Release Package | |
| if: startsWith(github.ref, 'refs/tags/v') || startsWith(github.ref, 'refs/heads/release/npm/') || github.event_name == 'workflow_dispatch' | |
| run: npm publish fetchclient.tgz --provenance --access public | |
| - name: Setup GitHub CI Node.js environment | |
| if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') || startsWith(github.ref, 'refs/heads/release/npm/') || github.event_name == 'workflow_dispatch' | |
| uses: actions/setup-node@v7 | |
| with: | |
| node-version: "24.x" | |
| registry-url: "https://npm.pkg.github.com" | |
| scope: "@foundatiofx" | |
| - name: Push GitHub CI Packages | |
| if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') || startsWith(github.ref, 'refs/heads/release/npm/') || github.event_name == 'workflow_dispatch' | |
| run: | | |
| package="@foundatiofx/fetchclient@${{ needs.lint.outputs.version }}" | |
| if npm view "$package" version --registry https://npm.pkg.github.com > /dev/null 2>&1; then | |
| echo "$package already exists in GitHub Packages; skipping publish." | |
| else | |
| npm publish fetchclient.tgz --tag ${{ (startsWith(github.ref, 'refs/tags/v') || startsWith(github.ref, 'refs/heads/release/npm/') || github.event_name == 'workflow_dispatch') && 'latest' || 'next' }} --access public | |
| fi | |
| env: | |
| NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} |