Files
2026-09-24 11:35:00 +02:00

84 lines
3.3 KiB
YAML

name: "Mirror RPM to Gitea"
description: "Uploads an RPM file to a Gitea organization RPM registry"
inputs:
owner:
description: "Remote - Organization or user account name"
required: true
repository:
description: "Remote - Git repository name"
required: true
files:
description: "Space-separated list of files to mirror for the release"
required: true
runs:
using: "composite"
steps:
- shell: bash
name: Check for latest release on GitHub
id: check_release
run: |
echo "::notice::Checking ${{ inputs.owner }}/${{ inputs.repository }} for new releases"
# Fetch all releases and sort them by creation date descending, we only need the latest release tag/date info
API_OUTPUT=$(curl -s \
"https://api.github.com/repos/${{ inputs.owner }}/${{ inputs.repository }}/releases?per_page=1")
# Check if API call failed or returned no data
if [ "$API_OUTPUT" == '[]' ]; then
echo "::error::No releases found in the target repository."
exit 1
fi
echo "::group::API Output"
echo "${API_OUTPUT}"
echo "::endgroup::"
# Extract the tag name and published date of the latest release
LATEST_TAG=$(echo "${API_OUTPUT}" | jq -r '.[0].tag_name')
PUBLISH_DATE=$(echo "${API_OUTPUT}" | jq -r '.[0].published_at')
echo "::notice:: Found latest version: ${LATEST_TAG} published on ${PUBLISH_DATE}"
# Set output variables for subsequent steps
echo "latest_tag=${LATEST_TAG}" >> $GITHUB_OUTPUT
echo "publish_date=${PUBLISH_DATE}" >> $GITHUB_OUTPUT
# Check if the release already exists on Gitea
- shell: bash
name: Check if release exists on Gitea
id: check_release_exists
run: |
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/tags/${{ steps.check_release.outputs.latest_tag }}")
if [ "$HTTP_STATUS" -eq 200 ]; then
echo "::notice::Release already exists. Skipping step."
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "::notice::Release does not exist."
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- shell: bash
name: Download latest release from GitHub
if: steps.check_release_exists.outputs.exists != 'true'
run: |
DOWNLOAD_URL="https://github.com/${{ inputs.owner }}/${{ inputs.repository }}/releases/download/${{ steps.check_release.outputs.latest_tag }}/${{ inputs.files }}"
echo "::notice::Downloading release from $DOWNLOAD_URL ..."
curl -L -o "${{ inputs.files }}" "$DOWNLOAD_URL"
- shell: bash
name: Create and upload release on Gitea
if: steps.check_release_exists.outputs.exists != 'true'
uses: actions/gitea-release-action@v1
with:
name: ${{ steps.check_release.outputs.latest_tag }}
tag_name: ${{ steps.check_release.outputs.latest_tag }}
release_name: ${{ steps.check_release.outputs.latest_tag }}
body: "Release ${{ steps.check_release.outputs.latest_tag }} published on ${{ steps.check_release.outputs.publish_date }}"
files: ./${{ inputs.files }}