Files
actions/set-git-config/action.yml

82 lines
2.6 KiB
YAML

---
# yaml-language-server: $schema=https://json.schemastore.org/github-action.json
name: Set Git Config
description: 'Sets Git configuration for actions.'
author: 'Ismo Vuorinen'
branding:
icon: git-commit
color: gray-dark
inputs:
token:
description: 'GitHub token.'
required: false
default: '${{ github.token }}'
username:
description: 'GitHub username for commits.'
default: 'github-actions'
email:
description: 'GitHub email for commits.'
default: 'github-actions@github.com'
is_fiximus:
description: 'Whether to use the Fiximus bot.'
required: false
default: 'false'
outputs:
token:
description: 'GitHub token.'
value: ${{ steps.bot.outputs.token }}
username:
description: 'GitHub username for commits.'
value: ${{ steps.bot.outputs.username }}
email:
description: 'GitHub email for commits.'
value: ${{ steps.bot.outputs.email }}
is_fiximus:
description: 'Whether to use the Fiximus bot.'
value: ${{ steps.bot.outputs.is_fiximus }}
runs:
using: composite
steps:
- name: Check for FIXIMUS_TOKEN
id: bot
shell: bash
run: |
echo "token=${{ inputs.token }}" >> $GITHUB_OUTPUT
echo "username=${{ inputs.username }}" >> $GITHUB_OUTPUT
echo "email=${{ inputs.email }}" >> $GITHUB_OUTPUT
if [ "${{ inputs.is_fiximus }}" != "false" ]; then
echo "username=fiximus" >> $GITHUB_OUTPUT
echo "email=github-bot@ivuorinen.net" >> $GITHUB_OUTPUT
fi
- name: Configure Git
shell: bash
run: |
# Function to clean up Git config
cleanup_git_config() {
git config --local --unset-all "url.https://x-access-token:${TOKEN}@github.com/.insteadof" || true
git config --local --unset-all "user.name" || true
git config --local --unset-all "user.email" || true
}
# Set up trap to ensure cleanup on exit
trap cleanup_git_config EXIT
# Store token in variable to avoid repeated exposure
TOKEN="${{ steps.bot.outputs.token }}"
git config --local --unset-all http.https://github.com/.extraheader || true
git config --local \
--add url.https://x-access-token:${{ steps.bot.outputs.token }}@github.com/.insteadOf \
"https://github.com/"
git config --local \
--add url.https://x-access-token:${{ steps.bot.outputs.token }}@github.com/.insteadOf \
'git@github.com:'
git config --local user.name "${{ steps.bot.outputs.username }}"
git config --local user.email "${{ steps.bot.outputs.email }}"