forgejo min build env: native checkout and fetch github asset script/actions
This commit is contained in:
parent
5985d6863a
commit
790ca8c2ce
3 changed files with 128 additions and 0 deletions
39
act/checkout/action.yaml
Normal file
39
act/checkout/action.yaml
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
# SPDX-FileCopyrightText: 2026 Vital A Pi <code@vp.ag>
|
||||
# SPDX-License-Identifier: MIT
|
||||
name: 'Fast minimalist working copy checkout'
|
||||
description: 'No tags, no history, no Node.js'
|
||||
|
||||
inputs:
|
||||
server_url:
|
||||
description: 'Forgejo server URL'
|
||||
required: true
|
||||
default: ${{ forgejo.server_url }}
|
||||
repository:
|
||||
description: 'Repository path (owner/repo)'
|
||||
required: true
|
||||
default: ${{ forgejo.repository }}
|
||||
sha:
|
||||
description: 'Commit SHA to checkout'
|
||||
required: true
|
||||
default: ${{ forgejo.sha }}
|
||||
token:
|
||||
description: 'Forgejo token for authentication'
|
||||
required: true
|
||||
default: ${{ forgejo.token }}
|
||||
git_object_format:
|
||||
required: true
|
||||
default: sha256
|
||||
|
||||
runs:
|
||||
using: 'composite'
|
||||
steps:
|
||||
- name: Run git checkout commands
|
||||
shell: bash
|
||||
run: |
|
||||
shopt -s dotglob
|
||||
rm -rf *
|
||||
git init --object-format=${{ inputs.git_object_format }} -b main .
|
||||
git remote add origin "${{ inputs.server_url }}/${{ inputs.repository }}.git"
|
||||
export AH="Authorization: Basic $(printf 'x-access-token:${{ inputs.token }}' | base64 | tr -d '\n')"
|
||||
git --config-env=http.extraheader=AH fetch --depth 1 origin "${{ inputs.sha }}"
|
||||
git reset --hard FETCH_HEAD
|
||||
31
act/fetch-gh-asset/action.yaml
Normal file
31
act/fetch-gh-asset/action.yaml
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# SPDX-FileCopyrightText: 2026 Vital A Pi <code@vp.ag>
|
||||
# SPDX-License-Identifier: MIT
|
||||
name: 'GitHub asset downloader'
|
||||
description: 'Downloads the file and chacks its SHA-sum.'
|
||||
|
||||
inputs:
|
||||
repo:
|
||||
description: 'The GitHub repository slug (e.g., canonical/chisel)'
|
||||
required: true
|
||||
tag:
|
||||
description: 'The release tag (e.g., v1.4.1)'
|
||||
required: true
|
||||
asset:
|
||||
description: 'The exact name of the asset'
|
||||
required: true
|
||||
jq_predicate:
|
||||
description: 'Optional jq predicate filter for complex matching'
|
||||
required: false
|
||||
default: ''
|
||||
|
||||
runs:
|
||||
using: 'composite'
|
||||
steps:
|
||||
- name: Run git checkout commands
|
||||
shell: bash
|
||||
run: |
|
||||
"${{ github.action_path }}/../../fetch-gh-asset.sh" \
|
||||
"${{ inputs.repo }}" \
|
||||
"${{ inputs.tag }}" \
|
||||
"${{ inputs.asset }}" \
|
||||
"${{ inputs.jq_predicate }}"
|
||||
58
fetch-gh-asset.sh
Normal file
58
fetch-gh-asset.sh
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
#!/usr/bin/env bash
|
||||
# SPDX-FileCopyrightText: 2025 Vital A Pi <code@vp.ag>
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
# GitHub Release Asset Downloader with Integrity Check (Forgejo CI-Kit)
|
||||
# Features:
|
||||
# - Executes in an isolated subshell to prevent env/flags contamination.
|
||||
# - Parses lists reliably using bash readarray.
|
||||
# - Leverages native GitHub 2025+ SHA256 digests (.digest) for instant verification.
|
||||
#
|
||||
|
||||
|
||||
fetch_gh_asset() (
|
||||
set -euo pipefail
|
||||
|
||||
if [ $# -lt 3 ]; then
|
||||
echo "Error: Missing arguments" >&2
|
||||
echo "Usage: fetch_gh_asset <repo_slug> <release_tag> <asset_name> [<jq_predicate>]" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
local REPO_SLUG="$1"
|
||||
local RELEASE_TAG="$2"
|
||||
local ASSET_NAME_TO_LOOKUP="$3"
|
||||
local JQ_PREDICATE="${4:-}"
|
||||
|
||||
if [ ! -z "$JQ_PREDICATE" ]; then
|
||||
local JQ_FILTER=".name | $JQ_PREDICATE"
|
||||
else
|
||||
local JQ_FILTER='.name == $aname'
|
||||
fi
|
||||
|
||||
readarray -t DATA < <(
|
||||
curl -s -f -H 'Accept: application/vnd.github+json' \
|
||||
"https://api.github.com/repos/${REPO_SLUG}/releases/tags/${RELEASE_TAG}" \
|
||||
| jq -r --arg aname "$ASSET_NAME_TO_LOOKUP" \
|
||||
".assets[] | select($JQ_FILTER) | .name, .digest, .browser_download_url"
|
||||
)
|
||||
if [ ${#DATA[@]} -ne 3 ]; then
|
||||
echo "Error: Asset not found, or ambiguous matches found, or API request failed" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
local ASSET_NAME="${DATA[0]}"
|
||||
# Releases now expose digests (SHA256) for release assets
|
||||
# https://github.blog/changelog/2025-06-03-releases-now-expose-digests-for-release-assets/
|
||||
local ASSET_DIGEST="${DATA[1]#*:}" # Comes as "sha256:..."
|
||||
local ASSET_URL="${DATA[2]}"
|
||||
|
||||
curl -sfL -o "$ASSET_NAME" "$ASSET_URL"
|
||||
|
||||
echo "$ASSET_DIGEST $ASSET_NAME" | shasum -a 256 -c -
|
||||
)
|
||||
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
fetch_gh_asset "$@"
|
||||
fi
|
||||
Loading…
Add table
Add a link
Reference in a new issue