Files
checkout/action.yml
T

72 lines
2.4 KiB
YAML

name: 'Checkout (Gitea)'
description: 'Checkout repository with Gitea oauth2 git authentication'
inputs:
token:
description: 'Token used to fetch the repository'
required: false
default: ${{ github.token }}
server-url:
description: 'Gitea server base URL'
required: false
default: ${{ github.server_url }}
insecure-ssl:
description: 'Disable TLS certificate verification for git fetch (self-signed Gitea)'
required: false
default: 'true'
fetch-depth:
description: 'Number of commits to fetch. 0 = full history.'
required: false
default: '1'
ref:
description: 'Branch, tag or SHA to checkout (default: workflow SHA)'
required: false
default: ''
runs:
using: composite
steps:
- name: Checkout repository
shell: bash
env:
CHECKOUT_TOKEN: ${{ inputs.token }}
CHECKOUT_SERVER_URL: ${{ inputs.server-url }}
CHECKOUT_INSECURE_SSL: ${{ inputs.insecure-ssl }}
CHECKOUT_REF: ${{ inputs.ref }}
CHECKOUT_FETCH_DEPTH: ${{ inputs.fetch-depth }}
run: |
set -eo pipefail
token="${CHECKOUT_TOKEN:-}"
if [ -z "$token" ]; then
echo "Checkout token is not set (pass inputs.token or secrets.GITHUB_TOKEN)" >&2
exit 1
fi
server="${CHECKOUT_SERVER_URL:-${GITHUB_SERVER_URL:-${GITEA_SERVER_URL:-}}}"
server="${server%/}"
if [ -z "$server" ]; then
echo "Gitea server URL is not set" >&2
exit 1
fi
host="${server#https://}"
host="${host#http://}"
repo="${GITHUB_REPOSITORY:?}"
ref="${CHECKOUT_REF:-}"
if [ -z "$ref" ]; then
ref="${GITHUB_SHA:?}"
fi
depth="${CHECKOUT_FETCH_DEPTH:-1}"
depth_args=()
if [ "$depth" != "0" ]; then
depth_args=(--depth "$depth")
fi
ws="${GITHUB_WORKSPACE:?}"
cd "$ws"
rm -rf ./* ./.[!.]* ./..?* 2>/dev/null || true
git init -b main .
git config --global --add safe.directory "$ws"
if [ "${CHECKOUT_INSECURE_SSL:-false}" = "true" ] || [ "${GIT_SSL_NO_VERIFY:-false}" = "true" ]; then
git config --global http.sslVerify false
fi
git remote add origin "https://oauth2:${token}@${host}/${repo}.git"
git fetch "${depth_args[@]}" origin "$ref"
git checkout FETCH_HEAD
echo "Checked out ${repo} @ ${ref:0:12}"