arch-package-release/action.yml

177 lines
5.5 KiB
YAML

---
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: |
echo '::group::Prepared Data'
#
# Package
#
echo '::group::Package'
FILES=(*.pkg.tar.zst)
echo "Files discovered: ${FILES}"
echo 'inputs.package = ${{ inputs.package }}'
if [ -n '${{ inputs.package }}' ]; then
if [[ "${#FILES[@]}" == 1 ]]; then
echo "Setting package to ${FILES[0]}"
echo "::set-output name=package::${FILES[0]}"
else
echo '::error title=package::No package was provided and the number of packages in the output is greater than 1.'
exit 1
fi
fi
echo '::endgroup::'
#
# Username
#
echo '::group::Username'
echo 'gitea.actor = ${{ gitea.actor }}'
echo 'inputs.username = ${{ inputs.username }}'
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::'
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 }}' \
--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 }}'
)
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
#
if ((HTTP_CODE >= 200 && HTTP_CODE <= 399)); then
# Success
echo 'The package ${{ steps.prepared.outputs.package }} was successfully pushed to the package registry'
exit 0
elif ((HTTP_CODE >= 400 && HTTP_CODE <= 499)); then
# 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."
exit 0
fi
echo "::error title=Client Error::The server returned a client error with the HTTP code ${HTTP_CODE}."
exit 1
elif ((HTTP_CODE >= 500 && HTTP_CODE <= 599)); then
# Server error
echo "::error title=Server Error::The server returned a server error with the HTTP code ${HTTP_CODE}."
exit 1
fi