|
| 1 | +name: Publish |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "*" |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + id-token: write |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: publish-${{ github.ref }} |
| 14 | + cancel-in-progress: false |
| 15 | + |
| 16 | +jobs: |
| 17 | + publish: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Checkout repository |
| 22 | + uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + fetch-depth: 0 |
| 25 | + |
| 26 | + - name: Use Node.js 24 |
| 27 | + uses: actions/setup-node@v4 |
| 28 | + with: |
| 29 | + node-version: 24 |
| 30 | + cache: npm |
| 31 | + |
| 32 | + - name: Upgrade npm for trusted publishing |
| 33 | + run: npm install --global npm@^11.5.1 |
| 34 | + |
| 35 | + - name: Setup Bun |
| 36 | + uses: oven-sh/setup-bun@v1 |
| 37 | + with: |
| 38 | + bun-version: 1.3.1 |
| 39 | + |
| 40 | + - name: Validate release tag |
| 41 | + id: version |
| 42 | + run: | |
| 43 | + version="$(node -p "require('./package.json').version")" |
| 44 | + tag="${GITHUB_REF_NAME}" |
| 45 | +
|
| 46 | + if [ "$tag" != "$version" ] && [ "$tag" != "v$version" ]; then |
| 47 | + echo "Tag '$tag' does not match package.json version '$version'." >&2 |
| 48 | + exit 1 |
| 49 | + fi |
| 50 | +
|
| 51 | + echo "version=$version" >> "$GITHUB_OUTPUT" |
| 52 | +
|
| 53 | + - name: Determine npm dist-tag |
| 54 | + id: dist_tag |
| 55 | + run: | |
| 56 | + node <<'NODE' >> "$GITHUB_OUTPUT" |
| 57 | + const {version} = require("./package.json") |
| 58 | + const prerelease = version.split("-")[1] |
| 59 | + const distTag = prerelease ? prerelease.split(".")[0] : "latest" |
| 60 | + console.log(`dist_tag=${distTag}`) |
| 61 | + NODE |
| 62 | +
|
| 63 | + - name: Install dependencies |
| 64 | + run: npm ci |
| 65 | + |
| 66 | + - name: Build generated artifacts |
| 67 | + run: | |
| 68 | + bun run res:build |
| 69 | + bun run build:resx-client |
| 70 | +
|
| 71 | + - name: Verify generated artifacts are committed |
| 72 | + run: git diff --exit-code |
| 73 | + |
| 74 | + - name: Run tests |
| 75 | + run: bun run test |
| 76 | + |
| 77 | + - name: Check whether this version is already published |
| 78 | + id: already_published |
| 79 | + run: | |
| 80 | + if npm view "rescript-x@${{ steps.version.outputs.version }}" version >/dev/null 2>&1; then |
| 81 | + echo "published=true" >> "$GITHUB_OUTPUT" |
| 82 | + else |
| 83 | + echo "published=false" >> "$GITHUB_OUTPUT" |
| 84 | + fi |
| 85 | +
|
| 86 | + - name: Show packed contents |
| 87 | + if: steps.already_published.outputs.published != 'true' |
| 88 | + run: npm pack --dry-run |
| 89 | + |
| 90 | + - name: Publish to npm |
| 91 | + if: steps.already_published.outputs.published != 'true' |
| 92 | + run: npm publish --tag "${{ steps.dist_tag.outputs.dist_tag }}" |
| 93 | + |
| 94 | + - name: Skip duplicate publish |
| 95 | + if: steps.already_published.outputs.published == 'true' |
| 96 | + run: echo "rescript-x@${{ steps.version.outputs.version }} is already published, skipping." |
0 commit comments