Skip to content

Commit

Permalink
Develop (#25)
Browse files Browse the repository at this point in the history
CI
Napi multiple workers
  • Loading branch information
alshdavid authored May 21, 2024
1 parent c047f4b commit c4199c9
Show file tree
Hide file tree
Showing 41 changed files with 559 additions and 464 deletions.
188 changes: 188 additions & 0 deletions .github/actions/build-mach/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
name: 'alshdavid/build'
description: "Build Project"

inputs:
os:
description: 'target operating system'
default: ${{ runner.os == 'Linux' && 'linux' || runner.os == 'macOS' && 'macos' || runner.os == 'Windows' && 'windows' }}
arch:
description: 'target CPU architecture'
default: ${{ runner.arch == 'ARM64' && 'arm64' || runner.arch == 'X64' && 'amd64' }}
profile:
description: 'Build profile'
default: "release"
mach_version:
description: 'prepare packages for publishing'
default: ''

runs:
using: 'composite'
steps:
# Builds for Native Hosts
- name: "Build Mach (native host - Unix)"
if: |
(runner.os == 'Linux' && runner.arch == 'X64' &&
inputs.os == 'linux' && inputs.arch == 'amd64') ||
(runner.os == 'Linux' && runner.arch == 'ARM64' &&
inputs.os == 'linux' && inputs.arch == 'arm64') ||
(runner.os == 'macOS' && runner.arch == 'X64' &&
inputs.os == 'macos' && inputs.arch == 'amd64') ||
(runner.os == 'macOS' && runner.arch == 'ARM64' &&
inputs.os == 'macos' && inputs.arch == 'arm64')
shell: bash
env:
os: "${{inputs.os}}"
arch: "${{inputs.arch}}"
MACH_VERSION: "${{inputs.mach_version}}"
profile: "${{inputs.profile}}"
run: |
source .github/actions/setup-env/setup-env.bash
bash .github/actions/build-mach/build.bash
- name: "Build Mach (native host - Windows)"
if: |
(runner.os == 'Windows' && runner.arch == 'X64' &&
inputs.os == 'windows' && inputs.arch == 'amd64') ||
(runner.os == 'Windows' && runner.arch == 'ARM64' &&
inputs.os == 'windows' && inputs.arch == 'arm64')
shell: powershell
env:
os: "${{inputs.os}}"
arch: "${{inputs.arch}}"
MACH_VERSION: "${{inputs.mach_version}}"
profile: "${{inputs.profile}}"
run: |
. .github/actions/setup-env/setup-env.ps1
. .github/actions/build-mach/build.ps1
# Cross Compilation
- name: "Build Mach (cross build - Linux arm64 on amd64)"
if: |
(runner.os == 'Linux' && runner.arch == 'X64' &&
inputs.os == 'linux' && inputs.arch == 'arm64')
shell: bash
env:
os: "${{inputs.os}}"
arch: "${{inputs.arch}}"
MACH_VERSION: "${{inputs.mach_version}}"
profile: "${{inputs.profile}}"
run: |
source .github/actions/setup-env/setup-env.bash
export CC=aarch64-linux-gnu-gcc
export MACH_SKIP_POST_INSTALL="true"
sudo apt-get update
sudo apt-get install gcc-aarch64-linux-gnu build-essential
rustup target add aarch64-unknown-linux-gnu
aarch64-linux-gnu-gcc --version
bash .github/actions/build-mach/build.bash
- name: "Build Mach (cross build - MacOS amd64 on arm64)"
if: |
(runner.os == 'macOS' && runner.arch == 'ARM64' &&
inputs.os == 'macos' && inputs.arch == 'amd64')
shell: bash
env:
os: "${{inputs.os}}"
arch: "${{inputs.arch}}"
MACH_VERSION: "${{inputs.mach_version}}"
profile: "${{inputs.profile}}"
run: |
source .github/actions/setup-env/setup-env.bash
rustup target add x86_64-apple-darwin
bash .github/actions/build-mach/build.bash
- name: "Build Mach (cross build - MacOS arm64 on amd64)"
if: |
(runner.os == 'macOS' && runner.arch == 'ARM64' &&
inputs.os == 'macos' && inputs.arch == 'amd64')
shell: bash
env:
os: "${{inputs.os}}"
arch: "${{inputs.arch}}"
MACH_VERSION: "${{inputs.mach_version}}"
profile: "${{inputs.profile}}"
run: |
source .github/actions/setup-env/setup-env.bash
rustup aarch64-apple-darwin
bash .github/actions/build-mach/build.bash
- name: "Build Mach (cross build - Windows arm64 on amd64)"
if: |
(runner.os == 'Windows' && runner.arch == 'X64' &&
inputs.os == 'windows' && inputs.arch == 'arm64')
shell: powershell
env:
os: "${{inputs.os}}"
arch: "${{inputs.arch}}"
MACH_VERSION: "${{inputs.mach_version}}"
profile: "${{inputs.profile}}"
run: |
. .github/actions/setup-env/setup-env.ps1
rustup target add aarch64-pc-windows-msvc
. .github/actions/build-mach/build.ps1
# Copy Artifacts
- name: "Copy Artifacts (Unix)"
if: runner.os != 'Windows'
shell: bash
env:
os: "${{inputs.os}}"
arch: "${{inputs.arch}}"
run: |
source .github/actions/setup-env/setup-env.bash
if [ "$MACH_VERSION" = "" ]; then
exit 0
fi
export ROOT_DIR="$(pwd)"
export JOB_NAME="${os}-${arch}"
mkdir $ROOT_DIR/artifacts
cd $ROOT_DIR/target/$JOB_NAME
mv release mach
tar -czvf mach-$JOB_NAME.tar.gz mach
mv mach-$JOB_NAME.tar.gz $ROOT_DIR/artifacts
cd $ROOT_DIR/npm/mach-os-arch
npm pack
mv *.tgz npm-mach-$JOB_NAME.tgz
mv *.tgz $ROOT_DIR/artifacts/npm-mach-$JOB_NAME.tgz
ls -l $ROOT_DIR/artifacts
- name: "Copy Files (Windows)"
if: runner.os == 'Windows'
shell: powershell
env:
os: "${{inputs.os}}"
arch: "${{inputs.arch}}"
run: |
. .github/actions/setup-env/setup-env.ps1
if ("$env:MACH_VERSION" -eq "") {
exit 0
}
$env:RootPath = (Get-Location).Path
$env:Job = "${env:os}-${env:arch}"
New-Item -ItemType "directory" -Force -Path "${env:RootPath}/artifacts"
echo "${env:RootPath}/target/${env:Job}"
cd "${env:RootPath}/target/${env:Job}"
mv release mach
tar -czvf "mach-${env:Job}.tar.gz" mach
Move-Item "mach-${env:Job}.tar.gz" -Destination "${env:RootPath}/artifacts"
cd "${env:RootPath}/npm/mach-os-arch"
npm pack
Move-Item *.tgz -Destination "npm-mach-${env:Job}.tgz"
Move-Item *.tgz -Destination "${env:RootPath}/artifacts/npm-mach-${env:Job}.tgz"
9 changes: 9 additions & 0 deletions .github/actions/build-mach/build.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set -e

if ! [ "$MACH_VERSION" = "" ]; then
echo "Building with version $MACH_VERSION"
just build-publish
else
echo "Building untagged local version"
just build
fi
5 changes: 5 additions & 0 deletions .github/actions/build-mach/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if ("${env:MACH_VERSION}" -ne "") {
just build-publish
} else {
just build
}
43 changes: 43 additions & 0 deletions .github/actions/build-npm/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: 'alshdavid/build-npm'
description: "Build Project"

inputs:
os:
description: 'target operating system'
default: ${{ runner.os == 'Linux' && 'linux' || runner.os == 'macOS' && 'macos' || runner.os == 'Windows' && 'windows' }}
arch:
description: 'target CPU architecture'
default: ${{ runner.arch == 'ARM64' && 'arm64' || runner.arch == 'X64' && 'amd64' }}
profile:
description: 'Build profile'
default: "release"
mach_version:
description: 'prepare packages for publishing'
default: ''

runs:
using: 'composite'
steps:
- name: "Build Project"
shell: bash
env:
os: "${{inputs.os}}"
arch: "${{inputs.arch}}"
MACH_VERSION: "${{inputs.mach_version}}"
profile: "${{inputs.profile}}"
run: |
source .github/actions/setup-env/setup-env.bash
bash .github/actions/build-npm/build.bash
- name: "Copy Artifacts"
shell: bash
env:
os: "${{inputs.os}}"
arch: "${{inputs.arch}}"
MACH_VERSION: "${{inputs.mach_version}}"
profile: "${{inputs.profile}}"
run: |
source .github/actions/setup-env/setup-env.bash
bash .github/actions/build-npm/copy.bash

12 changes: 12 additions & 0 deletions .github/actions/build-npm/build.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
set -e

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
ROOT_DIR=$(dirname $(dirname $(dirname $SCRIPT_DIR)))

if ! [ "$MACH_VERSION" = "" ]; then
echo "Building with version $MACH_VERSION"
just build-publish
else
echo "Building untagged local version"
just build
fi
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
set -ev
set -e

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
ROOT_DIR=$(dirname $(dirname $(dirname $SCRIPT_DIR)))

source $ROOT_DIR/.github/workflows/platform/unix/setup.bash
export MACH_SKIP_POST_INSTALL="true"

mkdir $ROOT_DIR/artifacts
sudo apt-get update
rustup target add x86_64-unknown-linux-gnu

profile=release os=linux arch=amd64 just build-publish

cd npm/mach
npm pack
mv *.tgz npm-mach.tgz
Expand Down
9 changes: 9 additions & 0 deletions .github/actions/setup-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: 'alshdavid/setup-env'
description: "Generate Vars"

runs:
using: 'composite'
steps:
- name: "Generate Vars"
shell: bash
run: "bash .github/actions/setup-env/generate.bash"
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
set -ev
set -e

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
ROOT_DIR=$(dirname $(dirname $(dirname $SCRIPT_DIR)))

source $ROOT_DIR/.github/workflows/platform/unix/install-nodejs.bash

pnpm install

export BRANCH_NAME=${GITHUB_REF##*/}
Expand All @@ -16,10 +14,15 @@ fi

NEXT_MACH_VERSION="$(node $ROOT_DIR/.github/scripts/ci/next-npm-version.mjs)"

echo "NEXT_MACH_VERSION=$NEXT_MACH_VERSION" >> $GITHUB_OUTPUT
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_OUTPUT
echo "NPM_TAG=$NPM_TAG" >> $GITHUB_OUTPUT
touch "$ROOT_DIR/.env"

echo "MACH_VERSION=$NEXT_MACH_VERSION" >> "$ROOT_DIR/.env"
echo "BRANCH_NAME=$BRANCH_NAME" >> "$ROOT_DIR/.env"
echo "NPM_TAG=$NPM_TAG" >> "$ROOT_DIR/.env"

echo NEXT_MACH_VERSION = $NEXT_MACH_VERSION
echo MACH_VERSION = $NEXT_MACH_VERSION
echo NPM_TAG = $NPM_TAG
echo BRANCH_NAME = $BRANCH_NAME
echo BRANCH_NAME = $BRANCH_NAME

cat "$ROOT_DIR/.env"

37 changes: 37 additions & 0 deletions .github/actions/setup-env/setup-env.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
set -e

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
ROOT_DIR=$(dirname $(dirname $(dirname $SCRIPT_DIR)))

cd $ROOT_DIR

# Just
export PATH="${HOME}/.local/just:$PATH"

# Rust
export RUSTUP_HOME="${HOME}/.local/rust/rustup"
export CARGO_HOME="${HOME}/.local/rust/cargo"
export PATH="${HOME}/.local/rust/cargo/bin:$PATH"

# Nodejs
export PATH="${HOME}/.local/nodejs/bin:$PATH"
export PATH="${HOME}/.local/nodejs/prefix/bin:$PATH"
export NPM_CONFIG_PREFIX="${HOME}/.local/nodejs/prefix"
pnpm config set store-dir $HOME/.local/nodejs/pnpm-store

ENV_PATH="${ROOT_DIR}/.env"

if [ -f "$ENV_PATH" ]; then
echo "Reading $ENV_PATH"
while read -r LINE; do
# Remove leading and trailing whitespaces, and carriage return
CLEANED_LINE=$(echo "$LINE" | awk '{$1=$1};1' | tr -d '\r')

if [[ $CLEANED_LINE != '#'* ]] && [[ $CLEANED_LINE == *'='* ]]; then
echo "Setting: $CLEANED_LINE"
export "$CLEANED_LINE"
fi
done < "$ENV_PATH"
fi

28 changes: 28 additions & 0 deletions .github/actions/setup-env/setup-env.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Project Root
$env:RootPath = "$PSScriptRoot\..\..\.."

# Just
$env:Path = "${HOME}\.local\just;${env:Path}"

# Rust
$env:RUSTUP_HOME = "${HOME}\.local\rust\rustup"
$env:CARGO_HOME = "${HOME}\.local\rust\cargo"
$env:Path = "${env:USERPROFILE}\.cargo\bin;${env:Path}"

# Nodejs
$env:Path = "${HOME}\.local\nodejs;${env:Path}"
$env:Path = "${HOME}\.local\nodejs\prefix\bin;${env:Path}"
$env:NPM_CONFIG_PREFIX = "${HOME}\.local\nodejs\prefix"
pnpm config set store-dir "${HOME}\.local\nodejs\pnpm-store"

if (Test-Path "${env:RootPath}\.env") {
echo "Loading .env"
Get-Content "${env:RootPath}\.env" | foreach {
$name, $value = $_.split('=')
if ([string]::IsNullOrWhiteSpace($name) -and $name.Contains('#')) {
continue
}
echo "Setting $name = $value"
Set-Item "env:$name" "$value"
}
}
Loading

0 comments on commit c4199c9

Please sign in to comment.