--- name: arch-package-release description: Push Arch Package to the Forgejo Package Repository. author: Michael Sasser 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' # # Forge 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}" echo "::set-output name=forge_url::${FORGE_URL}" # # 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 # # 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}" echo "::set-output name=package_owner::${PACKAGE_OWNER}" # # 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::' # TODO: Handle overwrite - name: Push Package shell: bash run: | echo '::group::cURL Version' curl --version echo '::endgroup::' PACKAGE_URL='${{ steps.prepared.outputs.forge_url }}/api/packages/${{ steps.prepared.outputs.repository_owner }}/arch/${{ inputs.package_repository_name }}' echo '::group::Request' RESPONSE=$( curl -X PUT "${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::' 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" == 409 ]]; then echo "::warning title=package already exists::The package with the same name, pkgver, pkgrel and architecture ('${{ steps.prepared.outputs.package }}') already exists and was therefore not updated." exit 0 if 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