|
5 | 5 | types: [published] |
6 | 6 |
|
7 | 7 | permissions: |
8 | | - contents: read |
9 | | - id-token: write # required for OIDC trusted publishing |
| 8 | + contents: write |
| 9 | + id-token: write |
| 10 | + |
| 11 | +concurrency: |
| 12 | + group: publish-${{ github.event.release.id }} |
| 13 | + cancel-in-progress: false |
10 | 14 |
|
11 | 15 | jobs: |
12 | 16 | publish: |
|
15 | 19 | steps: |
16 | 20 | - name: Checkout repository |
17 | 21 | uses: actions/checkout@v6 |
| 22 | + with: |
| 23 | + fetch-depth: 0 |
18 | 24 |
|
19 | 25 | - name: Set up pnpm |
20 | 26 | uses: pnpm/action-setup@v6 |
|
26 | 32 | registry-url: 'https://registry.npmjs.org' |
27 | 33 | cache: 'pnpm' |
28 | 34 |
|
29 | | - - name: Update npm (OIDC/provenance support) |
| 35 | + - name: Update npm (provenance support) |
30 | 36 | run: npm i -g npm@latest |
31 | 37 |
|
| 38 | + - name: Resolve release version |
| 39 | + shell: bash |
| 40 | + run: | |
| 41 | + TAG_NAME='${{ github.event.release.tag_name }}' |
| 42 | + if [[ ! "$TAG_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then |
| 43 | + echo "Release tag must be v-prefixed semver (for example v1.2.3 or v1.2.3-rc.1), got: $TAG_NAME" >&2 |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | + echo "APP_VERSION=${TAG_NAME#v}" >> "$GITHUB_ENV" |
| 47 | +
|
| 48 | + - name: Sync package versions |
| 49 | + shell: bash |
| 50 | + run: | |
| 51 | + PRE_SYNC_VERSION=$(node -p "require('./package.json').version") |
| 52 | + if [[ "$PRE_SYNC_VERSION" != "$APP_VERSION" ]]; then |
| 53 | + echo "package.json version ($PRE_SYNC_VERSION) differs from release version ($APP_VERSION); syncing package files in CI." |
| 54 | + fi |
| 55 | +
|
| 56 | + npm version "$APP_VERSION" --no-git-tag-version --allow-same-version |
| 57 | + pnpm install --lockfile-only --ignore-scripts |
| 58 | +
|
| 59 | + POST_SYNC_VERSION=$(node -p "require('./package.json').version") |
| 60 | + if [[ "$POST_SYNC_VERSION" != "$APP_VERSION" ]]; then |
| 61 | + echo "Failed to sync package.json version to release version ($APP_VERSION); got: $POST_SYNC_VERSION" >&2 |
| 62 | + exit 1 |
| 63 | + fi |
| 64 | +
|
32 | 65 | - name: Install dependencies |
33 | 66 | run: pnpm install --frozen-lockfile |
34 | 67 |
|
|
41 | 74 | - name: Verify consumer compatibility |
42 | 75 | run: pnpm verify:compat |
43 | 76 |
|
| 77 | + - name: Resolve npm dist-tag |
| 78 | + shell: bash |
| 79 | + run: | |
| 80 | + if [[ "$APP_VERSION" == *-* ]]; then |
| 81 | + PRERELEASE=${APP_VERSION#*-} |
| 82 | + TAG=${PRERELEASE%%.*} |
| 83 | + echo "NPM_TAG=$TAG" >> "$GITHUB_ENV" |
| 84 | + else |
| 85 | + echo "NPM_TAG=latest" >> "$GITHUB_ENV" |
| 86 | + fi |
| 87 | +
|
44 | 88 | - name: Publish to npm (OIDC) |
45 | | - run: npm publish |
| 89 | + run: npm publish --provenance --tag "$NPM_TAG" |
| 90 | + |
| 91 | + - name: Commit synced package files |
| 92 | + id: sync_package_files |
| 93 | + if: github.event.release.target_commitish == 'main' && github.repository == 'eclipse-basyx/basyx-typescript-sdk' |
| 94 | + continue-on-error: true |
| 95 | + shell: bash |
| 96 | + run: | |
| 97 | + package_snapshot="$(mktemp)" |
| 98 | + lockfile_snapshot="$(mktemp)" |
| 99 | + sync_worktree="$(mktemp -d)" |
| 100 | +
|
| 101 | + cp package.json "$package_snapshot" |
| 102 | + cp pnpm-lock.yaml "$lockfile_snapshot" |
| 103 | +
|
| 104 | + cleanup() { |
| 105 | + git worktree remove --force "$sync_worktree" >/dev/null 2>&1 || true |
| 106 | + rm -f "$package_snapshot" "$lockfile_snapshot" |
| 107 | + rm -rf "$sync_worktree" |
| 108 | + } |
| 109 | + trap cleanup EXIT |
| 110 | +
|
| 111 | + git fetch origin main |
| 112 | + git worktree add -B main "$sync_worktree" origin/main |
| 113 | +
|
| 114 | + cd "$sync_worktree" |
| 115 | + git config user.name "github-actions[bot]" |
| 116 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 117 | +
|
| 118 | + cp "$package_snapshot" package.json |
| 119 | + cp "$lockfile_snapshot" pnpm-lock.yaml |
| 120 | +
|
| 121 | + git add package.json pnpm-lock.yaml |
| 122 | + if git diff --cached --quiet; then |
| 123 | + echo "No package file changes to commit against origin/main." |
| 124 | + exit 0 |
| 125 | + fi |
| 126 | +
|
| 127 | + git commit -m "chore(release): sync package versions to ${{ github.event.release.tag_name }} [skip ci]" |
| 128 | + git push origin main |
| 129 | +
|
| 130 | + - name: Warn if package sync push failed |
| 131 | + if: steps.sync_package_files.outcome == 'failure' |
| 132 | + run: | |
| 133 | + echo "::warning::npm publish succeeded, but pushing synced package files to main failed. Please sync package.json and pnpm-lock.yaml manually." |
0 commit comments