arch-package-release/action.yml

184 lines
5.7 KiB
YAML
Raw Permalink Normal View History

2024-12-27 15:45:07 +01:00
---
name: arch-package-release
description: Push Arch Package to the Forgejo Package Repository.
author: Michael Sasser <info@michaelsasser.org>
branding:
icon: shield
color: blue
inputs:
#
# Variables
#
package:
description: Path to the package.
required: false
default: ""
package_owner:
description: The name of the package owner.
required: false
default: ""
package_repository_name:
description: The name of the Arch package repository e.g. os, extra.
required: false
default: "extra"
username:
description: The username used for pushing the package.
required: false
default: ""
forge_url:
description: The URL to the forge the package is pushed to.
required: false
default: ""
#
# Secrets
#
PERSONAL_ACCESS_TOKEN:
description: The PAT for used for pushing the package.
required: true
runs:
using: composite
steps:
- name: Prepare
id: prepared
shell: bash
run: |
#
# PAT
#
if [ -z '${{ inputs.PERSONAL_ACCESS_TOKEN }}' ]; then
echo '::error title=PAT empty::You need to specify the input PERSONAL_ACCESS_TOKEN. Currently, it is an empty string.'
exit 1
fi
2024-12-27 15:45:07 +01:00
echo '::group::Prepared Data'
2024-12-27 15:45:07 +01:00
#
# Package
#
echo '::group::Package'
FILES=(*.pkg.tar.zst)
echo "Files discovered: ${FILES}"
echo 'inputs.package = ${{ inputs.package }}'
2024-12-27 15:45:07 +01:00
if [ -n '${{ inputs.package }}' ]; then
if [[ "${#FILES[@]}" == 1 ]]; then
echo "Setting package to ${FILES[0]}"
echo "::set-output name=package::${FILES[0]}"
2024-12-27 15:45:07 +01:00
else
echo '::error title=package::No package was provided and the number of packages in the output is greater than 1.'
2024-12-27 15:45:07 +01:00
exit 1
fi
fi
echo '::endgroup::'
2024-12-27 15:45:07 +01:00
#
# Username
#
echo '::group::Username'
echo 'gitea.actor = ${{ gitea.actor }}'
echo 'inputs.username = ${{ inputs.username }}'
2024-12-27 15:45:07 +01:00
USERNAME='${{ gitea.actor }}'
if [ -n '${{ inputs.username }}' ]; then
USERNAME='${{ inputs.username }}'
fi
echo "Setting username to ${USERNAME}"
echo "::set-output name=username::${USERNAME}"
echo '::endgroup::'
#
# Package Owner (local)
#
echo '::group::Package Owner'
echo 'gitea.repository_owner = ${{ gitea.repository_owner }}'
echo 'inputs.package_owner = ${{ inputs.package_owner }}'
PACKAGE_OWNER='${{ gitea.repository_owner }}'
if [ -n '${{ inputs.package_owner }}' ]; then
PACKAGE_OWNER='${{ inputs.package_owner }}'
fi
echo "Setting forge URL to ${PACKAGE_OWNER} (local)"
echo '::endgroup::'
#
# Forge URL (local
#
echo '::group::Forgejo URL'
echo 'gitea.server_url = ${{ gitea.server_url }}'
echo 'inputs.forge_url = ${{ inputs.forge_url }}'
FORGE_URL='${{ gitea.server_url }}'
if [ -n '${{ inputs.forge_url }}' ]; then
FORGE_URL='${{ inputs.forge_url }}'
fi
echo "Setting forge URL to ${FORGE_URL} (local)"
echo '::endgroup::'
#
# Package URL
#
echo '::group::Package URL'
PACKAGE_URL="${FORGE_URL}/api/packages/${PACKAGE_OWNER}/arch/${{ inputs.package_repository_name }}"
echo "Setting package URL to: ${PACKAGE_URL}"
echo "::set-output name=package_url::${PACKAGE_URL}"
echo '::endgroup::'
2024-12-27 15:45:07 +01:00
echo '::endgroup::'
- name: Push Package
shell: bash
run: |
echo '::group::cURL Version'
curl --version
echo '::endgroup::'
echo '::group::Request'
RESPONSE=$(
curl -X PUT '${{ steps.prepared.outputs.package_url }}' \
2024-12-27 15:45:07 +01:00
--silent \
--verbose \
--write-out '\n%{http_code}' \
--user '${{ steps.prepared.outputs.username }}:${{ inputs.PERSONAL_ACCESS_TOKEN }}' \
--header 'Content-Type: application/octet-stream' \
--data-binary '@${{ steps.prepared.outputs.package }}'
2024-12-27 15:45:07 +01:00
)
echo '::endgroup::'
HTTP_CODE=$(tail -n1 <<<"${RESPONSE}")
CONTEXT=$(sed '$ d' <<<"${RESPONSE}")
echo '::group::Response'
echo "${CONTEXT}"
echo '::endgroup::'
echo '::group::HTTP Code'
echo "${HTTP_CODE}"
echo '::endgroup::'
#
# Handle Result
#
2024-12-27 16:12:36 +01:00
if ((HTTP_CODE >= 200 && HTTP_CODE <= 399)); then
2024-12-27 15:45:07 +01:00
# Success
2024-12-27 16:12:36 +01:00
echo 'The package ${{ steps.prepared.outputs.package }} was successfully pushed to the package registry'
2024-12-27 15:45:07 +01:00
exit 0
2024-12-27 16:12:36 +01:00
elif ((HTTP_CODE >= 400 && HTTP_CODE <= 499)); then
2024-12-27 15:45:07 +01:00
# Client Error
if [[ "$HTTP_CODE" == 401 ]]; then
echo "::error title=Unauthorized::The authentication credentials given to the action are insufficiant to push the package."
exit 1
elif [[ "$HTTP_CODE" == 403 ]]; then
echo "::error title=Forbidden::No authentication credentials where given to the action to push the package."
exit 1
elif [[ "$HTTP_CODE" == 409 ]]; then
echo "::warning title=Conflict::The package with the same name, pkgver, pkgrel and architecture (${{ steps.prepared.outputs.package }}) already exists and was therefore not updated."
2024-12-27 15:45:07 +01:00
exit 0
2024-12-27 16:12:36 +01:00
fi
echo "::error title=Client Error::The server returned a client error with the HTTP code ${HTTP_CODE}."
2024-12-27 15:45:07 +01:00
exit 1
2024-12-27 16:12:36 +01:00
elif ((HTTP_CODE >= 500 && HTTP_CODE <= 599)); then
2024-12-27 15:45:07 +01:00
# Server error
2024-12-27 16:12:36 +01:00
echo "::error title=Server Error::The server returned a server error with the HTTP code ${HTTP_CODE}."
2024-12-27 15:45:07 +01:00
exit 1
fi