From 3b58390ac652695dc8f0baab17b5415c3c403330 Mon Sep 17 00:00:00 2001 From: Michael Milton Date: Mon, 11 Aug 2025 13:52:15 +1000 Subject: [PATCH 1/2] Add git insteadof example --- README.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/README.md b/README.md index f969916..af65dde 100644 --- a/README.md +++ b/README.md @@ -296,6 +296,42 @@ jobs: GITHUB_TOKEN: ${{ steps.create_token.outputs.token }} ``` +### Tell git to use the app token to authenticate + +Certain tools use `git` to access repositories, but have no facility to accept a GitHub API token. +In this scenario it's easier to configure `git` itself to use the token. +For example, this is important if you have a Python project with a `git+https` or a `git+ssh` dependency on a private repository. + +```yaml +on: [pull_request] + +jobs: + python-build: + runs-on: ubuntu-latest + steps: + - uses: actions/create-github-app-token@v2 + id: app-token + with: + # required + app-id: ${{ vars.APP_ID }} + private-key: ${{ secrets.PRIVATE_KEY }} + - name: Configure git to use the app token + run: git config --global url."https://USERNAME:${GITHUB_TOKEN}@github.com/".insteadOf "https://github.com/" + env: + GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} + - uses: actions/setup-python@v5 + - name: Install dependencies + run: pip install . +``` + +Refer to [`git`'s configuration docs](https://git-scm.com/docs/git-config#Documentation/git-config.txt-urlbaseinsteadOf) for more information on this syntax. + +The above example will use the same token for all `git` operations on GitHub via `https`, but you can configure it on a per repository or per-organisation basis by changing the prefix: + +```bash +git config --global url."https://USERNAME:${GITHUB_TOKEN}@github.com/MyOrg/MyRepo".insteadOf "https://github.com/MyOrg/MyRepo" +``` + ## Inputs ### `app-id` From 61b09e920fb390e51f6c5280b22a8eca9719f002 Mon Sep 17 00:00:00 2001 From: Michael Milton Date: Mon, 11 Aug 2025 13:56:43 +1000 Subject: [PATCH 2/2] Explain the USERNAME --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index af65dde..0de73ae 100644 --- a/README.md +++ b/README.md @@ -326,6 +326,8 @@ jobs: Refer to [`git`'s configuration docs](https://git-scm.com/docs/git-config#Documentation/git-config.txt-urlbaseinsteadOf) for more information on this syntax. +In this example, `USERNAME` is ignored by GitHub since the token contains the full authentication information. For this reason, you can leave it in the configuration as is. + The above example will use the same token for all `git` operations on GitHub via `https`, but you can configure it on a per repository or per-organisation basis by changing the prefix: ```bash