Skip to content

Commit b572736

Browse files
authored
ci: add CI/CD for PRs, next tag and releases (#213)
1 parent 36e3dd3 commit b572736

File tree

10 files changed

+377
-6
lines changed

10 files changed

+377
-6
lines changed

.github/workflows/npm_release.yml

+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
tags:
6+
- 'v*'
7+
8+
env:
9+
NPM_TAG: "next"
10+
11+
jobs:
12+
build:
13+
name: Build
14+
runs-on: macos-12
15+
outputs:
16+
npm_version: ${{ steps.npm_version_output.outputs.NPM_VERSION }}
17+
npm_tag: ${{ steps.npm_version_output.outputs.NPM_TAG }}
18+
steps:
19+
- uses: actions/checkout@v3
20+
with:
21+
fetch-depth: 0
22+
- name: LLVM cache
23+
uses: actions/cache@v3
24+
with:
25+
path: ./llvm
26+
key: ${{ hashFiles('download_llvm.sh') }}
27+
- uses: actions/setup-node@v3
28+
with:
29+
node-version: 18
30+
- name: Install Python
31+
uses: actions/setup-python@v4
32+
with:
33+
python-version: "3"
34+
- name: Install Dependencies
35+
run: |
36+
npm install
37+
python3 -m pip install --upgrade pip six
38+
brew install cmake
39+
[ ! -f /usr/local/bin/cmake ] && ln -s /usr/local/bin/cmake $(which cmake) || true
40+
- name: Get Current Version
41+
run: |
42+
NPM_VERSION=$(node -e "console.log(require('./package.json').version);")
43+
echo NPM_VERSION=$NPM_VERSION >> $GITHUB_ENV
44+
- name: Bump version for dev release
45+
if: ${{ !contains(github.ref, 'refs/tags/') }}
46+
run: |
47+
NPM_VERSION=$(node ./scripts/get-next-version.js)
48+
echo NPM_VERSION=$NPM_VERSION >> $GITHUB_ENV
49+
npm version $NPM_VERSION --no-git-tag-version
50+
- name: Output NPM Version and tag
51+
id: npm_version_output
52+
run: |
53+
NPM_TAG=$(node ./scripts/get-npm-tag.js)
54+
echo NPM_VERSION=$NPM_VERSION >> $GITHUB_OUTPUT
55+
echo NPM_TAG=$NPM_TAG >> $GITHUB_OUTPUT
56+
- name: Build
57+
run: npm run build
58+
- name: Upload npm package artifact
59+
uses: actions/upload-artifact@v3
60+
with:
61+
name: npm-package
62+
path: dist/nativescript-ios-${{env.NPM_VERSION}}.tgz
63+
- name: Upload dSYMs artifact
64+
uses: actions/upload-artifact@v3
65+
with:
66+
name: NativeScript-dSYMs
67+
path: dist/dSYMs
68+
test:
69+
name: Test
70+
runs-on: macos-12
71+
needs: build
72+
steps:
73+
- uses: actions/checkout@v3
74+
- name: LLVM cache
75+
uses: actions/cache@v3
76+
with:
77+
path: ./llvm
78+
key: ${{ hashFiles('download_llvm.sh') }}
79+
- uses: actions/setup-node@v3
80+
with:
81+
node-version: 18
82+
- name: Install Python
83+
uses: actions/setup-python@v4
84+
with:
85+
python-version: "3"
86+
- name: Install Dependencies
87+
run: |
88+
npm install
89+
python3 -m pip install --upgrade pip six
90+
brew install cmake
91+
[ ! -f /usr/local/bin/cmake ] && ln -s /usr/local/bin/cmake $(which cmake) || true
92+
brew install chargepoint/xcparse/xcparse
93+
npm install -g @edusperoni/junit-cli-report-viewer verify-junit-xml
94+
- name: Prepare
95+
run: npm run setup-ci
96+
- name: Xcode Tests
97+
uses: nick-fields/retry@v2
98+
# try to run the tests with xcpretty. If it fails then try again without xcpretty twice for better log output
99+
# the xcode tests are a bit flaky and they should never fail on this step, as this step only collects the JS test results as junit xml
100+
with:
101+
timeout_minutes: 20
102+
max_attempts: 3
103+
command: set -o pipefail && xcodebuild -project v8ios.xcodeproj -scheme TestRunner -resultBundlePath $HOME/test_results -destination platform\=iOS\ Simulator,OS\=16.2,name\=iPhone\ 14\ Pro\ Max build test | xcpretty
104+
on_retry_command: rm -rf $HOME/test_results*
105+
new_command_on_retry: xcodebuild -project v8ios.xcodeproj -scheme TestRunner -resultBundlePath $HOME/test_results -destination platform\=iOS\ Simulator,OS\=16.2,name\=iPhone\ 14\ Pro\ Max build test
106+
- name: Validate Test Results
107+
run: |
108+
xcparse attachments $HOME/test_results.xcresult $HOME/test-out
109+
find $HOME/test-out -name "*junit*.xml" -maxdepth 1 -print0 | xargs -n 1 -0 npx junit-cli-report-viewer
110+
find $HOME/test-out -name "*junit*.xml" -maxdepth 1 -print0 | xargs -n 1 -0 npx verify-junit-xml
111+
publish:
112+
runs-on: ubuntu-latest
113+
needs:
114+
- build
115+
- test
116+
env:
117+
NPM_VERSION: ${{needs.build.outputs.npm_version}}
118+
NPM_TAG: ${{needs.build.outputs.npm_tag}}
119+
steps:
120+
- uses: actions/setup-node@v3
121+
with:
122+
node-version: 18
123+
- uses: actions/download-artifact@v3
124+
with:
125+
name: npm-package
126+
path: dist
127+
- name: Publish package
128+
run: |
129+
echo "Publishing @nativescript/ios@$NPM_VERSION to NPM with tag $NPM_TAG..."
130+
npm publish ./dist/nativescript-ios-${{env.NPM_VERSION}}.tgz --tag $NPM_TAG --provenance
131+
env:
132+
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
133+
github-release:
134+
runs-on: ubuntu-latest
135+
# only runs on tagged commits
136+
if: ${{ contains(github.ref, 'refs/tags/') }}
137+
permissions:
138+
contents: write
139+
needs:
140+
- build
141+
- test
142+
env:
143+
NPM_VERSION: ${{needs.build.outputs.npm_version}}
144+
steps:
145+
- uses: actions/setup-node@v3
146+
with:
147+
node-version: 18
148+
- name: Setup
149+
run: npm install
150+
- uses: actions/download-artifact@v3
151+
with:
152+
name: npm-package
153+
path: dist
154+
- uses: actions/download-artifact@v3
155+
with:
156+
name: NativeScript-dSYMs
157+
path: dist
158+
- name: Partial Changelog
159+
run: npx conventional-changelog -p angular -r2 > body.md
160+
- uses: ncipollo/release-action@v1
161+
with:
162+
artifacts: "dist/nativescript-ios-*.tgz,dist/dSYMs/*"
163+
bodyFile: "body.md"

.github/workflows/pull_request.yml

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
on:
2+
pull_request:
3+
4+
env:
5+
NPM_TAG: "pr"
6+
7+
jobs:
8+
build:
9+
name: Build
10+
runs-on: macos-12
11+
steps:
12+
- uses: actions/checkout@v3
13+
with:
14+
fetch-depth: 0
15+
- name: LLVM cache
16+
uses: actions/cache@v3
17+
with:
18+
path: ./llvm
19+
key: ${{ hashFiles('download_llvm.sh') }}
20+
- uses: actions/setup-node@v3
21+
with:
22+
node-version: 18
23+
- name: Install Python
24+
uses: actions/setup-python@v4
25+
with:
26+
python-version: "3"
27+
- name: Install Dependencies
28+
run: |
29+
npm install
30+
python3 -m pip install --upgrade pip six
31+
brew install cmake
32+
[ ! -f /usr/local/bin/cmake ] && ln -s /usr/local/bin/cmake $(which cmake) || true
33+
- name: Get Current Version
34+
run: |
35+
echo NPM_VERSION=$(node -e "console.log(require('./package.json').version);") >> $GITHUB_ENV
36+
- name: Bump version for PR release
37+
run: |
38+
NPM_VERSION=$(node ./scripts/get-next-version.js)
39+
echo NPM_VERSION=$NPM_VERSION >> $GITHUB_ENV
40+
npm version $NPM_VERSION --no-git-tag-version
41+
- name: Build
42+
run: npm run build
43+
- name: Upload npm package artifact
44+
uses: actions/upload-artifact@v3
45+
with:
46+
name: npm-package
47+
path: dist/nativescript-ios-${{env.NPM_VERSION}}.tgz
48+
- name: Upload dSYMs artifact
49+
uses: actions/upload-artifact@v3
50+
with:
51+
name: NativeScript-dSYMs
52+
path: dist/dSYMs
53+
test:
54+
name: Test
55+
runs-on: macos-12
56+
needs: build
57+
steps:
58+
- uses: actions/checkout@v3
59+
- name: LLVM cache
60+
uses: actions/cache@v3
61+
with:
62+
path: ./llvm
63+
key: ${{ hashFiles('download_llvm.sh') }}
64+
- uses: actions/setup-node@v3
65+
with:
66+
node-version: 18
67+
- name: Install Python
68+
uses: actions/setup-python@v4
69+
with:
70+
python-version: "3"
71+
- name: Install Dependencies
72+
run: |
73+
npm install
74+
python3 -m pip install --upgrade pip six
75+
brew install cmake
76+
[ ! -f /usr/local/bin/cmake ] && ln -s /usr/local/bin/cmake $(which cmake) || true
77+
brew install chargepoint/xcparse/xcparse
78+
npm install -g @edusperoni/junit-cli-report-viewer verify-junit-xml
79+
- name: Xcode Tests
80+
uses: nick-fields/retry@v2
81+
# try to run the tests with xcpretty. If it fails then try again without xcpretty twice for better log output
82+
# the xcode tests are a bit flaky and they should never fail on this step, as this step only collects the JS test results as junit xml
83+
with:
84+
timeout_minutes: 20
85+
max_attempts: 3
86+
command: set -o pipefail && xcodebuild -project v8ios.xcodeproj -scheme TestRunner -resultBundlePath $HOME/test_results -destination platform\=iOS\ Simulator,OS\=16.2,name\=iPhone\ 14\ Pro\ Max build test | xcpretty
87+
on_retry_command: rm -rf $HOME/test_results*
88+
new_command_on_retry: xcodebuild -project v8ios.xcodeproj -scheme TestRunner -resultBundlePath $HOME/test_results -destination platform\=iOS\ Simulator,OS\=16.2,name\=iPhone\ 14\ Pro\ Max build test
89+
- name: Validate Test Results
90+
run: |
91+
xcparse attachments $HOME/test_results.xcresult $HOME/test-out
92+
find $HOME/test-out -name "*junit*.xml" -maxdepth 1 -print0 | xargs -n 1 -0 npx junit-cli-report-viewer
93+
find $HOME/test-out -name "*junit*.xml" -maxdepth 1 -print0 | xargs -n 1 -0 npx verify-junit-xml

TestRunnerTests/Embassy/TCPSocket.swift

+5-4
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public final class TCPSocket {
114114
let size = socklen_t(MemoryLayout<sockaddr_in6>.size)
115115
// bind the address and port on socket
116116
guard withUnsafePointer(to: &address, { pointer in
117-
return pointer.withMemoryRebound(to: sockaddr.self, capacity: Int(size)) { pointer in
117+
return UnsafeRawPointer(pointer).withMemoryRebound(to: sockaddr.self, capacity: Int(size)) { pointer in
118118
return SystemLibrary.bind(fileDescriptor, pointer, size) >= 0
119119
}
120120
}) else {
@@ -135,7 +135,7 @@ public final class TCPSocket {
135135
var address = sockaddr_in6()
136136
var size = socklen_t(MemoryLayout<sockaddr_in6>.size)
137137
let clientFileDescriptor = withUnsafeMutablePointer(to: &address) { pointer in
138-
return pointer.withMemoryRebound(to: sockaddr.self, capacity: Int(size)) { pointer in
138+
return UnsafeMutableRawPointer(pointer).withMemoryRebound(to: sockaddr.self, capacity: Int(size)) { pointer in
139139
return SystemLibrary.accept(fileDescriptor, pointer, &size)
140140
}
141141
}
@@ -218,7 +218,8 @@ public final class TCPSocket {
218218
) throws -> (String, Int) {
219219
var address = sockaddr_storage()
220220
var size = socklen_t(MemoryLayout<sockaddr_storage>.size)
221-
return try withUnsafeMutablePointer(to: &address) { pointer in
221+
return try withUnsafeMutablePointer(to: &address) { unsafePointer in
222+
let pointer = UnsafeMutableRawPointer(unsafePointer)
222223
let result = pointer.withMemoryRebound(
223224
to: sockaddr.self,
224225
capacity: Int(size)
@@ -228,7 +229,7 @@ public final class TCPSocket {
228229
guard result >= 0 else {
229230
throw OSError.lastIOError()
230231
}
231-
switch Int32(pointer.pointee.ss_family) {
232+
switch Int32(unsafePointer.pointee.ss_family) {
232233
case AF_INET:
233234
return try pointer.withMemoryRebound(
234235
to: sockaddr_in.self,

TestRunnerTests/TestRunnerTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ class TestRunnerTests: XCTestCase {
6363
app.launchEnvironment["REPORT_BASEURL"] = "http://[::1]:\(port)/junit_report"
6464
app.launch()
6565

66-
wait(for: [runtimeUnitTestsExpectation], timeout: 60.0, enforceOrder: true)
66+
wait(for: [runtimeUnitTestsExpectation], timeout: 300.0, enforceOrder: true)
6767
}
6868
}

build_all.sh

+1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ rm -rf ./dist
66
./build_metadata_generator.sh
77
./build_nativescript.sh
88
./build_tklivesync.sh
9+
./prepare_dSYMs.sh
910
./build_npm.sh

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@
2424
"build-v8-source": "./build_v8_source.sh",
2525
"build-v8-source-catalyst": "./build_v8_source_catalyst.sh",
2626
"build": "./build_all.sh",
27+
"setup-ci": "./build_metadata_generator.sh",
2728
"update-version": "./update_version.sh",
2829
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s"
2930
},
3031
"license": "Apache-2.0",
3132
"devDependencies": {
32-
"conventional-changelog-cli": "^2.1.1"
33+
"conventional-changelog-cli": "^2.1.1",
34+
"dayjs": "^1.11.7",
35+
"semver": "^7.5.0"
3336
}
3437
}

prepare_dSYMs.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
set -e
3+
4+
OUTFOLDER="./dist/dSYMs"
5+
6+
mkdir -p "$OUTFOLDER"
7+
8+
for framework_path in ./dist/NativeScript.xcframework/ios*; do
9+
DSYMPATH="$framework_path/dSYMs/NativeScript.framework.dSYM"
10+
if [ -d "$DSYMPATH" ]; then
11+
OUTPATH="$OUTFOLDER/$(basename $framework_path)NativeScript.framework.dSYM"
12+
echo "Copying $DSYMPATH to $OUTPATH"
13+
cp -r "$DSYMPATH" "$OUTPATH"
14+
fi
15+
done
16+

0 commit comments

Comments
 (0)