actions) add gitea-compatible checkout action
This commit is contained in:
25
README.md
Normal file
25
README.md
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
# actions/checkout
|
||||||
|
|
||||||
|
A lightweight checkout action for Gitea Actions, including support for Gitea instances served from a URL subpath (for example `https://host/git`).
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- name: Checkout
|
||||||
|
uses: https://git.campbellwireless.net/actions/checkout@v1
|
||||||
|
with:
|
||||||
|
server-url: https://cloud.campbellwireless.net/git
|
||||||
|
```
|
||||||
|
|
||||||
|
## Inputs
|
||||||
|
|
||||||
|
- `server-url` (required): base server URL. Include subpath if your Gitea is not at root.
|
||||||
|
- `repository` (optional): `owner/name`, defaults to `${{ github.repository }}`.
|
||||||
|
- `ref` (optional): branch/tag/SHA, defaults to `${{ github.sha }}`.
|
||||||
|
- `token` (optional): auth token, defaults to `${{ secrets.GITHUB_TOKEN }}`.
|
||||||
|
- `path` (optional): checkout destination under workspace, defaults to `.`.
|
||||||
|
- `fetch-depth` (optional): number of commits to fetch, defaults to `1`; set `0` for full history.
|
||||||
|
|
||||||
|
## Output
|
||||||
|
|
||||||
|
- `commit`: checked out commit SHA.
|
||||||
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