diff --git a/.github/workflows/build_alfa_cli.yml b/.github/workflows/build_alfa_cli.yml index 650d8dd..9ce7594 100644 --- a/.github/workflows/build_alfa_cli.yml +++ b/.github/workflows/build_alfa_cli.yml @@ -11,6 +11,7 @@ on: jobs: tag: runs-on: ubuntu-latest + timeout-minutes: 15 outputs: tag: ${{ steps.create-tag.outputs.tag }} @@ -29,6 +30,7 @@ jobs: release: needs: tag runs-on: ${{ matrix.os }} + timeout-minutes: 15 strategy: matrix: @@ -59,3 +61,60 @@ jobs: file: alfa_* tag: ${{ needs.tag.outputs.tag }} file_glob: true + + release-on-arm: + needs: tag + runs-on: ubuntu-latest + timeout-minutes: 15 + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: '0' + - name: Setup arm emulation with qemu + run: | + sudo apt-get update -q -y + sudo apt-get -qq install -y qemu qemu-user-static + docker run --rm --privileged multiarch/qemu-user-static --reset -p yes --credential yes + + - name: Create docker command script + run: | + SCRIPT=$(cat << EOF + #!/bin/sh + set -eu + + # installs dependencies + dart pub get + + # compile executable (make isn't part of this docker image) + dart compile exe bin/alfa.dart -o alfa + + # renames executable + ./rename.sh + EOF + ) + + echo "$SCRIPT" > run.sh + + chmod +x run.sh + + - name: Cat docker command script + run: cat run.sh + + - name: Build arm executable with docker + run: | + docker run \ + --rm \ + -t \ + --workdir "${GITHUB_WORKSPACE}" \ + -v "${GITHUB_WORKSPACE}:${GITHUB_WORKSPACE}" \ + --platform linux/arm64 \ + dart:stable \ + "${GITHUB_WORKSPACE}/run.sh" + + - name: Upload binaries to release + uses: svenstaro/upload-release-action@v2 + with: + file: alfa_* + tag: ${{ needs.tag.outputs.tag }} + file_glob: true diff --git a/.gitignore b/.gitignore index 5ba7b1d..716c357 100644 --- a/.gitignore +++ b/.gitignore @@ -13,5 +13,5 @@ pubspec.lock # alfa executables /alfa -/alfa_linux -/alfa_macos +/alfa_linux* +/alfa_macos* diff --git a/bin/alfa.dart b/bin/alfa.dart index 5e42400..d6b2b2f 100644 --- a/bin/alfa.dart +++ b/bin/alfa.dart @@ -58,6 +58,7 @@ void main(List args) async { // gets environment variables String user = Platform.environment['SUDO_USER']; String alfaUser = Platform.environment['ALFA_USER']; + String alfaArch = Platform.environment['ALFA_ARCH']; if (user == 'root' && alfaUser != '') { user = alfaUser; } @@ -65,7 +66,7 @@ void main(List args) async { // gets operating system // valid options (linux, macos) var osName = Platform.operatingSystem; - print("Running alfa on ${osName}"); + print("Running alfa on ${osName} ${alfaArch}"); // loads config file which maps the install keys to the tags var configFile = await TomlDocument.load(argResults['config']); @@ -189,7 +190,7 @@ void main(List args) async { arguments = ['-u', user]; } - arguments.addAll(['--preserve-env=ALFA_USER', '--', '/bin/bash']); + arguments.addAll(['--preserve-env=ALFA_USER,ALFA_ARCH', '--', '/bin/bash']); } arguments.addAll(['-euc', command]); diff --git a/codemagic.yaml b/codemagic.yaml new file mode 100644 index 0000000..ed19081 --- /dev/null +++ b/codemagic.yaml @@ -0,0 +1,36 @@ +workflows: + release: + name: Release + instance_type: mac_mini_m1 + max_build_duration: 15 + environment: + flutter: stable + + groups: + - github + + triggering: + events: + - tag + tag_patterns: + - pattern: 'v*' + + scripts: + - name: Add Dart SDK to PATH + script: | + echo PATH="$PATH":"$FLUTTER_ROOT/.pub-cache/bin" >> $CM_ENV + echo PATH="$PATH":"$FLUTTER_ROOT/bin" >> $CM_ENV + - name: Install dependencies + script: dart pub get + - name: Compile executable + script: make + - name: Renames executable + script: ./rename.sh + + artifacts: + - alfa_macos_arm64 + + publishing: + scripts: + - name: Publish to GitHub + script: gh release upload "${CM_TAG}" alfa_macos_arm64 diff --git a/functions.sh b/functions.sh index 03dcd62..712836a 100755 --- a/functions.sh +++ b/functions.sh @@ -4,6 +4,7 @@ # rather "install_brew". # To access the list of "options" in the config.toml file you pass to the installer, use the "$@" variable. # To access the user that called the installer, do not user the environment variable "$SUDO_USER", but rather use "$ALFA_USER". +# To access the uname -m output (system architecture), you can use the environment variable "$ALFA_ARCH" create_git_config() { # sets up git config name and email @@ -217,14 +218,14 @@ install_anaconda3_common() { install_anaconda3_macos() { # installs anaconda3 echo "Installing Anaconda3..." - curl "${1:-https://repo.anaconda.com/archive/Anaconda3-2022.05-MacOSX-x86_64.sh}" -o ~/anaconda3.sh + curl "${1:-https://repo.anaconda.com/archive/Anaconda3-2022.05-MacOSX-${ALFA_ARCH}.sh}" -o ~/anaconda3.sh install_anaconda3_common } install_anaconda3_linux() { # installs anaconda3 echo "Installing Anaconda3..." - curl "${1:-https://repo.anaconda.com/archive/Anaconda3-2022.05-Linux-x86_64.sh}" -o ~/anaconda3.sh + curl "${1:-https://repo.anaconda.com/archive/Anaconda3-2022.05-Linux-${ALFA_ARCH}.sh}" -o ~/anaconda3.sh install_anaconda3_common } diff --git a/install.sh b/install.sh index 744800c..fa8ac6e 100755 --- a/install.sh +++ b/install.sh @@ -10,17 +10,21 @@ fi alfaCommand="" -# sets the alfa command variable based on the operating system -unameResults="$(uname -s)" -if [[ "Linux" == *"$unameResults"* ]]; then - alfaCommand="alfa_linux" -elif [[ "Darwin" == *"$unameResults"* ]]; then - alfaCommand="alfa_macos" +# renames the alfa executable based on the operating system and architecture +unameSystem="$(uname -s)" +unameMachine="$(uname -m)" + +if [[ "Linux" == "$unameSystem" && ( "x86_64" == "$unameMachine" || "aarch64" == "$unameMachine" ) ]]; then + alfaCommand="alfa_linux_$unameMachine" +elif [[ "Darwin" == "$unameSystem" && ( "x86_64" == "$unameMachine" || "arm64" == "$unameMachine" ) ]]; then + alfaCommand="alfa_macos_$unameMachine" else - echo "alfa cannot run on ${unameResults}. It can only run on Linux and macOS." + echo "alfa cannot run on ${unameSystem} ${unameMachine}. It can only run on Linux and macOS." exit 1 fi +export ALFA_ARCH="$unameMachine" + # runs the alfa command depending upon if sudo exists if ! command -v "sudo" > /dev/null 2>&1; then # sudo command doesn't exist @@ -37,7 +41,7 @@ else while :; do sudo -v; sleep 59; done & loopPid="$!" - export ALFA_USER="${SUDO_USER:-${USER:-}}"; sudo --preserve-env=ALFA_USER ./$alfaCommand "$@" + export ALFA_USER="${SUDO_USER:-${USER:-}}"; sudo --preserve-env=ALFA_USER,ALFA_ARCH ./$alfaCommand "$@" trap 'trap - SIGTERM && kill $(pgrep -P $loopPid) $loopPid' SIGINT SIGTERM EXIT diff --git a/rename.sh b/rename.sh index cae09cc..384ce14 100755 --- a/rename.sh +++ b/rename.sh @@ -8,14 +8,16 @@ if [[ ! -f "alfa" ]]; then exit 1 fi -# renames the alfa executable based on the operating system -unameResults="$(uname -s)" -if [[ "Linux" == *"$unameResults"* ]]; then - alfaCommand="alfa_linux" -elif [[ "Darwin" == *"$unameResults"* ]]; then - alfaCommand="alfa_macos" +# renames the alfa executable based on the operating system and architecture +unameSystem="$(uname -s)" +unameMachine="$(uname -m)" + +if [[ "Linux" == "$unameSystem" && ( "x86_64" == "$unameMachine" || "aarch64" == "$unameMachine" ) ]]; then + alfaCommand="alfa_linux_$unameMachine" +elif [[ "Darwin" == "$unameSystem" && ( "x86_64" == "$unameMachine" || "arm64" == "$unameMachine" ) ]]; then + alfaCommand="alfa_macos_$unameMachine" else - echo "alfa cannot run on ${unameResults}. It can only run on Linux and macOS." + echo "alfa cannot run on ${unameSystem} ${unameMachine}. It can only run on Linux and macOS." exit 1 fi