cache-git-credential/action.yml

61 lines
1.9 KiB
YAML

name: Cache Git credential
description: Provision a credential in Git's cache helper, globally or for a specific repo.
inputs:
username:
required: false
default: ""
description: Username for the credential. If not given, the runner-supplied `actor` is used.
password:
required: false
default: ""
description: Password or token for the credential. If not given, the runner-supplied `token` is used.
url:
required: false
default: ""
description: URL associated with the credential. If not given, the runner-supplied `server_url` is used.
repo:
required: false
default: ""
description: Repository path for local configuration. If not given, the credential is deposited at global scope.
runs:
using: composite
steps:
- name: Provision credential
shell: bash
env:
INPUT_USERNAME: ${{ inputs.username }}
INPUT_PASSWORD: ${{ inputs.password }}
INPUT_URL: ${{ inputs.url }}
INPUT_REPO: ${{ inputs.repo }}
DEFAULT_USERNAME: ${{ github.actor }}
DEFAULT_PASSWORD: ${{ github.token }}
DEFAULT_URL: ${{ github.server_url }}
run: |
set -euo pipefail
username="${INPUT_USERNAME:-}"
password="${INPUT_PASSWORD:-}"
url="${INPUT_URL:-}"
repo="${INPUT_REPO:-}"
[[ -n "$username" ]] || username="$DEFAULT_USERNAME"
[[ -n "$password" ]] || password="$DEFAULT_PASSWORD"
[[ -n "$url" ]] || url="$DEFAULT_URL"
if [[ -n "$repo" ]]; then
git -C "$repo" config --local credential.helper cache
git_command=(git -C "$repo" credential approve)
else
git config --global credential.helper cache
git_command=(git credential approve)
fi
printf 'url=%s\nusername=%s\npassword=%s\n\n' \
"$url" \
"$username" \
"$password" |
"${git_command[@]}"