diff --git a/.github/workflows/minimal-crates.yaml b/.github/workflows/minimal-crates.yaml index b905bd9..96f75ce 100644 --- a/.github/workflows/minimal-crates.yaml +++ b/.github/workflows/minimal-crates.yaml @@ -19,6 +19,11 @@ on: crypto backend of rustls. type: "boolean" default: false + secrets: + GIT_TOKEN: + description: | + Token for private git dependencies on github.com. + required: false workflow_dispatch: concurrency: @@ -26,6 +31,15 @@ concurrency: cancel-in-progress: true env: + # Every job fetches github.com git dependencies with GIT_TOKEN, if given. + # The empty credential.helper stops git from storing the token after a + # fetch: macOS osxkeychain blocks during actions/checkout. + CARGO_NET_GIT_FETCH_WITH_CLI: "true" + GIT_CONFIG_COUNT: ${{ secrets.GIT_TOKEN != '' && '2' || '0' }} + GIT_CONFIG_KEY_0: url.https://x-access-token:${{ secrets.GIT_TOKEN }}@github.com/.insteadOf + GIT_CONFIG_VALUE_0: https://github.com/ + GIT_CONFIG_KEY_1: credential.helper + GIT_CONFIG_VALUE_1: "" RUST_BACKTRACE: 1 RUSTC_WRAPPER: "sccache" SCCACHE_GHA_ENABLED: "true" diff --git a/README.md b/README.md index 269fb6a..60d2d68 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,21 @@ jobs: uses: "n0-computer/workflows/.github/workflows/minimal-crates.yaml@main" ``` +### Private git dependencies + +Every shared workflow takes an optional `GIT_TOKEN` secret. All its +jobs fetch git dependencies from github.com with it, so a caller can +depend on a private repository: + +```yaml + secrets: + GIT_TOKEN: ${{ secrets.MY_PRIVATE_REPO_TOKEN }} +``` + +A fine-grained token with read-only Contents access to the private +repository is enough. A new shared workflow must take the secret too: +copy its `secrets` and `env` entries from `minimal-crates.yaml`. + ### Editing a shared workflow - Start editing a shared workflow in a branch, e.g. `username/branch_name`.