Skip to content

Commit

Permalink
feat(action): git auth global action
Browse files Browse the repository at this point in the history
  • Loading branch information
JoffreyPlouvier committed Oct 26, 2023
1 parent 64c4149 commit ef844bb
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
30 changes: 30 additions & 0 deletions actions/git/git-auth-global/README.md
Original file line number Diff line number Diff line change
@@ -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 `@<tag>` if you wan to use a specific frozen version of the workflow.
29 changes: 29 additions & 0 deletions actions/git/git-auth-global/action.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ef844bb

Please sign in to comment.