Files

52 lines
2.2 KiB
YAML

name: "Deploy rpm artifacts to Gitea packages"
description: "Upload files using curl"
author: "Daniel Demus"
inputs:
pat:
description: "A PAT that allows the actor to write to the packages API endpoint"
required: true
build_arch:
description: Build architecture, default x86_64
required: false
default: x86_64
runs:
using: "composite"
steps:
- id: entrypoint
name: Deploy artifacts
shell: bash
run: |
cd ${{ gitea.workspace }}
SPECFILE=$([ "${{ inputs.specfile }}" ] && echo -n "${{ inputs.specfile }}" || echo -n $([ $(ls -1 *.spec 2>/dev/null| wc -l) -eq 1 ] && echo -n "$(ls -1 *.spec)"))
[ "$SPECFILE" == "" ] && exit 1
DIST="$(rpmspec --rpms --eval='%distcore')" DIST=${DIST#[.-]}
CURLARGS=(-s --fail-with-body --user ${{ gitea.actor }}:${{ inputs.pat }})
REPO_NAME=$(basename "${{ gitea.repository }}")
IFS=$'\n' RPM_OUTPUTS=( $(rpmspec -q --builtrpms --target=${{ inputs.build_arch }} --qf '%{n};%{evr};%{arch}\n' $SPECFILE) )
for RPM_OUTPUT in ${RPM_OUTPUTS[@]}; do
IFS=';' RPM_PARTS=($RPM_OUTPUT)
echo Publishing ${RPM_PARTS[0]}-${RPM_PARTS[1]}.${RPM_PARTS[2]}.rpm to ${{ gitea.server_url }}
curl "${CURLARGS[@]}" -H "Content-Type: application/octet-stream" --upload-file RPMS/${RPM_PARTS[2]}/${RPM_PARTS[0]}-${RPM_PARTS[1]}.${RPM_PARTS[2]}.rpm ${{ gitea.server_url }}/api/packages/${{ gitea.actor }}/rpm/${{ gitea.actor }}-${DIST}/upload
EXITCODE=$?
if [ $EXITCODE -ne 0 ]; then
echo Publishing failed
exit $EXITCODE
fi
PACKAGE_API_ARGS=(${CURLARGS[@]} ${{ gitea.api_url }}/packages/${{ gitea.actor }}/rpm/${RPM_PARTS[0]})
if [ "$(curl ${PACKAGE_API_ARGS[@]}?page=1'&'limit=1 | jq '.[0].repository.id > 0')" == "false" ]; then
echo Linking $RPM to $REPO_NAME
curl -X POST ${PACKAGE_API_ARGS[@]}/-/link/$REPO_NAME
EXITCODE=$?
if [ $EXITCODE -ne 0 ]; then
echo Linking failed
exit $EXITCODE
fi
fi
echo
done
branding:
icon: "upload"
color: "gray-dark"