mirror of
https://hub.datalad.org/git-annex/setup-gitannex-action.git
synced 2026-11-25 08:15:06 +00:00
Use an overall safer approach to push parameters into git-credential-approve.
99 lines
3.4 KiB
YAML
99 lines
3.4 KiB
YAML
name: Set up git-annex
|
||
description: Install git-annex, and configure Git(-annex) for accessing private repositories.
|
||
|
||
inputs:
|
||
version:
|
||
required: false
|
||
default: ""
|
||
description: Optional identifier for the git-annex version to install. See https://pypi.org/project/git-annex/#history for available versions.
|
||
git-name:
|
||
required: false
|
||
default: "Workflow runner"
|
||
description: User name used for the Git identity with which git-annex may create commits.
|
||
git-email:
|
||
required: false
|
||
default: ""
|
||
description: User email used for the Git identity with which git-annex may create commits. By default, a surrogate email is generated from the actor identity and the server URL that triggered the workflow.
|
||
enable-private-repo-access:
|
||
required: false
|
||
default: "true"
|
||
description: Cache the action actor/token credential for non-interactive access by git-annex.
|
||
credential-cache-timeout:
|
||
required: false
|
||
default: "900"
|
||
description: Credential cache lifetime in seconds (1–86400).
|
||
|
||
runs:
|
||
using: composite
|
||
steps:
|
||
- name: Ensure uv is available
|
||
shell: bash
|
||
run: |
|
||
set -euo pipefail
|
||
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
|
||
if command -v uv >/dev/null 2>&1; then
|
||
echo "uv already available: $(uv --version)"
|
||
else
|
||
echo "##[group]Installing uv"
|
||
curl -LsSf https://astral.sh/uv/install.sh | sh
|
||
export PATH="$HOME/.local/bin:$PATH"
|
||
echo "##[endgroup]"
|
||
echo "uv installed: $(uv --version)"
|
||
fi
|
||
|
||
- name: Install git-annex
|
||
shell: bash
|
||
env:
|
||
SGA_VERSION: ${{ inputs.version }}
|
||
run: |
|
||
set -euo pipefail
|
||
echo "##[group]Installing git-annex"
|
||
if [ -n "${SGA_VERSION}" ]; then
|
||
uv tool install "git-annex==${SGA_VERSION}"
|
||
else
|
||
uv tool install git-annex
|
||
fi
|
||
echo "##[group]Verify (git-)annex setup"
|
||
git --version
|
||
git annex version
|
||
echo "##[endgroup]"
|
||
echo "##[endgroup]"
|
||
echo "git-annex installed: $(git annex version --raw)"
|
||
|
||
- name: Configure Git identity (for git-annex)
|
||
shell: bash
|
||
env:
|
||
SGA_NAME: ${{ inputs.git-name }}
|
||
SGA_EMAIL: ${{ inputs.git-email }}
|
||
run: |
|
||
set -euo pipefail
|
||
git config --global user.name "${SGA_NAME}"
|
||
if [ -n "$SGA_EMAIL" ]; then
|
||
git config --global user.email "${SGA_EMAIL}"
|
||
else
|
||
git config --global user.email "${{ github.actor }}@${GITHUB_SERVER_URL#*://}"
|
||
fi
|
||
|
||
- name: Provision Git(-annex) access token for private repositories
|
||
if: ${{ inputs.enable-private-repo-access == 'true' }}
|
||
shell: bash
|
||
env:
|
||
GH_SERVER_URL: ${{ github.server_url }}
|
||
GH_ACTOR: ${{ github.actor }}
|
||
GH_TOKEN: ${{ github.token }}
|
||
SGA_CREDENTIAL_CACHE_TIMEOUT: ${{ inputs.credential-cache-timeout }}
|
||
run: |
|
||
set -euo pipefail
|
||
|
||
if [[ ! "$SGA_CREDENTIAL_CACHE_TIMEOUT" =~ ^[0-9]+$ ]] ||
|
||
(( SGA_CREDENTIAL_CACHE_TIMEOUT < 1 || SGA_CREDENTIAL_CACHE_TIMEOUT > 86400 )); then
|
||
echo "credential-cache-timeout must be an integer from 1 to 86400 seconds" >&2
|
||
exit 1
|
||
fi
|
||
|
||
git config --global credential.helper \
|
||
"cache --timeout=$SGA_CREDENTIAL_CACHE_TIMEOUT"
|
||
printf 'url=%s\nusername=%s\npassword=%s\n\n' \
|
||
"$GH_SERVER_URL" "$GH_ACTOR" "$GH_TOKEN" |
|
||
git credential approve
|
||
|