Skip to content

Commit 31d3fcf

Browse files
committed
try fixing npm_napi_release workflow
1 parent 05e8cc4 commit 31d3fcf

File tree

5 files changed

+135
-55
lines changed

5 files changed

+135
-55
lines changed

.github/workflows/npm_napi_release.yml

Lines changed: 64 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ on:
77
- "v*"
88

99
env:
10-
NPM_TAG: "next"
1110
XCODE_VERSION: "^15.0"
1211

1312
jobs:
1413
build:
1514
name: Build
1615
runs-on: macos-14
1716
outputs:
18-
npm_version: ${{ steps.npm_version_output.outputs.NPM_VERSION }}
19-
npm_tag: ${{ steps.npm_version_output.outputs.NPM_TAG }}
17+
npm_version_ios: ${{ steps.npm_version_output.outputs.NPM_VERSION_IOS }}
18+
npm_tag_ios: ${{ steps.npm_version_output.outputs.NPM_TAG_IOS }}
19+
npm_version_macos: ${{ steps.npm_version_output.outputs.NPM_VERSION_MACOS }}
20+
npm_tag_macos: ${{ steps.npm_version_output.outputs.NPM_TAG_MACOS }}
2021
steps:
2122
- name: Harden the runner (Audit all outbound calls)
2223
uses: step-security/harden-runner@95d9a5deda9de15063e7595e9719c11c38c90ae2 # v2.13.2
@@ -57,30 +58,43 @@ jobs:
5758
run: |
5859
NPM_VERSION=$(node -e "console.log(require('./package.json').version);")
5960
echo NPM_VERSION=$NPM_VERSION >> $GITHUB_ENV
60-
- name: Bump version for dev release
61+
- name: Bump versions for dev release
6162
if: ${{ !contains(github.ref, 'refs/tags/') }}
6263
run: |
63-
NPM_VERSION=$(node ./scripts/get-next-version.js)
64-
echo NPM_VERSION=$NPM_VERSION >> $GITHUB_ENV
65-
npm version $NPM_VERSION --no-git-tag-version
66-
- name: Output NPM Version and tag
64+
# Bump @nativescript/ios-node-api
65+
NPM_VERSION_IOS=$(node ./scripts/get-next-version.js ios)
66+
echo NPM_VERSION_IOS=$NPM_VERSION_IOS >> $GITHUB_ENV
67+
cd packages/ios
68+
npm version $NPM_VERSION_IOS --no-git-tag-version
69+
cd -
70+
71+
# Bump @nativescript/macos-node-api
72+
NPM_VERSION_MACOS=$(node ./scripts/get-next-version.js macos)
73+
echo NPM_VERSION_MACOS=$NPM_VERSION_MACOS >> $GITHUB_ENV
74+
cd packages/macos
75+
npm version $NPM_VERSION_MACOS --no-git-tag-version
76+
cd -
77+
- name: Output NPM Versions and tags
6778
id: npm_version_output
6879
run: |
69-
NPM_TAG=$(node ./scripts/get-npm-tag.js)
70-
echo NPM_VERSION=$NPM_VERSION >> $GITHUB_OUTPUT
71-
echo NPM_TAG=$NPM_TAG >> $GITHUB_OUTPUT
80+
NPM_TAG_IOS=$(node ./scripts/get-npm-tag.js ios)
81+
NPM_TAG_MACOS=$(node ./scripts/get-npm-tag.js macos)
82+
echo NPM_VERSION_IOS=$NPM_VERSION_IOS >> $GITHUB_OUTPUT
83+
echo NPM_VERSION_MACOS=$NPM_VERSION_MACOS >> $GITHUB_OUTPUT
84+
echo NPM_TAG_IOS=$NPM_TAG_IOS >> $GITHUB_OUTPUT
85+
echo NPM_TAG_MACOS=$NPM_TAG_MACOS >> $GITHUB_OUTPUT
7286
- name: Build
73-
run: npm run build-ios
74-
- name: Upload npm package artifact
87+
run: ./build_all_react_native.sh
88+
- name: Upload npm package artifact for @nativescript/ios-node-api
7589
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
7690
with:
77-
name: npm-package
78-
path: dist/nativescript-ios-${{steps.npm_version_output.outputs.NPM_VERSION}}.tgz
79-
- name: Upload dSYMs artifact
91+
name: nativescript-ios-node-api
92+
path: packages/ios/nativescript-ios-node-api-${{steps.npm_version_output.outputs.NPM_VERSION_IOS}}.tgz
93+
- name: Upload npm package artifact for @nativescript/macos-node-api
8094
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
8195
with:
82-
name: NativeScript-dSYMs
83-
path: dist/dSYMs
96+
name: nativescript-macos-node-api
97+
path: packages/macos/nativescript-macos-node-api-${{steps.npm_version_output.outputs.NPM_VERSION_MACOS}}.tgz
8498
test:
8599
name: Test
86100
runs-on: macos-14
@@ -96,7 +110,7 @@ jobs:
96110
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
97111
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
98112
with:
99-
node-version: 22
113+
node-version: 24
100114
- name: Install Python
101115
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
102116
with:
@@ -174,25 +188,42 @@ jobs:
174188
path: dist
175189
- name: Update npm (required for OIDC trusted publishing)
176190
run: |
177-
npm install -g npm@^11.5.1
191+
npm install -g npm@^11.6.2
178192
npm --version
179-
- name: Publish package (OIDC trusted publishing)
193+
- name: Publish @nativescript/ios-node-api package (OIDC trusted publishing)
180194
if: ${{ vars.USE_NPM_TOKEN != 'true' }}
181195
run: |
182-
echo "Publishing @nativescript/ios@$NPM_VERSION to NPM with tag $NPM_TAG via OIDC trusted publishing..."
196+
echo "Publishing @nativescript/ios-node-api@$NPM_VERSION_IOS to NPM with tag $NPM_TAG_IOS via OIDC trusted publishing..."
183197
unset NODE_AUTH_TOKEN
184198
if [ -n "${NPM_CONFIG_USERCONFIG:-}" ]; then
185199
rm -f "$NPM_CONFIG_USERCONFIG"
186200
fi
187-
npm publish ./dist/nativescript-ios-${{env.NPM_VERSION}}.tgz --tag $NPM_TAG --access public --provenance
201+
npm publish packages/ios/nativescript-ios-node-api-${{env.NPM_VERSION_IOS}}.tgz --tag $NPM_TAG_IOS --access public --provenance
188202
env:
189203
NODE_AUTH_TOKEN: ""
190-
191-
- name: Publish package (granular token)
204+
- name: Publish @nativescript/macos-node-api package (OIDC trusted publishing)
205+
if: ${{ vars.USE_NPM_TOKEN != 'true' }}
206+
run: |
207+
echo "Publishing @nativescript/macos-node-api@$NPM_VERSION_MACOS to NPM with tag $NPM_TAG_MACOS via OIDC trusted publishing..."
208+
unset NODE_AUTH_TOKEN
209+
if [ -n "${NPM_CONFIG_USERCONFIG:-}" ]; then
210+
rm -f "$NPM_CONFIG_USERCONFIG"
211+
fi
212+
npm publish packages/macos/nativescript-macos-node-api-${{env.NPM_VERSION_MACOS}}.tgz --tag $NPM_TAG_MACOS --access public --provenance
213+
env:
214+
NODE_AUTH_TOKEN: ""
215+
- name: Publish @nativescript/ios-node-api package (granular token)
216+
if: ${{ vars.USE_NPM_TOKEN == 'true' }}
217+
run: |
218+
echo "Publishing @nativescript/ios-node-api@$NPM_VERSION to NPM with tag $NPM_TAG_IOS via granular token..."
219+
npm publish packages/ios/nativescript-ios-node-api-${{env.NPM_VERSION_IOS}}.tgz --tag $NPM_TAG_IOS --access public --provenance
220+
env:
221+
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
222+
- name: Publish @nativescript/macos-node-api package (granular token)
192223
if: ${{ vars.USE_NPM_TOKEN == 'true' }}
193224
run: |
194-
echo "Publishing @nativescript/ios@$NPM_VERSION to NPM with tag $NPM_TAG via granular token..."
195-
npm publish ./dist/nativescript-ios-${{env.NPM_VERSION}}.tgz --tag $NPM_TAG --access public --provenance
225+
echo "Publishing @nativescript/macos-node-api@$NPM_VERSION to NPM with tag $NPM_TAG_MACOS via granular token..."
226+
npm publish packages/macos/nativescript-macos-node-api-${{env.NPM_VERSION_MACOS}}.tgz --tag $NPM_TAG_MACOS --access public --provenance
196227
env:
197228
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
198229
github-release:
@@ -216,25 +247,22 @@ jobs:
216247
fetch-depth: 0
217248
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
218249
with:
219-
node-version: 22
250+
node-version: 24
220251
- name: Setup
221252
run: npm install
222253
- uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
223254
with:
224-
name: npm-package
225-
path: dist
255+
name: nativescript-ios-node-api
256+
path: packages/ios
226257
- uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
227258
with:
228-
name: NativeScript-dSYMs
229-
path: dist/dSYMs
230-
- name: Zip dSYMs
231-
working-directory: dist/dSYMs
232-
run: find . -maxdepth 1 -name '*.dSYM' -print | xargs -I@ zip -r @.zip @
259+
name: nativescript-macos-node-api
260+
path: packages/macos
233261
- name: Partial Changelog
234262
run: npx conventional-changelog -p angular -r2 > body.md
235263
- uses: ncipollo/release-action@b7eabc95ff50cbeeedec83973935c8f306dfcd0b # v1.20.0
236264
with:
237-
artifacts: "dist/nativescript-ios-*.tgz,dist/dSYMs/*.zip"
265+
artifacts: "packages/macos/nativescript-macos-node-api-*.tgz,packages/ios/nativescript-ios-node-api-*.tgz"
238266
bodyFile: "body.md"
239267
prerelease: ${{needs.build.outputs.npm_tag != 'latest'}}
240268
allowUpdates: true

