Skip to content

Commit 40e588e

Browse files
aaronziCopilot
andauthored
Improves GitHub Workflows (#525)
* Improves the npm publishing workflow Co-authored-by: Copilot <copilot@github.com> * Updates to newest release candidate of rolldown * Improves workflows Co-authored-by: Copilot <copilot@github.com> * adresses review remarks Co-authored-by: Copilot <copilot@github.com> * Adresses further remarks Co-authored-by: Copilot <copilot@github.com> --------- Co-authored-by: Copilot <copilot@github.com>
1 parent 779d340 commit 40e588e

6 files changed

Lines changed: 131 additions & 6 deletions

File tree

.github/workflows/build-sdk.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ name: Build SDK
33
on:
44
pull_request:
55
branches: [ main ]
6+
types: [opened, synchronize, reopened, ready_for_review]
7+
paths:
8+
- 'src/**'
9+
- 'scripts/**'
10+
- 'openapi/**'
11+
- 'rolldown.config.mjs'
12+
- 'tsconfig*.json'
13+
- 'package.json'
14+
- 'pnpm-lock.yaml'
15+
- 'pnpm-workspace.yaml'
16+
- '.github/workflows/build-sdk.yml'
617

718
permissions:
819
contents: read

.github/workflows/lint-sdk.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,20 @@ name: Lint SDK
33
on:
44
pull_request:
55
branches: [ main ]
6+
types: [opened, synchronize, reopened, ready_for_review]
7+
paths:
8+
- 'src/**'
9+
- 'scripts/**'
10+
- 'openapi/**'
11+
- '.prettierrc*'
12+
- '.prettierignore'
13+
- '.editorconfig'
14+
- 'eslint.config.mts'
15+
- 'tsconfig*.json'
16+
- 'package.json'
17+
- 'pnpm-lock.yaml'
18+
- 'pnpm-workspace.yaml'
19+
- '.github/workflows/lint-sdk.yml'
620

721
permissions:
822
contents: read

.github/workflows/publish.yml

Lines changed: 92 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ on:
55
types: [published]
66

77
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
1014

1115
jobs:
1216
publish:
@@ -15,6 +19,8 @@ jobs:
1519
steps:
1620
- name: Checkout repository
1721
uses: actions/checkout@v6
22+
with:
23+
fetch-depth: 0
1824

1925
- name: Set up pnpm
2026
uses: pnpm/action-setup@v6
@@ -26,9 +32,36 @@ jobs:
2632
registry-url: 'https://registry.npmjs.org'
2733
cache: 'pnpm'
2834

29-
- name: Update npm (OIDC/provenance support)
35+
- name: Update npm (provenance support)
3036
run: npm i -g npm@latest
3137

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+
3265
- name: Install dependencies
3366
run: pnpm install --frozen-lockfile
3467

@@ -41,5 +74,60 @@ jobs:
4174
- name: Verify consumer compatibility
4275
run: pnpm verify:compat
4376

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+
4488
- 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."

.github/workflows/test-sdk.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@ name: Test SDK
33
on:
44
pull_request:
55
branches: [ main ]
6+
types: [opened, synchronize, reopened, ready_for_review]
7+
paths:
8+
- 'src/**'
9+
- 'scripts/**'
10+
- 'ci/**'
11+
- 'openapi/**'
12+
- 'vitest.config.ts'
13+
- 'tsconfig*.json'
14+
- 'package.json'
15+
- 'pnpm-lock.yaml'
16+
- 'pnpm-workspace.yaml'
17+
- '.github/workflows/test-sdk.yml'
618

719
permissions:
820
contents: read

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"eslint-plugin-simple-import-sort": "^13.0.0",
6262
"jiti": "^2.4.2",
6363
"prettier": "^3.8.3",
64-
"rolldown": "^1.0.0-rc.16",
64+
"rolldown": "^1.0.0-rc.17",
6565
"ts-node": "^10.9.2",
6666
"tsconfig-paths": "^4.2.0",
6767
"typedoc": "^0.28.1",

pnpm-lock.yaml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)