Skip to content

Commit

Permalink
fix: change swc update command
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-ippolito committed Nov 12, 2024
1 parent 38d2f96 commit d6ce352
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 24 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/update-swc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
- cron: '0 0 * * 1' # Every Monday at 00:00 UTC

env:
NODE_VERSION: lts/*
NODE_VERSION: 22

jobs:
update-swc:
Expand All @@ -26,6 +26,8 @@ jobs:

- name: Set up Node.js
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: ${{ env.NODE_VERSION }}

- name: Check if SWC update is required
id: version-check
Expand All @@ -48,7 +50,7 @@ jobs:
- name: Update SWC
if: steps.version-check.outputs.UPDATE_REQUIRED == 'true'
run: ./tools/update-swc.sh
run: node --run build:wasm

- name: Create Pull Request with first commit
if: steps.version-check.outputs.UPDATE_REQUIRED == 'true'
Expand Down
2 changes: 1 addition & 1 deletion deps/swc/bindings/binding_typescript_wasm/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -eux

export CARGO_PROFILE_RELEASE_LTO="fat"
export CARGO_PROFILE_RELEASE_OPT_LEVEL="z"
wasm-pack build --out-name wasm --release --scope=swc --target nodejs
wasm-pack build --out-namsh e wasm --release --scope=swc --target nodejs
ls -al ./pkg

node ./scripts/patch.mjs
68 changes: 47 additions & 21 deletions tools/build-wasm.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
const WASM_BUILDER_CONTAINER =
"ghcr.io/nodejs/wasm-builder@sha256:975f391d907e42a75b8c72eb77c782181e941608687d4d8694c3e9df415a0970"; // v0.0.9

const { execSync, execFileSync } = require("node:child_process");
const { resolve } = require("node:path");

const WASM_BUILDER_CONTAINER =
"ghcr.io/nodejs/wasm-builder@sha256:975f391d907e42a75b8c72eb77c782181e941608687d4d8694c3e9df415a0970"; // v0.0.9

const ROOT = resolve(__dirname, "../");

let platform = process.env.WASM_PLATFORM;
if (!platform && process.argv[2]) {
platform = execFileSync("docker", [
"info",
"-f",
"{{.OSType}}/{{.Architecture}}",
])
.toString()
.trim();
function getPlatformFromDocker() {
try {
return execFileSync("docker", [
"info",
"-f",
"{{.OSType}}/{{.Architecture}}",
])
.toString()
.trim();
} catch (error) {
console.error(
"Error retrieving platform information from Docker:",
error.message,
);
}
}

if (process.argv[2] === "--docker") {
function runDockerContainer() {
const args = [];
args.push("run");
args.push("--rm");
Expand All @@ -43,14 +49,34 @@ if (process.argv[2] === "--docker") {
args.push("./tools/build-wasm.js");
console.log(`> docker ${args}\n\n`);
execFileSync("docker", args, { stdio: "inherit" });
}

let platform = process.env.WASM_PLATFORM;
if (!platform && process.argv[2]) {
platform = getPlatformFromDocker();
}

// If "--docker" is passed, run the Docker container with the specified mounts
if (process.argv[2] === "--docker") {
runDockerContainer();
process.exit(0);
}

execSync(
`cd bindings/binding_typescript_wasm && \
cargo install --locked wasm-pack && \
PATH=/home/node/.cargo/bin:$PATH && \
./scripts/build.sh && \
cp -r pkg/* ../../lib`,
{ stdio: "inherit" },
);
const wasmBindingPath = `${ROOT}/bindings/binding_typescript_wasm`;

const commands = [
`cd ${wasmBindingPath}`,
"cargo install --locked wasm-pack",
"export PATH=/home/node/.cargo/bin:$PATH",
`sh ${wasmBindingPath}/scripts/build.sh`,
`cp -r ${wasmBindingPath}/pkg/* ${ROOT}/lib`,
];

try {
for (const command of commands) {
execSync(command, { stdio: "inherit" });

Check warning

Code scanning / CodeQL

Shell command built from environment values Medium

This shell command depends on an uncontrolled
absolute path
.
This shell command depends on an uncontrolled
absolute path
.
}
} catch (error) {
console.error("Error executing build command:", error.message);
process.exit(1);
}

0 comments on commit d6ce352

Please sign in to comment.