All checks were successful
Smoke test git-annex setup action / smoke-test (push) Successful in 18s
This allows for overiding Git default of 900s for caching a credential. This is needed for longer-running workflows that require credential us of a longer time span.
77 lines
2.4 KiB
YAML
77 lines
2.4 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.
|
|
|
|
timeout:
|
|
required: false
|
|
default: ""
|
|
description: >-
|
|
Number of seconds credentials are kept in the cache. If not given,
|
|
Git's own default of 900 seconds is used.
|
|
|
|
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 }}
|
|
INPUT_TIMEOUT: ${{ inputs.timeout }}
|
|
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:-}"
|
|
timeout="${INPUT_TIMEOUT:-}"
|
|
|
|
[[ -n "$username" ]] || username="$DEFAULT_USERNAME"
|
|
[[ -n "$password" ]] || password="$DEFAULT_PASSWORD"
|
|
[[ -n "$url" ]] || url="$DEFAULT_URL"
|
|
|
|
# Git's `credential cache` helper defaults to a 900s expiry.
|
|
credential_helper="cache"
|
|
[[ -n "$timeout" ]] && credential_helper+=" --timeout=${timeout}"
|
|
|
|
if [[ -n "$repo" ]]; then
|
|
git_repo=(-C "$repo")
|
|
git_scope=(--local)
|
|
else
|
|
git_repo=()
|
|
git_scope=(--global)
|
|
fi
|
|
|
|
git "${git_repo[@]+"${git_repo[@]}"}" config "${git_scope[@]}" \
|
|
credential.helper "$credential_helper"
|
|
|
|
printf 'url=%s\nusername=%s\npassword=%s\n\n' \
|
|
"$url" \
|
|
"$username" \
|
|
"$password" |
|
|
git "${git_repo[@]+"${git_repo[@]}"}" credential approve
|