Skip to content

Commit ebdee46

Browse files
Adding workflows for node linux builds and script to bundle them in a way usable for our internal systems
1 parent 084d761 commit ebdee46

3 files changed

Lines changed: 311 additions & 0 deletions

File tree

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Build node-fibers with prebuilt Node
2+
3+
on:
4+
workflow_dispatch:
5+
workflow_run:
6+
workflows: [Build Node]
7+
types:
8+
- completed
9+
#pull_request:
10+
#paths: .github/workflows/build-node-fibers.yml
11+
#push:
12+
#branches:
13+
#- v20.18.3
14+
#- workflows-for-v20.18.3
15+
16+
jobs:
17+
build-fibers:
18+
strategy:
19+
matrix:
20+
include:
21+
- platform: linux
22+
arch: x64
23+
runs_on: ubuntu-22.04
24+
- platform: linux
25+
arch: arm64
26+
runs_on: ubuntu-22.04-arm
27+
runs-on: ${{ matrix.runs_on }}
28+
29+
env:
30+
NODE_VERSION: v20.18.3
31+
32+
steps:
33+
- name: Debug Matrix Values
34+
run: |
35+
echo "Matrix platform: ${{ matrix.platform }}"
36+
echo "Matrix arch: ${{ matrix.arch }}"
37+
38+
- name: Download Node archive
39+
run: |
40+
gh release download node-${{ env.NODE_VERSION }}-release \
41+
--repo asana/node \
42+
--pattern "node-${{ env.NODE_VERSION }}-${{ matrix.platform }}-${{ matrix.arch }}-LATEST.tar.xz"
43+
env:
44+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
46+
- name: Extract Node archive
47+
run: |
48+
mkdir -p node-install
49+
tar -C node-install -xJf node-${{ env.NODE_VERSION }}-${{ matrix.platform }}-${{ matrix.arch }}-LATEST.tar.xz
50+
echo "$GITHUB_WORKSPACE/node-install/usr/local/bin" >> $GITHUB_PATH
51+
52+
- name: Verify Node Binary Architecture
53+
run: |
54+
echo "Node File:"
55+
file $GITHUB_WORKSPACE/node-install/usr/local/bin/node
56+
echo "Runner architecture:"
57+
uname -m
58+
59+
- name: Checkout node-fibers fork
60+
uses: actions/checkout@v3
61+
with:
62+
repository: asana/node-fibers
63+
ref: jackstrohm_node20_fibers
64+
path: node-fibers
65+
66+
- name: Build node-fibers
67+
working-directory: node-fibers
68+
run: |
69+
which node
70+
node -v
71+
node -p "process.arch"
72+
npm install --nodedir="$GITHUB_WORKSPACE/node-install/usr/local"
73+
npm test || true
74+
rm bin/repl
75+
find .
76+
77+
- name: Find and archive fibers.node
78+
run: |
79+
# Find the directory under bin/ that contains fibers.node
80+
FIBERS_PATH=$(find ./node-fibers/bin -type f -name fibers.node | head -n1)
81+
FIBERS_DIR=$(dirname "$FIBERS_PATH")
82+
ARCHIVE_NAME=$(basename "$FIBERS_DIR").tar.gz
83+
echo "ARCHIVE_NAME=$ARCHIVE_NAME" >> $GITHUB_ENV
84+
tar -czf "$ARCHIVE_NAME" -C "$(dirname "$FIBERS_DIR")" "$(basename "$FIBERS_DIR")"
85+
86+
- name: Upload archive to release
87+
uses: softprops/action-gh-release@v1
88+
with:
89+
name: node-${{ env.NODE_VERSION }}-LATEST
90+
tag_name: node-${{ env.NODE_VERSION }}-release
91+
files: ${{ env.ARCHIVE_NAME }}
92+
env:
93+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/build-node.yml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: Build Node
2+
3+
on:
4+
push:
5+
branches:
6+
- v20.18.3
7+
- workflows-for-v20.18.3
8+
pull_request:
9+
paths: .github/workflows/build-node.yml
10+
11+
jobs:
12+
build-node:
13+
name: Build ${{ matrix.platform }}-${{ matrix.arch }}
14+
strategy:
15+
matrix:
16+
include:
17+
- platform: linux
18+
arch: x64
19+
runs_on: ubuntu-22.04
20+
- platform: linux
21+
arch: arm64
22+
runs_on: ubuntu-22.04-arm
23+
runs-on: ${{ matrix.runs_on }}
24+
25+
env:
26+
S3_BUCKET: your-bucket-name
27+
AWS_REGION: us-east-1
28+
29+
steps:
30+
- name: Checkout Node fork
31+
uses: actions/checkout@v3
32+
with:
33+
repository: Asana/node
34+
path: node
35+
ref: ${{ github.event_name == 'pull_request' && format('refs/pull/{0}/merge', github.event.pull_request.number) || github.ref_name }}
36+
token: ${{ secrets.GITHUB_TOKEN }}
37+
38+
- name: Extract Node Version
39+
id: extract-node-version
40+
run: |
41+
NODE_MAJOR_VERSION=$(grep '#define NODE_MAJOR_VERSION' node/src/node_version.h | awk '{print $3}')
42+
NODE_MINOR_VERSION=$(grep '#define NODE_MINOR_VERSION' node/src/node_version.h | awk '{print $3}')
43+
NODE_PATCH_VERSION=$(grep '#define NODE_PATCH_VERSION' node/src/node_version.h | awk '{print $3}')
44+
NODE_VERSION="v${NODE_MAJOR_VERSION}.${NODE_MINOR_VERSION}.${NODE_PATCH_VERSION}"
45+
echo "NODE_VERSION=${NODE_VERSION}" >> $GITHUB_ENV
46+
47+
- name: Set build metadata
48+
id: meta
49+
working-directory: node
50+
run: |
51+
TIMESTAMP=$(date -u +%Y-%m-%dT%H-%M)
52+
SHORT_SHA=$(git rev-parse --short HEAD)
53+
echo "BUILD_ID=${TIMESTAMP}-${SHORT_SHA}" >> $GITHUB_ENV
54+
echo "build_id=${TIMESTAMP}-${SHORT_SHA}" >> $GITHUB_OUTPUT
55+
56+
- name: Install dependencies (Linux)
57+
if: matrix.platform == 'linux'
58+
run: |
59+
sudo apt-get update
60+
sudo apt-get install -y python3 g++ make curl tar xz-utils
61+
62+
- name: Build Node (linux)
63+
working-directory: node
64+
if: matrix.platform == 'linux'
65+
run: |
66+
./configure --experimental-enable-pointer-compression
67+
make -j4 install DESTDIR=$GITHUB_WORKSPACE/node-install
68+
69+
- name: Build Node (darwin)
70+
working-directory: node
71+
if: matrix.platform == 'darwin'
72+
run: |
73+
./configure --experimental-enable-pointer-compression --without-snapshot
74+
make -j2 install DESTDIR=$GITHUB_WORKSPACE/node-install
75+
76+
- name: Archive Node
77+
run: |
78+
mkdir -p artifacts
79+
FILENAME=node-${NODE_VERSION}-${{ matrix.platform }}-${{ matrix.arch }}-${{ steps.meta.outputs.build_id }}.tar.xz
80+
FILENAME_LATEST=node-${NODE_VERSION}-${{ matrix.platform }}-${{ matrix.arch }}-LATEST.tar.xz
81+
tar -C node-install -cJf artifacts/$FILENAME .
82+
cp artifacts/$FILENAME artifacts/$FILENAME_LATEST
83+
echo "NODE_ARCHIVE=$FILENAME" >> $GITHUB_ENV
84+
echo "NODE_ARCHIVE_LATEST=$FILENAME_LATEST" >> $GITHUB_ENV
85+
86+
- name: Upload Node archive
87+
uses: actions/upload-artifact@v4
88+
with:
89+
name: node-${{ env.NODE_VERSION }}-${{ matrix.platform }}-${{ matrix.arch }}-${{ steps.meta.outputs.build_id }}
90+
path: artifacts/${{ env.NODE_ARCHIVE }}
91+
92+
- name: Upload Node archive latest
93+
uses: actions/upload-artifact@v4
94+
with:
95+
name: node-${{ env.NODE_VERSION }}-${{ matrix.platform }}-${{ matrix.arch }}-LATEST
96+
path: artifacts/${{ env.NODE_ARCHIVE_LATEST }}
97+
98+
- name: Upload Node archive to release
99+
uses: softprops/action-gh-release@v1
100+
with:
101+
name: node-${{ env.NODE_VERSION }}-LATEST
102+
tag_name: node-${{ env.NODE_VERSION }}-release
103+
files: ./artifacts/${{ env.NODE_ARCHIVE_LATEST }}
104+
env:
105+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

