actions) add gitea-compatible checkout action
This commit is contained in:
81
action.yml
Normal file
81
action.yml
Normal file
@@ -0,0 +1,81 @@
|
||||
name: 'Checkout'
|
||||
description: 'Checkout a repository in Gitea Actions environments'
|
||||
author: 'CampbellWireless'
|
||||
|
||||
inputs:
|
||||
repository:
|
||||
description: 'Repository in owner/name format'
|
||||
required: false
|
||||
default: ${{ github.repository }}
|
||||
ref:
|
||||
description: 'The branch, tag, or SHA to checkout'
|
||||
required: false
|
||||
default: ${{ github.sha }}
|
||||
token:
|
||||
description: 'Token used to authenticate fetch operations'
|
||||
required: false
|
||||
default: ${{ secrets.GITHUB_TOKEN }}
|
||||
server-url:
|
||||
description: 'Base URL of the Git server (include subpath if applicable)'
|
||||
required: true
|
||||
path:
|
||||
description: 'Relative path under GITHUB_WORKSPACE to checkout into'
|
||||
required: false
|
||||
default: '.'
|
||||
fetch-depth:
|
||||
description: 'Number of commits to fetch. Use 0 for full history.'
|
||||
required: false
|
||||
default: '1'
|
||||
|
||||
outputs:
|
||||
commit:
|
||||
description: 'Checked out commit SHA'
|
||||
value: ${{ steps.checkout.outputs.commit }}
|
||||
|
||||
runs:
|
||||
using: 'composite'
|
||||
steps:
|
||||
- id: checkout
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
workspace="${GITHUB_WORKSPACE:-$(pwd)}"
|
||||
target_path="${{ inputs.path }}"
|
||||
if [[ "$target_path" == "." ]]; then
|
||||
repo_dir="$workspace"
|
||||
else
|
||||
repo_dir="$workspace/$target_path"
|
||||
mkdir -p "$repo_dir"
|
||||
fi
|
||||
|
||||
repo_url="${{ inputs.server-url }}"
|
||||
repo_url="${repo_url%/}/${{ inputs.repository }}.git"
|
||||
|
||||
if [[ ! -d "$repo_dir/.git" ]]; then
|
||||
git init "$repo_dir"
|
||||
fi
|
||||
|
||||
git -C "$repo_dir" remote remove origin >/dev/null 2>&1 || true
|
||||
git -C "$repo_dir" remote add origin "$repo_url"
|
||||
|
||||
token='${{ inputs.token }}'
|
||||
if [[ -n "$token" ]]; then
|
||||
auth="$(printf '%s' "${GITHUB_ACTOR:-x-access-token}:$token" | base64 | tr -d '\n')"
|
||||
host="$(printf '%s' '${{ inputs.server-url }}' | sed -E 's#https?://([^/]+).*#\1#')"
|
||||
git -C "$repo_dir" config --local "http.https://$host/.extraheader" "AUTHORIZATION: basic $auth"
|
||||
fi
|
||||
|
||||
depth='${{ inputs.fetch-depth }}'
|
||||
if [[ "$depth" == "0" ]]; then
|
||||
git -C "$repo_dir" fetch --prune --no-recurse-submodules origin \
|
||||
+refs/heads/*:refs/remotes/origin/* \
|
||||
+refs/tags/*:refs/tags/*
|
||||
git -C "$repo_dir" checkout --detach "${{ inputs.ref }}"
|
||||
else
|
||||
git -C "$repo_dir" fetch --prune --no-recurse-submodules --depth "$depth" origin "${{ inputs.ref }}"
|
||||
git -C "$repo_dir" checkout --detach FETCH_HEAD
|
||||
fi
|
||||
|
||||
commit_sha="$(git -C "$repo_dir" rev-parse HEAD)"
|
||||
echo "commit=$commit_sha" >> "$GITHUB_OUTPUT"
|
||||
Reference in New Issue
Block a user