Skip to content

Commit b4bed25

Browse files
authored
fix(ci): test container not being pushed (#63)
1 parent 3526b55 commit b4bed25

8 files changed

+86
-24
lines changed

.github/workflows/asan.yml

+40-14
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,62 @@ jobs:
88
runs-on: ubuntu-latest
99

1010
steps:
11-
- uses: actions/checkout@v3
12-
11+
- name: Checkout
12+
uses: actions/checkout@v3
1313
- name: Setup node
1414
uses: actions/[email protected]
1515
with:
1616
node-version: 18
1717
check-latest: true
1818
cache: 'npm'
19+
- name: Setup java 17
20+
uses: actions/setup-java@v3
21+
with:
22+
distribution: 'temurin'
23+
java-version: '17'
24+
25+
- name: Rust Cache
26+
uses: Swatinem/[email protected]
27+
- name: Cache java definitions
28+
uses: actions/cache@v3
29+
with:
30+
path: '**/test/javaDefinitions'
31+
key: ${{runner.os}}-javaDefinitions
1932

2033
- name: Install dependencies
2134
run: npm ci
35+
- name: Build
36+
run: npm run build
37+
- name: Generate test types
38+
run: npm run generateTestTypes -- --system-test
39+
- name: Remove target and dist directories
40+
run: |
41+
rm -rf dist
42+
mv target target.bak
43+
cp -r test/javaDefinitions javaDefinitions.bak
2244
2345
- name: Run tests with address sanitizer
2446
uses: addnab/docker-run-action@v3
2547
with:
2648
registry: gcr.io
27-
image: ghcr.io/markusjx/prebuilt-debug-jdk:17-bullseye
49+
image: ghcr.io/markusjx/node-java-bridge/java-bridge-asan-testcontainer:latest
2850
options: -v ${{ github.workspace }}:/app
2951
run: |
30-
curl -fsSL https://deb.nodesource.com/setup_18.x | bash - >> /dev/null
31-
apt-get install -yqq nodejs
32-
cargo update
3352
npm run build:napi:debug -- --target=x86_64-unknown-linux-gnu \
3453
--cargo-flags="-Zbuild-std"
35-
npm run postbuild
54+
npm run build:ts
55+
npm run generateTestTypes -- --update-imports
56+
npm run mocha -- --timeout 10000
3657
37-
export LD_PRELOAD=$(clang -print-file-name=libclang_rt.asan-x86_64.so)
38-
export RUST_BACKTRACE=1
39-
export FORCE_RUN_ALL_TESTS=true
40-
export INCREASE_TIMEOUT=true
41-
export SKIP_CLASS_TEST=true
42-
export DEBUG='napi:*'
43-
npm run testOnly
58+
- name: Create test summary
59+
uses: test-summary/action@dist
60+
if: always()
61+
with:
62+
show: all
63+
paths: testResults.xml
64+
- name: Move target back
65+
run: |
66+
sudo rm -rf target
67+
mv target.bak target
68+
sudo rm -rf test/javaDefinitions
69+
mv javaDefinitions.bak test/javaDefinitions

.github/workflows/system_test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
4545
- name: Run tests
4646
uses: addnab/docker-run-action@v3
47-
timeout-minutes: 120
47+
timeout-minutes: 180
4848
with:
4949
image: arm64v8/node:${{matrix.node-version}}-bullseye
5050
options: -v ${{github.workspace}}/test:/github/workspace -w /github/workspace/system_test

.github/workflows/test-container.yml

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ jobs:
3838
- name: Log into registry
3939
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login $REGISTRY -u ${{ github.actor }} --password-stdin
4040
- name: Push latest image
41-
if: ${{github.event.inputs.set-latest == 'true'}}
4241
run: |
4342
IMAGE_ID=$REGISTRY/${{ github.repository }}
4443
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')/$IMAGE_NAME

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ jobs:
147147
run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
148148
- name: Run tests
149149
uses: addnab/docker-run-action@v3
150-
timeout-minutes: 120
150+
timeout-minutes: 180
151151
with:
152152
image: arm64v8/node:${{matrix.node-version}}-bullseye
153153
options: -v ${{ github.workspace }}:/github/workspace -w /github/workspace

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@
5656
"build:java:win32": "cd java-src && .\\gradlew.bat shadowJar",
5757
"prepublishOnly": "napi prepublish -t npm",
5858
"test": "npm run testOnly",
59-
"testOnly": "mocha -r ts-node/register test/*.test.ts --reporter mocha-multi-reporters --reporter-options configFile=mocha-reporter-config.json",
59+
"testOnly": "npm run mocha",
6060
"pretestOnly": "npm run generateTestTypes",
61+
"mocha": "mocha -r ts-node/register test/*.test.ts --reporter mocha-multi-reporters --reporter-options configFile=mocha-reporter-config.json",
6162
"pretest": "npm run build",
6263
"version": "napi version",
6364
"prettier": "prettier --write .",

test/ArrayListTest.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { it } from 'mocha';
33
import { expect } from 'chai';
44
import { shouldIncreaseTimeout } from './testUtil';
55

6-
const timeout = shouldIncreaseTimeout ? 10e3 : 2e3;
6+
const timeout = shouldIncreaseTimeout ? 20e3 : 2e3;
77

88
declare class ListClass<T extends JavaType> extends JavaClass {
99
containsSync(element: T): boolean;

test/Dockerfile-test-template.hbs

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ ENV JAVA_HOME=/jdk
1818
ENV RUSTFLAGS="-Clinker=clang -Zsanitizer=address"
1919
ENV RUSTDOCFLAGS="-Clinker=clang -Zsanitizer=address"
2020
ENV ASAN_OPTIONS="detect_leaks=0"
21+
ENV RUST_BACKTRACE=1
22+
ENV FORCE_RUN_ALL_TESTS=true
23+
ENV INCREASE_TIMEOUT=true
24+
#ENV SKIP_CLASS_TEST=true
25+
ENV CI=true
2126
ENV PATH="$PATH:/root/.cargo/bin:/jdk/bin:/nodejs/node:/nodejs/npm"
2227

2328
WORKDIR /app

test/generateTestTypes.ts

+36-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import type { Ora } from 'ora';
55
import isCi from 'is-ci';
66
import type { ChalkInstance } from 'chalk';
77
import { hashElement } from 'folder-hash';
8+
import { glob as _glob } from 'glob';
9+
import { promisify } from 'util';
810

911
const isSystemTest = process.argv.includes('--system-test');
1012

@@ -130,8 +132,37 @@ async function run() {
130132
spinner?.succeed('Generated Java definitions');
131133
}
132134

133-
run().catch((err) => {
134-
spinner?.fail('Failed to convert classes');
135-
console.error(err);
136-
process.exit(1);
137-
});
135+
async function updateImports(): Promise<void> {
136+
console.log('Updating imports');
137+
138+
const glob = promisify(_glob);
139+
await Promise.all(
140+
(
141+
await glob('**/*.ts', { cwd: outDir })
142+
)
143+
.map((file) => path.join(outDir, file))
144+
.map(async (file) => {
145+
const contents = await fs.promises.readFile(file, 'utf8');
146+
await fs.promises.writeFile(
147+
file,
148+
contents.replaceAll(
149+
'from "java-bridge";',
150+
`from ${JSON.stringify(path.join(__dirname, '..'))};`
151+
)
152+
);
153+
})
154+
);
155+
}
156+
157+
if (process.argv.includes('--update-imports')) {
158+
updateImports().catch((err) => {
159+
console.error(err);
160+
process.exit(1);
161+
});
162+
} else {
163+
run().catch((err) => {
164+
spinner?.fail('Failed to convert classes');
165+
console.error(err);
166+
process.exit(1);
167+
});
168+
}

0 commit comments

Comments
 (0)