stage_for_s3.sh

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/bin/bash
2+
3+
mkdir stage
4+
cd stage
5+
6+
TIMESTAMP=$(date '+%Y%m%d.%H%M')
7+
8+
echo "Current timestamp is $TIMESTAMP"
9+
10+
gh release download -p "*.gz"
11+
gh release download -p "*.xz"
12+
13+
curl "https://asana-oss-cache.s3.us-east-1.amazonaws.com/node-fibers/fibers-5.0.4.pc.tgz" --output fibers-5.0.4.tar.gz
14+
tar -xzf fibers-5.0.4.tar.gz
15+
16+
ls *.gz | while read a
17+
do
18+
tar -xzf "$a" -C package/bin
19+
rm $a
20+
done
21+
22+
tar -czf temp.tgz package/
23+
rm -fr package
24+
SHORT_HASH=$(cat temp.tgz | sha1sum | cut -c1-4)
25+
echo HASH: $SHORT_HASH
26+
UNIQUE="pc-${TIMESTAMP}-${SHORT_HASH}"
27+
28+
mv temp.tgz fibers-5.0.4-${UNIQUE}.tgz
29+
30+
#for file in *.tar.xz; do
31+
#if [[ "$file" == *-LATEST.tar.xz ]]; then
32+
## Extract base name without the -LATEST part
33+
#base="${file%-LATEST.tar.xz}"
34+
#
35+
## New filename
36+
#new_name="${base}-${UNIQUE}.tar.xz"
37+
#
38+
#echo "Renaming: $file -> $new_name"
39+
#mv "$file" "$new_name"
40+
#fi
41+
#done
42+
43+
for file in *.tar.xz; do
44+
if [[ "$file" == *-LATEST.tar.xz ]]; then
45+
base="${file%-LATEST.tar.xz}"
46+
new_name="${base}-${UNIQUE}.tar.xz"
47+
48+
echo "Renaming: $file -> $new_name"
49+
mv "$file" "$new_name"
50+
51+
if [[ "$new_name" =~ node-v([0-9.]+)-(darwin|linux)-(arm64|x64)-pc.*\.tar\.xz$ ]]; then
52+
version="${BASH_REMATCH[1]}"
53+
os="${BASH_REMATCH[2]}"
54+
arch="${BASH_REMATCH[3]}"
55+
target_dir="node-v${version}-${os}-${arch}"
56+
57+
echo "Target Dir: $target_dir"
58+
mkdir $target_dir
59+
tar -xzf "$new_name" -C "$target_dir"
60+
mv $target_dir/usr/local/* $target_dir
61+
rm -fr $target_dir/usr/local
62+
63+
tar -cJf "$new_name" $target_dir
64+
65+
rm -fr $target_dir
66+
67+
echo "✅ Done: Archive now contains:"
68+
tar -tf "$new_name" | head
69+
70+
# Make a clean working dir
71+
#temp_dir="$(mktemp -d)"
72+
#extract_dir="${temp_dir}/extract"
73+
#mkdir -p "$extract_dir"
74+
75+
#echo "Extracting $new_name..."
76+
#tar -xf "$new_name" -C "$extract_dir"
77+
78+
## Move usr/local to node-v*/...
79+
#if [ -d "$extract_dir/usr/local" ]; then
80+
#echo "Rewriting archive paths under $target_dir/"
81+
#mkdir -p "$extract_dir/$target_dir"
82+
#mv "$extract_dir/usr/local/"* "$extract_dir/$target_dir/"
83+
#rm -rf "$extract_dir/usr" # Clean up
84+
#else
85+
#echo "Error: expected usr/local inside archive, but not found."
86+
#ls "$extract_dir"
87+
#exit 1
88+
#fi
89+
90+
#echo "Repacking $new_name with new paths..."
91+
#(
92+
#cd "$extract_dir"
93+
#tar -cJf "$new_name" "$target_dir"
94+
#)
95+
#
96+
#echo "✅ Done: Archive now contains:"
97+
#tar -tf "$new_name" | head
98+
99+
#rm -rf "$temp_dir"
100+
else
101+
echo "Warning: Skipped $new_name due to unexpected filename format."
102+
fi
103+
fi
104+
done
105+
106+
107+
cd ..
108+
mv stage node-${UNIQUE}
109+
110+
echo "Files are in node-${UNIQUE}, please upload to s3"
111+
112+
113+

0 commit comments

Comments
 (0)