config-git-with-token-action
v2.0.15
Published
This GitHub Action configures git and gh to act as the user or bot behind a GitHub token.
Readme
config-git-with-token-action
As a GitHub Actions author, have you received GitHub token and tried to git commit and git push on behave of the identity behind that token? This GitHub Action helps you set up git and gh to operate as if you are the user or bot behind the GitHub token.
Usage as a Reusable Action
When writing a composite action, use this action as a step to set up git and gh with the token:
runs:
using: 'composite'
steps:
- uses: actions/checkout@v6
with:
persist-credentials: false
- uses: CatChen/config-git-with-token-action@v2
with:
github-token: ${{ inputs.github-token }}
- shell: bash
run: |
echo "Set up git user name: $(git config --get user.name)"
echo "Set up git user email: $(git config --get user.email)"
echo "Set up git remote origin with login and token: $(git remote get-url origin)"
- shell: bash
run: |
touch test_file
git commit test_file -m 'Created test file'
git pushUsage as a JavaScript Package
When creating a JavaScript action, install the config-git-with-token-action package and use it to set up git and gh in the same way.
npm i config-git-with-token-actionUse npm from above or yarn from below to install the config-git-with-token-action package.
yarn add config-git-with-token-actionImport configGitWithToken function from the package and call it to set up git and gh:
import { configGitWithToken } from 'config-git-with-token-action';
await configGitWithToken({ githubToken });FAQ
Why doesn't git push trigger downstream Workflows when I use this GitHub Action??
If you run actions/checkout before this Action without persist-credentials: false, checkout configures git to authenticate as github-actions[bot]. In that case your later git push can still use github-actions[bot] credentials, so downstream Workflows are not triggered as expected for your token identity.
Set persist-credentials: false in your checkout step to avoid this behavior.