.github/workflows/npm_release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ jobs:
6060
- name: Bump version for dev release
6161
if: ${{ !contains(github.ref, 'refs/tags/') }}
6262
run: |
63-
NPM_VERSION=$(node ./scripts/get-next-version.js)
63+
NPM_VERSION=$(node ./scripts/get-next-version.js root)
6464
echo NPM_VERSION=$NPM_VERSION >> $GITHUB_ENV
6565
npm version $NPM_VERSION --no-git-tag-version
6666
- name: Output NPM Version and tag
6767
id: npm_version_output
6868
run: |
69-
NPM_TAG=$(node ./scripts/get-npm-tag.js)
69+
NPM_TAG=$(node ./scripts/get-npm-tag.js root)
7070
echo NPM_VERSION=$NPM_VERSION >> $GITHUB_OUTPUT
7171
echo NPM_TAG=$NPM_TAG >> $GITHUB_OUTPUT
7272
- name: Build

prepare-target.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
const path = require('path');
2-
const fs = require('fs');
1+
const process = require("node:process");
2+
const path = require("node:path");
3+
const fs = require("node:fs");
34

45
const cmdArgs = process.argv.slice(2);
56
const target = cmdArgs[0]; // ios, macos or visionos
67

7-
const packagePath = path.join('package.json');
8+
const packagePath = path.resolve(__dirname, "package.json");
89
const packageJson = JSON.parse(fs.readFileSync(packagePath));
910

