diff --git a/.github/workflows/phone-build.yml b/.github/workflows/phone-build.yml new file mode 100644 index 0000000..d0bc1f8 --- /dev/null +++ b/.github/workflows/phone-build.yml @@ -0,0 +1,100 @@ +# Builds ratclone for the owner's phone (Ubuntu in proot, aarch64), only when it +# is started by hand. Nothing is published: the binary is kept as a run +# artifact for 7 days. +# +# Start it (from Termux, or anywhere with gh): +# gh workflow run phone-build.yml -R SyscallBrain/ratclone --ref +# gh workflow run phone-build.yml -R SyscallBrain/ratclone --ref -f checks=false +# Follow it and fetch the binary from that same run (the newest run of this +# workflow; gh run download without a run id would ask which run): +# run=$(gh run list -R SyscallBrain/ratclone -w phone-build.yml -L 1 --json databaseId -q '.[0].databaseId') +# gh run watch "$run" -R SyscallBrain/ratclone --exit-status +# gh run download "$run" -R SyscallBrain/ratclone +# Artifacts are zips, which drop the executable bit, so then: +# chmod +x ratclone-*/ratclone +name: Phone build (manual) + +# The only trigger is "Run workflow" / "gh workflow run": no push, +# pull_request or schedule, so it never starts on its own. +on: + workflow_dispatch: + inputs: + checks: + description: Run fmt, clippy and the tests before building + type: boolean + default: true + +permissions: {} + +env: + CARGO_TERM_COLOR: always + RUST_VERSION: 1.99.1 + # Static (musl) binary: runs on any aarch64 Linux, the proot Ubuntu + # included, whatever its glibc. + TARGET: aarch64-unknown-linux-musl + +jobs: + build: + # Native ARM runner (free on public repos): builds and tests on the + # phone's architecture, no cross-compiling. + runs-on: ubuntu-24.04-arm + timeout-minutes: 45 + permissions: + contents: read + steps: + - name: Check out source + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Install the Rust toolchain + run: | + rustup toolchain install "$RUST_VERSION" --profile minimal \ + --component rustfmt --component clippy --target "$TARGET" + rustup default "$RUST_VERSION" + sudo apt-get update -qq && sudo apt-get install -y -qq musl-tools + + # Keeps ~/.cargo and target/ between runs, so later builds are faster. + - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 + + - name: Install the current rclone (the tests call it) + if: inputs.checks + run: bash scripts/install-test-rclone.sh latest "$RUNNER_TEMP/rclone" + + - name: Format, lints and tests + if: inputs.checks + run: | + export PATH="$RUNNER_TEMP/rclone:$PATH" + RATCLONE_TEST_RCLONE_VERSION=$(cat "$RUNNER_TEMP/rclone/version") + export RATCLONE_TEST_RCLONE_VERSION + cargo fmt --check + cargo clippy --locked --all-targets -- -D warnings + cargo test --locked + + - name: Build the static binary + run: cargo build --release --locked --target "$TARGET" + + - name: Smoke-test and label the binary + run: | + bin="target/$TARGET/release/ratclone" + "$bin" --version + mkdir out + cp "$bin" out/ + short=$(git rev-parse --short HEAD) + echo "SHORT_SHA=$short" >> "$GITHUB_ENV" + { + echo "repo: $GITHUB_REPOSITORY" + echo "branch: $GITHUB_REF_NAME" + echo "commit: $(git rev-parse HEAD)" + echo "run: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" + echo "target: $TARGET" + } > out/BUILD-INFO.txt + (cd out && sha256sum ratclone > SHA256SUMS && cat SHA256SUMS BUILD-INFO.txt) + + - name: Upload the binary + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: ratclone-aarch64-${{ env.SHORT_SHA }} + path: out/ + if-no-files-found: error + retention-days: 7