Repository navigation
Publish domain collection to npm #96
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: Publish domain collection to npm | |
| on: | |
| schedule: | |
| - cron: "0 0 * * *" | |
| workflow_dispatch: | |
| inputs: | |
| allow-large-change: | |
| description: Allow a Normal domain count decrease over 25 percent | |
| required: false | |
| default: false | |
| type: boolean | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: npm-domain-collection-publish | |
| cancel-in-progress: false | |
| jobs: | |
| publish: | |
| name: Publish changed domains | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v7 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v7 | |
| with: | |
| node-version: "24" | |
| registry-url: "https://registry.npmjs.org" | |
| package-manager-cache: false | |
| - name: Update npm | |
| run: npm install -g npm@latest | |
| - name: Install pnpm | |
| run: npm install -g pnpm | |
| - name: Install dependencies | |
| run: pnpm install --no-lockfile | |
| - name: Run lint | |
| run: npm run lint | |
| - name: Run tests | |
| run: npm test | |
| - name: Build live domain artifacts | |
| run: npm run build | |
| - name: Download previous npm package | |
| id: previous | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| PackageName="@filteringdev/tinyshield-domain-collection" | |
| DownloadPreviousPackage() { | |
| rm -rf .build/previous | |
| mkdir -p .build/previous | |
| PreviousVersion="$(npm view "${PackageName}@latest" version)" || return 1 | |
| npm pack "${PackageName}@${PreviousVersion}" \ | |
| --pack-destination .build/previous \ | |
| --silent > /dev/null || return 1 | |
| mapfile -t Tarballs < <(find .build/previous -maxdepth 1 -type f -name '*.tgz' -print) | |
| if [[ "${#Tarballs[@]}" != "1" ]]; then | |
| echo "::warning::Expected one npm tarball, found ${#Tarballs[@]}" | |
| return 1 | |
| fi | |
| tar -xzf "${Tarballs[0]}" -C .build/previous || return 1 | |
| if [[ ! -f .build/previous/package/dist/manifest.json ]]; then | |
| echo "::warning::Downloaded package does not contain dist/manifest.json" | |
| return 1 | |
| fi | |
| } | |
| for Attempt in 1 2 3 4 5; do | |
| if DownloadPreviousPackage; then | |
| break | |
| fi | |
| if [[ "${Attempt}" == "5" ]]; then | |
| echo "::error::Unable to download ${PackageName}@latest after ${Attempt} attempts" | |
| exit 1 | |
| fi | |
| Delay=$((Attempt * 15)) | |
| echo "::warning::npm registry lookup failed; retrying in ${Delay} seconds" | |
| sleep "${Delay}" | |
| done | |
| echo "version=${PreviousVersion}" >> "${GITHUB_OUTPUT}" | |
| if [[ "${PreviousVersion}" == *-* ]]; then | |
| echo "prerelease=true" >> "${GITHUB_OUTPUT}" | |
| else | |
| echo "prerelease=false" >> "${GITHUB_OUTPUT}" | |
| fi | |
| - name: Compare domain manifests | |
| id: comparison | |
| shell: bash | |
| env: | |
| ALLOW_LARGE_CHANGE: ${{ inputs.allow-large-change || false }} | |
| FORCE_PUBLISH: ${{ steps.previous.outputs.prerelease }} | |
| run: | | |
| set -euo pipefail | |
| Arguments=(--previous-manifest ../.build/previous/package/dist/manifest.json) | |
| if [[ "${ALLOW_LARGE_CHANGE}" == "true" ]]; then | |
| Arguments+=(--allow-large-change) | |
| fi | |
| if [[ "${FORCE_PUBLISH}" == "true" ]]; then | |
| Arguments+=(--force-publish) | |
| fi | |
| npm run release:check -w builder -- "${Arguments[@]}" | |
| - name: Set next patch version | |
| if: steps.comparison.outputs.changed == 'true' | |
| run: | | |
| npm pkg set version="${{ steps.previous.outputs.version }}" | |
| npm version patch --no-git-tag-version --workspaces=false | |
| - name: Inspect publish contents | |
| if: steps.comparison.outputs.changed == 'true' | |
| run: npm run pack:check | |
| - name: Publish package | |
| if: steps.comparison.outputs.changed == 'true' | |
| run: npm publish --access public |