1011
packageJson.name = `@nativescript/${target}`;
11-
packageJson.description = `NativeScript Runtime for ${target === 'ios' ? 'iOS' : target === 'macos' ? 'macOS' : 'visionOS'}`;
12+
packageJson.description = `NativeScript Runtime for ${
13+
target === "ios" ? "iOS" : target === "macos" ? "macOS" : "visionOS"
14+
}`;
1215

13-
fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2));
16+
fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2));

scripts/get-next-version.js

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
1+
const child_process = require("node:child_process");
2+
const process = require("node:process");
3+
const fs = require("node:fs");
14
const semver = require("semver");
2-
const child_process = require("child_process");
35
const dayjs = require("dayjs");
4-
const fs = require("fs");
56

6-
const currentVersion =
7-
process.env.NPM_VERSION || require("../package.json").version;
7+
/** @type {string} */
8+
let currentVersion = process.env.NPM_VERSION;
9+
if (!currentVersion) {
10+
const cmdArgs = process.argv.slice(2);
11+
const target = cmdArgs[0];
12+
13+
switch (target) {
14+
case "root":
15+
currentVersion = require("../package.json").version;
16+
break;
17+
case "macos":
18+
currentVersion = require("../packages/macos/package.json").version;
19+
break;
20+
case "ios":
21+
currentVersion = require("../packages/ios/package.json").version;
22+
break;
23+
default:
24+
throw new Error(
25+
`Unknown target "${target}". Expected one of "root", "macos", or "ios".`,
26+
);
27+
}
28+
}
829

