diff --git a/.github/workflows/shadowsocksx-ng2-ci.yml b/.github/workflows/shadowsocksx-ng2-ci.yml index 41ea7c60..797ba587 100644 --- a/.github/workflows/shadowsocksx-ng2-ci.yml +++ b/.github/workflows/shadowsocksx-ng2-ci.yml @@ -26,9 +26,48 @@ jobs: with: persist-credentials: false + - name: Prepare Homebrew download cache + id: homebrew-cache-key + run: | + brew info --json=v2 age go-task xcodegen swiftlint > "$RUNNER_TEMP/homebrew-formulae.json" + formula_hash=$(python3 - "$RUNNER_TEMP/homebrew-formulae.json" <<'PY' + import hashlib + import json + import sys + + with open(sys.argv[1]) as source: + formulae = json.load(source)["formulae"] + versions = sorted( + (f["full_name"], f["versions"]["stable"], f["revision"], f["bottle"]) + for f in formulae + ) + print(hashlib.sha256(json.dumps(versions, sort_keys=True).encode()).hexdigest()) + PY + ) + echo "path=$(brew --cache)/downloads" >> "$GITHUB_OUTPUT" + echo "key=ng2-homebrew-downloads-v1-macos-$(sw_vers -productVersion)-$(uname -m)-$formula_hash" >> "$GITHUB_OUTPUT" + + - name: Restore Homebrew download cache + id: homebrew-cache + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ${{ steps.homebrew-cache-key.outputs.path }} + key: ${{ steps.homebrew-cache-key.outputs.key }} + - name: Install build tools and test dependencies + id: install-build-tools + env: + HOMEBREW_NO_AUTO_UPDATE: '1' + HOMEBREW_NO_INSTALL_CLEANUP: '1' run: brew install age go-task xcodegen swiftlint + - name: Save Homebrew download cache + if: steps.install-build-tools.outcome == 'success' && steps.homebrew-cache.outputs.cache-hit != 'true' + uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ${{ steps.homebrew-cache-key.outputs.path }} + key: ${{ steps.homebrew-cache-key.outputs.key }} + - name: Restore external binary archive cache id: external-binary-cache uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0