Skip to content

Commit 6feb8a1

Browse files
cknittcristianoc
authored andcommitted
Build npm package in CI
1 parent 95f833d commit 6feb8a1

File tree

6 files changed

+101
-19
lines changed

6 files changed

+101
-19
lines changed

.github/workflows/ci.yml

+68-14
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
branches: [master]
88

99
jobs:
10-
test:
10+
build:
1111
strategy:
1212
fail-fast: false
1313
matrix:
@@ -48,7 +48,7 @@ jobs:
4848
opam-depext: false
4949

5050
- name: Use Node.js
51-
uses: actions/setup-node@v2.1.5
51+
uses: actions/setup-node@v3
5252
with:
5353
node-version: 16
5454

@@ -57,17 +57,6 @@ jobs:
5757
env:
5858
RESCRIPT_FORCE_REBUILD: 1
5959

60-
- name: ninja config
61-
if: runner.os != 'Windows'
62-
run: opam exec -- node ./scripts/ninja.js config
63-
64-
- name: ninja build
65-
if: runner.os != 'Windows'
66-
run: opam exec -- node ./scripts/ninja.js build
67-
68-
- name: Check for changes in lib folder
69-
run: git diff --exit-code lib/js lib/es6
70-
7160
- name: Run tests
7261
if: runner.os != 'Windows'
7362
run: opam exec -- node scripts/ciTest.js -all
@@ -80,8 +69,73 @@ jobs:
8069
id: get_artifact_info
8170
run: node .github/workflows/get_artifact_info.js
8271

83-
- name: Upload artifacts
72+
- name: "Upload artifacts: binaries"
8473
uses: actions/upload-artifact@v3
8574
with:
8675
name: ${{ steps.get_artifact_info.outputs.artifact_name }}
8776
path: ${{ steps.get_artifact_info.outputs.artifact_path }}
77+
78+
- name: "Upload artifacts: lib/ocaml"
79+
if: runner.os == 'Linux'
80+
uses: actions/upload-artifact@v3
81+
with:
82+
name: lib-ocaml
83+
path: lib/ocaml
84+
85+
# Important: the ninja build must run after the artifact upload because for some reason
86+
# the bsc.exe created by the ninja build does not find the Pervasives module.
87+
# So this is run here just to test the normal dev workflow, too.
88+
- name: ninja config
89+
if: runner.os != 'Windows'
90+
run: opam exec -- node ./scripts/ninja.js config
91+
92+
- name: ninja build
93+
if: runner.os != 'Windows'
94+
run: opam exec -- node ./scripts/ninja.js build
95+
96+
- name: Check for changes in lib folder
97+
run: git diff --exit-code lib/js lib/es6
98+
99+
package:
100+
needs: build
101+
runs-on: ubuntu-latest
102+
103+
steps:
104+
- name: Checkout
105+
uses: actions/checkout@v3
106+
with:
107+
submodules: true
108+
109+
- name: Use Node.js
110+
uses: actions/setup-node@v3
111+
with:
112+
node-version: 16
113+
114+
- name: NPM install
115+
run: npm ci --ignore-scripts
116+
117+
- name: Download artifacts
118+
uses: actions/download-artifact@v3
119+
120+
- name: Copy artifacts
121+
run: ./scripts/moveArtifacts.sh
122+
123+
- name: Create ninja.tar.gz
124+
run: git -C ninja archive --format=tar.gz HEAD -o ../vendor/ninja.tar.gz
125+
126+
- name: Run prepublish.js
127+
run: node ./scripts/prepublish.js -nocheck
128+
129+
- name: npm pack
130+
run: npm pack
131+
132+
- name: Get package info
133+
id: get_package_info
134+
# For pull requests, pass the correct commit SHA explicitly as GITHUB_SHA points to the wrong commit.
135+
run: node .github/workflows/get_package_info.js ${{ github.event.pull_request.head.sha }}
136+
137+
- name: "Upload artifact: npm package tarball"
138+
uses: actions/upload-artifact@v3
139+
with:
140+
name: ${{ steps.get_package_info.outputs.artifact_name }}
141+
path: ${{ steps.get_package_info.outputs.artifact_path }}

.github/workflows/get_package_info.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const fs = require("fs");
2+
3+
const packageSpec = JSON.parse(fs.readFileSync("./package.json", "utf8"));
4+
const { name, version } = packageSpec;
5+
6+
const commitHash = process.argv[2] || process.env.GITHUB_SHA;
7+
const commitHashShort = commitHash.substring(0, 7);
8+
9+
const packageName = `${name}-${version}.tgz`;
10+
const artifactName = `${name}-${version}-${commitHashShort}.tgz`;
11+
12+
fs.renameSync(packageName, artifactName);
13+
14+
// Pass artifactPath and artifactName to subsequent GitHub actions
15+
console.log(`::set-output name=artifact_path::${artifactName}`);
16+
console.log(`::set-output name=artifact_name::${artifactName}`);

.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ ocaml-tree
4747
dummy.opam
4848
dune
4949
dune-project
50+
scripts/moveArtifacts.sh
5051
scripts/deps.js
5152
scripts/format.js
5253
scripts/local_br_clean.sh

jscomp/artifacts.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@
4545
],
4646
"lib": [
4747
"bstracing",
48-
"build.ninja",
49-
"minisocket.js",
50-
"prebuilt.ninja"
48+
"minisocket.js"
5149
],
5250
"lib/4.06.1": [
5351
"bsb_helper.ml",

scripts/moveArtifacts.sh

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
set -e
3+
4+
chmod +x binaries-*/*.exe
5+
6+
mv binaries-darwin/* darwin
7+
mv binaries-darwinarm64/* darwinarm64
8+
mv binaries-linux/* linux
9+
mv binaries-win32/* win32
10+
11+
rmdir binaries-*
12+
13+
mv lib-ocaml lib/ocaml

scripts/prepublish.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ if (!process.argv.includes("-nocheck")) {
103103
check(map);
104104
}
105105

106-
var output = p.spawnSync(`git diff jscomp/artifacts.json`, {
106+
var output = p.spawnSync(`git diff --exit-code jscomp/artifacts.json`, {
107107
cwd: root,
108108
encoding: "utf8",
109109
shell: true,
110110
});
111111

112-
assert(output.status === 0);
113112
console.log("The diff of artifacts", output.stdout);
113+
assert(output.status === 0);

0 commit comments

Comments
 (0)