diff --git a/.github/actions/apt/action.yml b/.github/actions/apt/action.yml new file mode 100644 index 0000000..d6a60f2 --- /dev/null +++ b/.github/actions/apt/action.yml @@ -0,0 +1,80 @@ +# apt-get install with its downloads cached (actions/cache): the .debs and +# the package lists they were resolved from, kept together, keyed on the +# runner image (ImageOS, ImageVersion: a new image every week or so) and +# the package list. On a hit the install is offline (--no-download): no +# mirror, nothing to stall on. On a miss, or if the offline install +# can't be done, the usual update and install, with retries and timeouts +# so a stalled mirror fails over instead of hanging; then the cache is +# saved for the next run. +name: apt packages +description: apt-get install, cached +inputs: + packages: + description: the packages (spaces or newlines between) + required: true + ppa: + description: a PPA to add first (ppa:owner/name), or empty + default: '' + recommends: + description: "'true' installs recommended packages too" + default: 'false' +runs: + using: composite + steps: + - id: key + shell: bash + env: + PKGS: ${{ inputs.packages }} + PPA: ${{ inputs.ppa }} + REC: ${{ inputs.recommends }} + run: | + pkgs=$(printf '%s\n' $PKGS | sort -u | tr '\n' ' ') + echo "pkgs=$pkgs" >> "$GITHUB_OUTPUT" + # (ImageOS, ImageVersion: the runner's environment, not the env context) + echo "key=apt-${ImageOS:-none}-$RUNNER_ARCH-${ImageVersion:-none}-$(printf '%s|%s|%s' "$pkgs" "$PPA" "$REC" | sha256sum | cut -c1-16)" >> "$GITHUB_OUTPUT" + + - id: restore + uses: actions/cache/restore@v4 + with: + path: /tmp/apt-cache + key: ${{ steps.key.outputs.key }} + + - id: install + shell: bash + env: + PKGS: ${{ steps.key.outputs.pkgs }} + PPA: ${{ inputs.ppa }} + REC: ${{ inputs.recommends }} + HIT: ${{ steps.restore.outputs.cache-hit }} + run: | + set -euo pipefail + C=/tmp/apt-cache + sudo mkdir -p "$C/archives/partial" "$C/lists/partial" + rec=--no-install-recommends + [ "$REC" = true ] && rec= + apt=(sudo DEBIAN_FRONTEND=noninteractive apt-get -y -q $rec + -o Dir::Cache::Archives="$C/archives" -o Dir::State::Lists="$C/lists" + -o APT::Keep-Downloaded-Packages=true + -o Acquire::Retries=5 + -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30) + if [ -n "$PPA" ]; then + for i in 1 2 3; do sudo add-apt-repository -y -n "$PPA" && break; sleep $((i * 10)); done + fi + fresh=false + if [ "$HIT" = true ] && "${apt[@]}" install --no-download $PKGS; then + echo "installed from the cache" + else + for i in 1 2 3; do "${apt[@]}" update && break; sleep $((i * 10)); done + for i in 1 2 3; do "${apt[@]}" install $PKGS && break; [ $i = 3 ] && exit 1; sleep $((i * 10)); done + fresh=true + fi + sudo rm -rf "$C/archives/partial" "$C/lists/partial" "$C/archives/lock" "$C/lists/lock" + sudo chown -R "$(id -u):$(id -g)" "$C" + echo "fresh=$fresh" >> "$GITHUB_OUTPUT" + + - if: steps.install.outputs.fresh == 'true' + uses: actions/cache/save@v4 + continue-on-error: true + with: + path: /tmp/apt-cache + key: ${{ steps.restore.outputs.cache-primary-key }} diff --git a/.github/actions/brew/action.yml b/.github/actions/brew/action.yml new file mode 100644 index 0000000..54d2287 --- /dev/null +++ b/.github/actions/brew/action.yml @@ -0,0 +1,50 @@ +# brew install with Homebrew's downloads cached (actions/cache): the +# bottles and its formula index (the API files), keyed on the runner image +# (ImageOS, ImageVersion) and the package list. No brew update (the slow, +# networked part; the image's Homebrew is recent enough), and with the +# index and bottles cached a hit downloads nothing. Retried, in case a +# download stalls. +name: brew packages +description: brew install, cached +inputs: + packages: + description: the formulae (spaces or newlines between) + required: true +runs: + using: composite + steps: + - id: key + shell: bash + env: + PKGS: ${{ inputs.packages }} + run: | + pkgs=$(printf '%s\n' $PKGS | sort -u | tr '\n' ' ') + echo "pkgs=$pkgs" >> "$GITHUB_OUTPUT" + # (ImageOS, ImageVersion: the runner's environment, not the env context) + echo "key=brew-${ImageOS:-none}-$RUNNER_ARCH-${ImageVersion:-none}-$(printf '%s' "$pkgs" | shasum -a 256 | cut -c1-16)" >> "$GITHUB_OUTPUT" + + - id: restore + uses: actions/cache/restore@v4 + with: + path: /tmp/brew-cache + key: ${{ steps.key.outputs.key }} + + - shell: bash + env: + PKGS: ${{ steps.key.outputs.pkgs }} + HOMEBREW_CACHE: /tmp/brew-cache + HOMEBREW_NO_AUTO_UPDATE: '1' + HOMEBREW_NO_INSTALL_CLEANUP: '1' + HOMEBREW_NO_ENV_HINTS: '1' + HOMEBREW_CURL_RETRIES: '5' + run: | + set -euo pipefail + for i in 1 2 3; do brew install $PKGS && exit 0; sleep $((i * 10)); done + exit 1 + + - if: steps.restore.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + continue-on-error: true + with: + path: /tmp/brew-cache + key: ${{ steps.restore.outputs.cache-primary-key }} diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index cfe4551..3a4ce9e 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -8,6 +8,9 @@ # release: the release APK and bundle (R8): signed with the release # environment's key for main and v* tags, the debug key for a pull request. # +# Packages: apt's downloads are cached (.github/actions/apt), keyed on +# the runner image and the package list. +# # D-Modem-RE is a private submodule: the DMODEM_TOKEN secret is a token # that can read it (a fine-grained personal access token with Contents: # read on D-Modem/D-Modem). @@ -76,7 +79,11 @@ jobs: "ndk;$NDK_VERSION" "cmake;$CMAKE_VERSION" "platforms;android-37.0" - name: OpenSSH, PuTTY, mksh (the interop tests), gawk (proot's build) - run: sudo apt-get install -y -q openssh-client openssh-server putty-tools gawk mksh && sudo mkdir -p /run/sshd + uses: ./.github/actions/apt + with: + packages: openssh-client openssh-server putty-tools gawk mksh + recommends: 'true' + - run: sudo mkdir -p /run/sshd # the keystore from its secret, for the build (app/build.gradle.kts); none on a fork's pull request - name: Signing keystore env: @@ -146,7 +153,9 @@ jobs: "ndk;$NDK_VERSION" "cmake;$CMAKE_VERSION" "platforms;android-37.0" - name: gawk (proot's build) - run: sudo apt-get install -y -q gawk + uses: ./.github/actions/apt + with: + packages: gawk # the keystore from its secret, for the build (app/build.gradle.kts); none on a fork's pull request - name: Signing keystore @@ -192,9 +201,9 @@ jobs: token: ${{ secrets.DMODEM_TOKEN || github.token }} - name: Packages - run: | - sudo apt-get update - sudo apt-get install -y --no-install-recommends cmake ninja-build g++ libssl-dev libgtest-dev + uses: ./.github/actions/apt + with: + packages: cmake ninja-build g++ libssl-dev libgtest-dev - name: Build run: | @@ -240,7 +249,9 @@ jobs: - uses: gradle/actions/setup-gradle@v4 - name: gawk (proot's build) - run: sudo apt-get install -y -q gawk + uses: ./.github/actions/apt + with: + packages: gawk - name: KVM run: | diff --git a/.github/workflows/apple.yml b/.github/workflows/apple.yml index fd1571c..ffe3262 100644 --- a/.github/workflows/apple.yml +++ b/.github/workflows/apple.yml @@ -31,8 +31,11 @@ jobs: submodules: recursive token: ${{ secrets.DMODEM_TOKEN || github.token }} - - name: Ninja - run: brew install ninja + # (Homebrew's downloads cached: .github/actions/brew) + - name: Ninja, XcodeGen + uses: ./.github/actions/brew + with: + packages: ninja xcodegen - uses: actions/setup-java@v4 with: @@ -62,7 +65,6 @@ jobs: # arm64 only: the shared Kotlin's XCFramework has no x86_64 simulator slice - name: The iOS app (simulator) run: | - brew install xcodegen cd ios/DModem && xcodegen generate xcodebuild -project DModem.xcodeproj -scheme DModem \ -destination 'generic/platform=iOS Simulator' \