930
if (!currentVersion) {
1031
throw new Error("Invalid current version");
@@ -16,16 +37,20 @@ let prPrerelease = "";
1637

1738
if (currentTag === "pr" && process.env.GITHUB_EVENT_PATH) {
1839
try {
19-
const ev = JSON.parse(fs.readFileSync(process.env.GITHUB_EVENT_PATH, "utf8"));
40+
const ev = JSON.parse(
41+
fs.readFileSync(process.env.GITHUB_EVENT_PATH, "utf8"),
42+
);
2043
const prNum = ev.pull_request.number;
2144
// add extra PR number to version-pr.PRNUM-....
2245
prPrerelease = `${prNum}-`;
23-
} catch (e) {
46+
} catch {
2447
// don't add pr prerelease
2548
}
2649
}
2750

28-
const preRelease = `${currentTag}.${prPrerelease}${dayjs().format("YYYY-MM-DD")}-${runID}`;
51+
const preRelease = `${currentTag}.${prPrerelease}${dayjs().format(
52+
"YYYY-MM-DD",
53+
)}-${runID}`;
2954

3055
function normalizeVersionCandidate(candidate) {
3156
if (!candidate) {
@@ -49,7 +74,9 @@ function normalizeVersionCandidate(candidate) {
4974
}
5075

5176
// Supports tag formats such as refs/tags/v1.2.3, pkg@1.2.3, etc.
52-
const extracted = trimmed.match(/\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?/);
77+
const extracted = trimmed.match(
78+
/\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?/,
79+
);
5380
if (extracted && semver.parse(extracted[0])) {
5481
return extracted[0];
5582
}
@@ -58,7 +85,9 @@ function normalizeVersionCandidate(candidate) {
5885
}
5986

6087
function getLastTagVersion() {
61-
const explicitTagVersion = normalizeVersionCandidate(process.env.LAST_TAGGED_VERSION);
88+
const explicitTagVersion = normalizeVersionCandidate(
89+
process.env.LAST_TAGGED_VERSION,
90+
);
6291
if (explicitTagVersion) {
6392
return explicitTagVersion;
6493
}
@@ -95,7 +124,7 @@ const lastTagVersion = getLastTagVersion();
95124
function setPreRelease(version) {
96125
const parsed = semver.parse(version);
97126
return semver.parse(
98-
`${parsed.major}.${parsed.minor}.${parsed.patch}-${preRelease}`
127+
`${parsed.major}.${parsed.minor}.${parsed.patch}-${preRelease}`,
99128
);
100129
}
101130

scripts/get-npm-tag.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
1+
const process = require("node:process");
12
const semver = require("semver");
23

3-
const currentVersion =
4-
process.env.NPM_VERSION || require("../package.json").version;
4+
let currentVersion = process.env.NPM_VERSION;
5+
if (!currentVersion) {
6+
const cmdArgs = process.argv.slice(2);
7+
const target = cmdArgs[0];
8+
9+
switch (target) {
10+
case "root":
11+
currentVersion = require("../package.json").version;
12+
break;
13+
case "macos":
14+
currentVersion = require("../packages/macos/package.json").version;
15+
break;
16+
case "ios":
17+
currentVersion = require("../packages/ios/package.json").version;
18+
break;
19+
default:
20+
throw new Error(
21+
`Unknown target "${target}". Expected one of "root", "macos", or "ios".`,
22+
);
23+
}
24+
}
525

626
function validateNpmTag(version) {
727
const parsed = semver.parse(version);

0 commit comments

Comments
 (0)