Gitea package upload script
I needed a quick way to upload QMK build artefacts to my gitea/forgejo instance, and since I’m lazy I want the script to bump the version number as well.
Luckily, gitea/forgejo has an API so it was fairly straight forward – just remember to:
- Install
jq
andcurl
, and - add below to your
~/.bash_profile
after replacing what needs replacing, and - create a
~/.netrc
file containing your credentials
# Replace GITEAOWNERHERE with the owner of the package repository (probably your username)
# Replace gitea.example.com with your instance address
function gitea-upload {
fname="${1%.*}"
# Extract the latest version and bump it
nver=$(curl -s --netrc-file ~/.netrc \
"https://gitea.example.com/api/v1/packages/GITEAOWNERHERE" \
| jq --arg fname "$fname" -c '.[] | select(.name == $fname) | .version' \
| sort \
| tail -n 1 \
| tr -d '"' \
| awk -F. -v OFS=. '{$NF += 1 ; print}' )
# Fall back to 1.0.0 if nver is empty
version="${nver:-1.0.0}"
echo "version: ${version}"
curl -s --netrc-file ~/.netrc \
--upload-file "$1" \
"https://gitea.example.com/api/packages/GITEAOWNERHERE/generic/${fname}/${version}/${fname}"
}
# Usage:
# gitea-upload filename.bin
You might want to tune the package name, I’m just removing the file extention from the files which works for my use case.
In case you need an example for the ~/.netrc
file:
machine gitea.example.com login YOUR-USERNAME-HERE password YOUR-PASSWORD-HERE