|
| 1 | +# Written by DocSpring/docspring's api_clients/scripts/generate from api_clients/github_workflows/javascript/release.yml: |
| 2 | +# change it there. |
| 3 | +# |
| 4 | +# Builds the package on every push and pull request. A v* tag (pushed by the monorepo's api_clients/scripts/release) |
| 5 | +# also publishes it to npm with trusted publishing, in the release environment, and waits until npm serves it. |
| 6 | +name: Release |
| 7 | + |
| 8 | +on: |
| 9 | + push: |
| 10 | + branches: ['**'] |
| 11 | + tags: ['v*'] |
| 12 | + pull_request: |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + |
| 17 | +jobs: |
| 18 | + build: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 22 | + with: |
| 23 | + persist-credentials: false |
| 24 | + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 |
| 25 | + with: |
| 26 | + node-version: 24 |
| 27 | + - name: Check the tag matches the package version |
| 28 | + if: github.ref_type == 'tag' |
| 29 | + run: | |
| 30 | + VERSION="$(node -p 'require("./package.json").version')" |
| 31 | + if [ "v$VERSION" != "$GITHUB_REF_NAME" ]; then |
| 32 | + echo "::error::The tag is $GITHUB_REF_NAME, but the package version is $VERSION" |
| 33 | + exit 1 |
| 34 | + fi |
| 35 | + # npm ci runs the package's prepare script, which builds dist/ |
| 36 | + - run: npm ci |
| 37 | + - run: npm pack |
| 38 | + - name: Publish dry run |
| 39 | + run: | |
| 40 | + VERSION="$(node -p 'require("./package.json").version')" |
| 41 | + # npm refuses a prerelease without a dist-tag, and latest must stay on the newest release |
| 42 | + DIST_TAG=latest |
| 43 | + case "$VERSION" in *-*) DIST_TAG=next ;; esac |
| 44 | + npm publish "docspring-$VERSION.tgz" --dry-run --access public --tag "$DIST_TAG" |
| 45 | + - if: github.ref_type == 'tag' |
| 46 | + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 |
| 47 | + with: |
| 48 | + name: package |
| 49 | + path: docspring-*.tgz |
| 50 | + if-no-files-found: error |
| 51 | + |
| 52 | + publish: |
| 53 | + needs: build |
| 54 | + if: github.ref_type == 'tag' |
| 55 | + runs-on: ubuntu-latest |
| 56 | + environment: release |
| 57 | + permissions: |
| 58 | + contents: read |
| 59 | + id-token: write |
| 60 | + steps: |
| 61 | + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 |
| 62 | + with: |
| 63 | + node-version: 24 |
| 64 | + # Trusted publishing needs npm 11.5.1 or later |
| 65 | + - run: npm install --global npm@11.21.1 |
| 66 | + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 |
| 67 | + with: |
| 68 | + name: package |
| 69 | + - name: Publish to npm |
| 70 | + run: | |
| 71 | + VERSION="${GITHUB_REF_NAME#v}" |
| 72 | + DIST_TAG=latest |
| 73 | + case "$VERSION" in *-*) DIST_TAG=next ;; esac |
| 74 | + npm publish "docspring-$VERSION.tgz" --access public --tag "$DIST_TAG" |
| 75 | +
|
| 76 | + verify: |
| 77 | + needs: publish |
| 78 | + runs-on: ubuntu-latest |
| 79 | + timeout-minutes: 15 |
| 80 | + steps: |
| 81 | + - name: Wait until npm serves the version |
| 82 | + run: | |
| 83 | + VERSION="${GITHUB_REF_NAME#v}" |
| 84 | + for _ in $(seq 60); do |
| 85 | + if curl -fsS -o /dev/null "https://registry.npmjs.org/docspring/$VERSION"; then |
| 86 | + echo "npm serves docspring $VERSION" |
| 87 | + exit 0 |
| 88 | + fi |
| 89 | + sleep 10 |
| 90 | + done |
| 91 | + echo "::error::npm doesn't serve docspring $VERSION after 10 minutes" |
| 92 | + exit 1 |
0 commit comments