diff --git a/act/checkout/action.yaml b/act/checkout/action.yaml new file mode 100644 index 0000000..9e8cfb6 --- /dev/null +++ b/act/checkout/action.yaml @@ -0,0 +1,39 @@ +# SPDX-FileCopyrightText: 2026 Vital A Pi +# 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 diff --git a/act/fetch-gh-asset/action.yaml b/act/fetch-gh-asset/action.yaml new file mode 100644 index 0000000..4d3640d --- /dev/null +++ b/act/fetch-gh-asset/action.yaml @@ -0,0 +1,31 @@ +# SPDX-FileCopyrightText: 2026 Vital A Pi +# 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 }}" diff --git a/fetch-gh-asset.sh b/fetch-gh-asset.sh new file mode 100644 index 0000000..78f52be --- /dev/null +++ b/fetch-gh-asset.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +# SPDX-FileCopyrightText: 2025 Vital A Pi +# 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 []" >&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