From 1233b433c4c8078ff89650a9703f6363bccec40c Mon Sep 17 00:00:00 2001 From: OliverNChalk <11343499+OliverNChalk@users.noreply.github.com> Date: Mon, 25 Nov 2024 12:28:12 +0100 Subject: [PATCH] build: enable cloning private repos --- .github/workflows/actions/checkout/action.yml | 19 +++++++++++++ .../actions/rust-toolchain/action.yml | 10 +++++++ .github/workflows/ci.yml | 27 +++++++++++++------ 3 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/actions/checkout/action.yml diff --git a/.github/workflows/actions/checkout/action.yml b/.github/workflows/actions/checkout/action.yml new file mode 100644 index 0000000..8955bd4 --- /dev/null +++ b/.github/workflows/actions/checkout/action.yml @@ -0,0 +1,19 @@ +name: checkout +description: "Checks out repo with optional token" +inputs: + token: + description: "Access token for private repos" + required: false + +runs: + using: "composite" + steps: + - uses: actions/checkout@v3 + if: "${{ inputs.token != null }}" + with: + token: ${{ secrets.CI_READ }} + submodules: recursive + - uses: actions/checkout@v3 + if: "${{ inputs.token == null }}" + with: + submodules: recursive diff --git a/.github/workflows/actions/rust-toolchain/action.yml b/.github/workflows/actions/rust-toolchain/action.yml index 4547904..36b8721 100644 --- a/.github/workflows/actions/rust-toolchain/action.yml +++ b/.github/workflows/actions/rust-toolchain/action.yml @@ -1,8 +1,12 @@ name: rust-toolchain +description: "Sets up a standard rust toolchain" inputs: toolchain: description: "Which rust toolchain to use" required: false + token: + description: "Access token for private repos" + required: false runs: using: "composite" @@ -23,3 +27,9 @@ runs: - uses: Swatinem/rust-cache@v2.0.0 with: shared-key: ${{ steps.get-toolchain.outputs.toolchain }} + - run: git config --global url."https://x-access-token:${{ inputs.token }}@github.com/".insteadOf "https://github.com/" + if: ${{ inputs.token != null }} + shell: bash + - run: git config --global url."https://${{ inputs.token }}@github.com/".insteadOf "git@github.com:" + if: ${{ inputs.token != null }} + shell: bash diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f139730..d2a5868 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,10 +22,12 @@ jobs: if: needs.skip-duplicates.outputs.should_skip != 'true' runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: ./.github/workflows/actions/checkout with: - submodules: recursive + token: ${{ secrets.CI_READ }} - uses: ./.github/workflows/actions/rust-toolchain + with: + personal-access-token: ${{ secrets.CI_READ }} - run: cargo check --all-features test: @@ -33,10 +35,12 @@ jobs: if: needs.skip-duplicates.outputs.should_skip != 'true' runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: ./.github/workflows/actions/checkout with: - submodules: recursive + token: ${{ secrets.CI_READ }} - uses: ./.github/workflows/actions/rust-toolchain + with: + personal-access-token: ${{ secrets.CI_READ }} - run: cargo test --all-features fmt: @@ -44,11 +48,12 @@ jobs: if: needs.skip-duplicates.outputs.should_skip != 'true' runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: ./.github/workflows/actions/checkout with: - submodules: recursive + token: ${{ secrets.CI_READ }} - uses: ./.github/workflows/actions/rust-toolchain with: + personal-access-token: ${{ secrets.CI_READ }} toolchain: nightly - run: rustup component add rustfmt - run: cargo fmt --all --check @@ -59,9 +64,12 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - uses: ./.github/workflows/actions/checkout with: - submodules: recursive + token: ${{ secrets.CI_READ }} - uses: ./.github/workflows/actions/rust-toolchain + with: + personal-access-token: ${{ secrets.CI_READ }} - run: rustup component add clippy - run: cargo clippy --all-features -- --deny warnings @@ -71,7 +79,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - uses: ./.github/workflows/actions/checkout with: - submodules: recursive + token: ${{ secrets.CI_READ }} - uses: ./.github/workflows/actions/rust-toolchain + with: + personal-access-token: ${{ secrets.CI_READ }} - run: cargo doc --all-features --no-deps