From ef844bb8a2685f54bd0867136645764ffabf13f6 Mon Sep 17 00:00:00 2001 From: Joffrey Date: Thu, 26 Oct 2023 17:09:36 +0200 Subject: [PATCH] feat(action): git auth global action --- actions/git/git-auth-global/README.md | 30 ++++++++++++++++++++++++++ actions/git/git-auth-global/action.yml | 29 +++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 actions/git/git-auth-global/README.md create mode 100644 actions/git/git-auth-global/action.yml diff --git a/actions/git/git-auth-global/README.md b/actions/git/git-auth-global/README.md new file mode 100644 index 0000000..ca30e66 --- /dev/null +++ b/actions/git/git-auth-global/README.md @@ -0,0 +1,30 @@ +# Git: git-auth-global + +## Behavior + +Modify git global config: + - authenticate requests to github.com with Github token + +Global config is cleared in post run + +_useful to use private pre-commit sources in CI_ + +## Usage + +```yaml +jobs: + advanceTag: + runs-on: ubuntu-latest + steps: + - uses: "actions/checkout@v3" + + - name: "Git Auth Global" + uses: "meero-com/github-actions-shared-workflows/actions/git/git-auth-global@main" + with: + github-token: ${{ secrets.API_TOKEN_GITHUB }} +``` + +Beware of using a `@ref` (`@main` in the example above) which suits your stability requirements in your workflow: + +* Use `@main` if you always want to use the latest version of the workflow. +* Use `@` if you wan to use a specific frozen version of the workflow. diff --git a/actions/git/git-auth-global/action.yml b/actions/git/git-auth-global/action.yml new file mode 100644 index 0000000..808c380 --- /dev/null +++ b/actions/git/git-auth-global/action.yml @@ -0,0 +1,29 @@ +name: "Github auth GIT global" +description: "github token auth in global git config" + +inputs: + github-token: + description: The GitHub token used to create an authenticated client + required: true + +runs: + using: "composite" + steps: + - name: git credentials path + id: git-credentials + run: | + store_path=$(pwd)/.git-credentials + echo "path=$store_path" >> $GITHUB_OUTPUT + shell: bash + + - name: Global Git auth + uses: gacts/run-and-post-run@v1 + env: + credential_path: ${{ steps.git-credentials.outputs.path }} + with: + run: | + git config --global credential.helper "store --file=$credential_path" + echo "https://${{ inputs.github-token }}:@github.com" > $credential_path + post: | + git config --global --unset credential.helper + rm $credential_path