diff --git a/.github/workflows/publish-npm.yml b/.github/workflows/publish-npm.yml index 1970199435..3661d5db0e 100644 --- a/.github/workflows/publish-npm.yml +++ b/.github/workflows/publish-npm.yml @@ -59,3 +59,101 @@ jobs: - name: Stage package on npm for maintainer approval run: npm stage publish --tag "${{ steps.package.outputs.tag }}" + + release-assets: + if: ${{ github.repository == 'twbs/bootstrap' && startsWith(github.event.release.tag_name, 'v') }} + runs-on: ubuntu-latest + permissions: + contents: read + outputs: + missing: ${{ steps.assets.outputs.missing }} + artifact-id: ${{ steps.archives.outputs.artifact-id }} + artifact-url: ${{ steps.archives.outputs.artifact-url }} + env: + RELEASE_TAG: ${{ github.event.release.tag_name }} + steps: + - name: Clone repository + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ github.event.release.tag_name }} + persist-credentials: false + + - name: Set up Node.js + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: '24' + package-manager-cache: false + + - name: Verify release version + run: | + node --input-type=commonjs <<'NODE' + const fs = require('node:fs') + const { name, version } = JSON.parse(fs.readFileSync('package.json', 'utf8')) + if (name !== 'bootstrap' || process.env.RELEASE_TAG !== `v${version}`) { + throw new Error(`Release ${process.env.RELEASE_TAG} does not match ${name}@${version}`) + } + NODE + + - name: Check release assets + id: assets + env: + GH_TOKEN: ${{ github.token }} + run: | + assets=$(gh release view "$RELEASE_TAG" --repo "$GITHUB_REPOSITORY" --json assets --jq '.assets[].name') + for suffix in dist examples; do + file="bootstrap-${RELEASE_TAG#v}-${suffix}.zip" + if ! grep -Fxq -- "$file" <<< "$assets"; then + echo "missing=true" >> "$GITHUB_OUTPUT" + break + fi + done + + - name: Install npm dependencies + if: steps.assets.outputs.missing == 'true' + run: npm ci + + - name: Build release archives + if: steps.assets.outputs.missing == 'true' + run: npm run release + + - name: Save release archives for review + if: steps.assets.outputs.missing == 'true' + id: archives + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: release-archives-${{ github.run_attempt }} + path: | + bootstrap-*-dist.zip + bootstrap-*-examples.zip + if-no-files-found: error + compression-level: 0 + + upload-release-assets: + needs: release-assets + if: needs.release-assets.outputs.missing == 'true' + runs-on: ubuntu-latest + environment: + name: release + url: ${{ needs.release-assets.outputs.artifact-url }} + permissions: + contents: write + env: + RELEASE_TAG: ${{ github.event.release.tag_name }} + steps: + - name: Download approved release archives + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + artifact-ids: ${{ needs.release-assets.outputs.artifact-id }} + merge-multiple: true + + - name: Upload missing release assets + env: + GH_TOKEN: ${{ github.token }} + run: | + assets=$(gh release view "$RELEASE_TAG" --repo "$GITHUB_REPOSITORY" --json assets --jq '.assets[].name') + for suffix in dist examples; do + file="bootstrap-${RELEASE_TAG#v}-${suffix}.zip" + if ! grep -Fxq -- "$file" <<< "$assets"; then + gh release upload "$RELEASE_TAG" "$file" --repo "$GITHUB_REPOSITORY" + fi + done