diff --git a/.github/workflows/build-node-fibers.yml b/.github/workflows/build-node-fibers.yml new file mode 100644 index 00000000000000..9313c34b20d447 --- /dev/null +++ b/.github/workflows/build-node-fibers.yml @@ -0,0 +1,93 @@ +name: Build node-fibers with prebuilt Node + +on: + workflow_dispatch: + workflow_run: + workflows: [Build Node] + types: + - completed + #pull_request: + #paths: .github/workflows/build-node-fibers.yml + #push: + #branches: + #- v20.18.3 + #- workflows-for-v20.18.3 + +jobs: + build-fibers: + strategy: + matrix: + include: + - platform: linux + arch: x64 + runs_on: ubuntu-22.04 + - platform: linux + arch: arm64 + runs_on: ubuntu-22.04-arm + runs-on: ${{ matrix.runs_on }} + + env: + NODE_VERSION: v20.18.3 + + steps: + - name: Debug Matrix Values + run: | + echo "Matrix platform: ${{ matrix.platform }}" + echo "Matrix arch: ${{ matrix.arch }}" + + - name: Download Node archive + run: | + gh release download node-${{ env.NODE_VERSION }}-release \ + --repo asana/node \ + --pattern "node-${{ env.NODE_VERSION }}-${{ matrix.platform }}-${{ matrix.arch }}-LATEST.tar.xz" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract Node archive + run: | + mkdir -p node-install + tar -C node-install -xJf node-${{ env.NODE_VERSION }}-${{ matrix.platform }}-${{ matrix.arch }}-LATEST.tar.xz + echo "$GITHUB_WORKSPACE/node-install/usr/local/bin" >> $GITHUB_PATH + + - name: Verify Node Binary Architecture + run: | + echo "Node File:" + file $GITHUB_WORKSPACE/node-install/usr/local/bin/node + echo "Runner architecture:" + uname -m + + - name: Checkout node-fibers fork + uses: actions/checkout@v3 + with: + repository: asana/node-fibers + ref: jackstrohm_node20_fibers + path: node-fibers + + - name: Build node-fibers + working-directory: node-fibers + run: | + which node + node -v + node -p "process.arch" + npm install --nodedir="$GITHUB_WORKSPACE/node-install/usr/local" + npm test || true + rm bin/repl + find . + + - name: Find and archive fibers.node + run: | + # Find the directory under bin/ that contains fibers.node + FIBERS_PATH=$(find ./node-fibers/bin -type f -name fibers.node | head -n1) + FIBERS_DIR=$(dirname "$FIBERS_PATH") + ARCHIVE_NAME=$(basename "$FIBERS_DIR").tar.gz + echo "ARCHIVE_NAME=$ARCHIVE_NAME" >> $GITHUB_ENV + tar -czf "$ARCHIVE_NAME" -C "$(dirname "$FIBERS_DIR")" "$(basename "$FIBERS_DIR")" + + - name: Upload archive to release + uses: softprops/action-gh-release@v1 + with: + name: node-${{ env.NODE_VERSION }}-LATEST + tag_name: node-${{ env.NODE_VERSION }}-release + files: ${{ env.ARCHIVE_NAME }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/build-node.yml b/.github/workflows/build-node.yml new file mode 100644 index 00000000000000..e97959697d3edb --- /dev/null +++ b/.github/workflows/build-node.yml @@ -0,0 +1,105 @@ +name: Build Node + +on: + push: + branches: + - v20.18.3 + - workflows-for-v20.18.3 + pull_request: + paths: .github/workflows/build-node.yml + +jobs: + build-node: + name: Build ${{ matrix.platform }}-${{ matrix.arch }} + strategy: + matrix: + include: + - platform: linux + arch: x64 + runs_on: ubuntu-22.04 + - platform: linux + arch: arm64 + runs_on: ubuntu-22.04-arm + runs-on: ${{ matrix.runs_on }} + + env: + S3_BUCKET: your-bucket-name + AWS_REGION: us-east-1 + + steps: + - name: Checkout Node fork + uses: actions/checkout@v3 + with: + repository: Asana/node + path: node + ref: ${{ github.event_name == 'pull_request' && format('refs/pull/{0}/merge', github.event.pull_request.number) || github.ref_name }} + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract Node Version + id: extract-node-version + run: | + NODE_MAJOR_VERSION=$(grep '#define NODE_MAJOR_VERSION' node/src/node_version.h | awk '{print $3}') + NODE_MINOR_VERSION=$(grep '#define NODE_MINOR_VERSION' node/src/node_version.h | awk '{print $3}') + NODE_PATCH_VERSION=$(grep '#define NODE_PATCH_VERSION' node/src/node_version.h | awk '{print $3}') + NODE_VERSION="v${NODE_MAJOR_VERSION}.${NODE_MINOR_VERSION}.${NODE_PATCH_VERSION}" + echo "NODE_VERSION=${NODE_VERSION}" >> $GITHUB_ENV + + - name: Set build metadata + id: meta + working-directory: node + run: | + TIMESTAMP=$(date -u +%Y-%m-%dT%H-%M) + SHORT_SHA=$(git rev-parse --short HEAD) + echo "BUILD_ID=${TIMESTAMP}-${SHORT_SHA}" >> $GITHUB_ENV + echo "build_id=${TIMESTAMP}-${SHORT_SHA}" >> $GITHUB_OUTPUT + + - name: Install dependencies (Linux) + if: matrix.platform == 'linux' + run: | + sudo apt-get update + sudo apt-get install -y python3 g++ make curl tar xz-utils + + - name: Build Node (linux) + working-directory: node + if: matrix.platform == 'linux' + run: | + ./configure --experimental-enable-pointer-compression + make -j4 install DESTDIR=$GITHUB_WORKSPACE/node-install + + - name: Build Node (darwin) + working-directory: node + if: matrix.platform == 'darwin' + run: | + ./configure --experimental-enable-pointer-compression --without-snapshot + make -j2 install DESTDIR=$GITHUB_WORKSPACE/node-install + + - name: Archive Node + run: | + mkdir -p artifacts + FILENAME=node-${NODE_VERSION}-${{ matrix.platform }}-${{ matrix.arch }}-${{ steps.meta.outputs.build_id }}.tar.xz + FILENAME_LATEST=node-${NODE_VERSION}-${{ matrix.platform }}-${{ matrix.arch }}-LATEST.tar.xz + tar -C node-install -cJf artifacts/$FILENAME . + cp artifacts/$FILENAME artifacts/$FILENAME_LATEST + echo "NODE_ARCHIVE=$FILENAME" >> $GITHUB_ENV + echo "NODE_ARCHIVE_LATEST=$FILENAME_LATEST" >> $GITHUB_ENV + + - name: Upload Node archive + uses: actions/upload-artifact@v4 + with: + name: node-${{ env.NODE_VERSION }}-${{ matrix.platform }}-${{ matrix.arch }}-${{ steps.meta.outputs.build_id }} + path: artifacts/${{ env.NODE_ARCHIVE }} + + - name: Upload Node archive latest + uses: actions/upload-artifact@v4 + with: + name: node-${{ env.NODE_VERSION }}-${{ matrix.platform }}-${{ matrix.arch }}-LATEST + path: artifacts/${{ env.NODE_ARCHIVE_LATEST }} + + - name: Upload Node archive to release + uses: softprops/action-gh-release@v1 + with: + name: node-${{ env.NODE_VERSION }}-LATEST + tag_name: node-${{ env.NODE_VERSION }}-release + files: ./artifacts/${{ env.NODE_ARCHIVE_LATEST }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/stage_for_s3.sh b/stage_for_s3.sh new file mode 100755 index 00000000000000..12aeead6550f9a --- /dev/null +++ b/stage_for_s3.sh @@ -0,0 +1,113 @@ +#!/bin/bash + +mkdir stage +cd stage + +TIMESTAMP=$(date '+%Y%m%d.%H%M') + +echo "Current timestamp is $TIMESTAMP" + +gh release download -p "*.gz" +gh release download -p "*.xz" + +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 +tar -xzf fibers-5.0.4.tar.gz + +ls *.gz | while read a +do + tar -xzf "$a" -C package/bin + rm $a +done + +tar -czf temp.tgz package/ +rm -fr package +SHORT_HASH=$(cat temp.tgz | sha1sum | cut -c1-4) +echo HASH: $SHORT_HASH +UNIQUE="pc-${TIMESTAMP}-${SHORT_HASH}" + +mv temp.tgz fibers-5.0.4-${UNIQUE}.tgz + +#for file in *.tar.xz; do + #if [[ "$file" == *-LATEST.tar.xz ]]; then + ## Extract base name without the -LATEST part + #base="${file%-LATEST.tar.xz}" +# + ## New filename + #new_name="${base}-${UNIQUE}.tar.xz" +# + #echo "Renaming: $file -> $new_name" + #mv "$file" "$new_name" + #fi +#done + +for file in *.tar.xz; do + if [[ "$file" == *-LATEST.tar.xz ]]; then + base="${file%-LATEST.tar.xz}" + new_name="${base}-${UNIQUE}.tar.xz" + + echo "Renaming: $file -> $new_name" + mv "$file" "$new_name" + + if [[ "$new_name" =~ node-v([0-9.]+)-(darwin|linux)-(arm64|x64)-pc.*\.tar\.xz$ ]]; then + version="${BASH_REMATCH[1]}" + os="${BASH_REMATCH[2]}" + arch="${BASH_REMATCH[3]}" + target_dir="node-v${version}-${os}-${arch}" + + echo "Target Dir: $target_dir" + mkdir $target_dir + tar -xzf "$new_name" -C "$target_dir" + mv $target_dir/usr/local/* $target_dir + rm -fr $target_dir/usr/local + + tar -cJf "$new_name" $target_dir + + rm -fr $target_dir + + echo "✅ Done: Archive now contains:" + tar -tf "$new_name" | head + + # Make a clean working dir + #temp_dir="$(mktemp -d)" + #extract_dir="${temp_dir}/extract" + #mkdir -p "$extract_dir" + + #echo "Extracting $new_name..." + #tar -xf "$new_name" -C "$extract_dir" + + ## Move usr/local to node-v*/... + #if [ -d "$extract_dir/usr/local" ]; then + #echo "Rewriting archive paths under $target_dir/" + #mkdir -p "$extract_dir/$target_dir" + #mv "$extract_dir/usr/local/"* "$extract_dir/$target_dir/" + #rm -rf "$extract_dir/usr" # Clean up + #else + #echo "Error: expected usr/local inside archive, but not found." + #ls "$extract_dir" + #exit 1 + #fi + + #echo "Repacking $new_name with new paths..." + #( + #cd "$extract_dir" + #tar -cJf "$new_name" "$target_dir" + #) +# + #echo "✅ Done: Archive now contains:" + #tar -tf "$new_name" | head + + #rm -rf "$temp_dir" + else + echo "Warning: Skipped $new_name due to unexpected filename format." + fi + fi +done + + +cd .. +mv stage node-${UNIQUE} + +echo "Files are in node-${UNIQUE}, please upload to s3" + + +