docs: export cache utilities and document download cache feature #88
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 npm | |
| on: | |
| push: | |
| branches: | |
| - main | |
| release: | |
| types: | |
| - published | |
| env: | |
| FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true" | |
| permissions: | |
| contents: read | |
| id-token: write | |
| concurrency: | |
| group: npm-publish-${{ github.event_name }}-${{ github.ref || github.event.release.tag_name || github.run_id }} | |
| cancel-in-progress: false | |
| jobs: | |
| publish-dev: | |
| if: github.ref == 'refs/heads/main' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 24 | |
| cache: npm | |
| cache-dependency-path: package-lock.json | |
| registry-url: https://registry.npmjs.org | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Verify npm publish prerequisites | |
| run: npm run publish:check-prereqs | |
| - name: Run tests | |
| run: npm test | |
| - name: Build package | |
| run: npm run build | |
| - name: Resolve development version | |
| id: version | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| HAGISCRIPT_REQUIRE_UNRELEASED_TAG: "1" | |
| run: | | |
| version="$(npm run --silent publish:prepare-dev-version)" | |
| echo "version=$version" >> "$GITHUB_OUTPUT" | |
| echo "Resolved dev version: $version" | |
| - name: Stamp development package version | |
| env: | |
| DEV_VERSION: ${{ steps.version.outputs.version }} | |
| run: npm version --no-git-tag-version "$DEV_VERSION" | |
| - name: Verify packed files | |
| run: npm run pack:check | |
| - name: Run installed package runtime integration test | |
| run: npm run integration:installed-runtime | |
| - name: Publish to npm dev dist-tag | |
| id: publish | |
| env: | |
| DEV_VERSION: ${{ steps.version.outputs.version }} | |
| NPM_CONFIG_PROVENANCE: "true" | |
| run: | | |
| if npm view "@hagicode/hagiscript@$DEV_VERSION" version --registry https://registry.npmjs.org >/dev/null 2>&1; then | |
| echo "Version $DEV_VERSION is already published on npm; skipping dev publish." | |
| echo "result=skipped" >> "$GITHUB_OUTPUT" | |
| { | |
| echo "### Publish gate" | |
| echo | |
| echo "Version $DEV_VERSION already exists on npm. Skipped duplicate dev publish." | |
| } >> "$GITHUB_STEP_SUMMARY" | |
| exit 0 | |
| fi | |
| publish_log="$(mktemp)" | |
| set +e | |
| npm publish --tag dev --provenance --access public 2>&1 | tee "$publish_log" | |
| publish_exit="${PIPESTATUS[0]}" | |
| set -e | |
| if [ "$publish_exit" -ne 0 ]; then | |
| { | |
| echo "### npm publish output" | |
| echo | |
| echo '```text' | |
| tail -n 200 "$publish_log" | |
| echo '```' | |
| } >> "$GITHUB_STEP_SUMMARY" | |
| exit "$publish_exit" | |
| fi | |
| echo "result=published" >> "$GITHUB_OUTPUT" | |
| - name: Summarize publish result | |
| if: always() | |
| env: | |
| RESOLVED_VERSION: ${{ steps.version.outputs.version || 'n/a' }} | |
| JOB_STATUS: ${{ job.status }} | |
| PUBLISH_RESULT: ${{ steps.publish.outputs.result || '' }} | |
| run: | | |
| { | |
| echo "## npm dev publish" | |
| echo | |
| echo "- Version: $RESOLVED_VERSION" | |
| echo "- Dist-tag: dev" | |
| echo "- Registry: npmjs.org" | |
| if [ "$JOB_STATUS" = "success" ] && [ "$PUBLISH_RESULT" = "published" ]; then | |
| echo "- Result: published with provenance enabled." | |
| elif [ "$JOB_STATUS" = "success" ] && [ "$PUBLISH_RESULT" = "skipped" ]; then | |
| echo "- Result: skipped because this version is already present on npm." | |
| else | |
| echo "- Result: failed before publish completed. Check the failed gate above." | |
| fi | |
| } >> "$GITHUB_STEP_SUMMARY" | |
| publish-release: | |
| if: github.event_name == 'release' && github.event.action == 'published' && !github.event.release.prerelease && !github.event.release.draft | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.release.tag_name }} | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 24 | |
| cache: npm | |
| cache-dependency-path: package-lock.json | |
| registry-url: https://registry.npmjs.org | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Verify release tag matches package version | |
| id: version | |
| env: | |
| RELEASE_TAG_NAME: ${{ github.event.release.tag_name }} | |
| run: | | |
| version="$(npm run --silent publish:verify-release -- "$RELEASE_TAG_NAME")" | |
| echo "version=$version" >> "$GITHUB_OUTPUT" | |
| echo "Validated release version: $version" | |
| - name: Stamp stable package version | |
| env: | |
| RELEASE_VERSION: ${{ steps.version.outputs.version }} | |
| run: npm version --no-git-tag-version "$RELEASE_VERSION" | |
| - name: Verify npm publish prerequisites | |
| run: npm run publish:check-prereqs | |
| - name: Run tests | |
| run: npm test | |
| - name: Build package | |
| run: npm run build | |
| - name: Verify packed files | |
| run: npm run pack:check | |
| - name: Run installed package runtime integration test | |
| run: npm run integration:installed-runtime | |
| - name: Publish to npm latest dist-tag | |
| id: publish | |
| env: | |
| RELEASE_VERSION: ${{ steps.version.outputs.version }} | |
| NPM_CONFIG_PROVENANCE: "true" | |
| run: | | |
| if npm view "@hagicode/hagiscript@$RELEASE_VERSION" version --registry https://registry.npmjs.org >/dev/null 2>&1; then | |
| echo "Version $RELEASE_VERSION is already published on npm; skipping stable publish." | |
| echo "result=skipped" >> "$GITHUB_OUTPUT" | |
| { | |
| echo "### Publish gate" | |
| echo | |
| echo "Version $RELEASE_VERSION already exists on npm. Skipped duplicate stable publish." | |
| } >> "$GITHUB_STEP_SUMMARY" | |
| exit 0 | |
| fi | |
| publish_log="$(mktemp)" | |
| set +e | |
| npm publish --tag latest --provenance --access public 2>&1 | tee "$publish_log" | |
| publish_exit="${PIPESTATUS[0]}" | |
| set -e | |
| if [ "$publish_exit" -ne 0 ]; then | |
| { | |
| echo "### npm publish output" | |
| echo | |
| echo '```text' | |
| tail -n 200 "$publish_log" | |
| echo '```' | |
| } >> "$GITHUB_STEP_SUMMARY" | |
| exit "$publish_exit" | |
| fi | |
| echo "result=published" >> "$GITHUB_OUTPUT" | |
| - name: Summarize publish result | |
| if: always() | |
| env: | |
| RESOLVED_VERSION: ${{ steps.version.outputs.version || 'n/a' }} | |
| JOB_STATUS: ${{ job.status }} | |
| RELEASE_URL: ${{ github.event.release.html_url }} | |
| TAG_NAME: ${{ github.event.release.tag_name }} | |
| PUBLISH_RESULT: ${{ steps.publish.outputs.result || '' }} | |
| run: | | |
| { | |
| echo "## npm stable publish" | |
| echo | |
| echo "- Version: $RESOLVED_VERSION" | |
| echo "- Dist-tag: latest" | |
| echo "- Release: $RELEASE_URL" | |
| echo "- Tag: $TAG_NAME" | |
| echo "- Registry: npmjs.org" | |
| if [ "$JOB_STATUS" = "success" ] && [ "$PUBLISH_RESULT" = "published" ]; then | |
| echo "- Result: published with provenance enabled." | |
| elif [ "$JOB_STATUS" = "success" ] && [ "$PUBLISH_RESULT" = "skipped" ]; then | |
| echo "- Result: skipped because this version is already present on npm." | |
| else | |
| echo "- Result: failed before publish completed. Check the failed gate above." | |
| fi | |
| } >> "$GITHUB_STEP_SUMMARY" |