81 lines
2.3 KiB
YAML
81 lines
2.3 KiB
YAML
name: Build Packages
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- '**'
|
|
tags:
|
|
- '**'
|
|
|
|
jobs:
|
|
build-library:
|
|
name: Build
|
|
runs-on: durin
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Build library
|
|
shell: bash
|
|
run: |
|
|
mkdir -p build
|
|
cd build
|
|
cmake -DCMAKE_BUILD_TYPE=Release ..
|
|
make -j
|
|
|
|
- name: Upload release asset to Gitea
|
|
if: github.ref_type == 'tag'
|
|
shell: bash
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.PIP_REPOSITORY_API_TOKEN }}
|
|
GITEA_SERVER: ${{ github.server_url }}
|
|
REPO: ${{ github.repository }}
|
|
TAG: ${{ github.ref_name }}
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
file="build/libdurin-plugin.so"
|
|
if [ ! -f "$file" ]; then
|
|
echo "Release asset not found: $file"
|
|
exit 1
|
|
fi
|
|
|
|
api="${GITEA_SERVER}/api/v1/repos/${REPO}"
|
|
|
|
release_json="$(curl -fsS \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
"${api}/releases/tags/${TAG}" || true)"
|
|
|
|
if [ -z "${release_json}" ] || [ "${release_json}" = "null" ]; then
|
|
echo "Release for tag ${TAG} does not exist, creating it"
|
|
release_json="$(curl -fsS \
|
|
-X POST \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
"${api}/releases" \
|
|
-d "{
|
|
\"tag_name\": \"${TAG}\",
|
|
\"name\": \"${TAG}\",
|
|
\"draft\": false,
|
|
\"prerelease\": false
|
|
}")"
|
|
else
|
|
echo "Release for tag ${TAG} already exists"
|
|
fi
|
|
|
|
release_id="$(printf '%s' "${release_json}" | sed -n 's/.*"id":[[:space:]]*\([0-9][0-9]*\).*/\1/p' | head -n1)"
|
|
|
|
if [ -z "${release_id}" ]; then
|
|
echo "Failed to determine release id"
|
|
echo "${release_json}"
|
|
exit 1
|
|
fi
|
|
|
|
asset_name="$(basename "${file}")"
|
|
|
|
echo "Uploading ${asset_name} to release ${release_id}"
|
|
curl -fsS \
|
|
-X POST \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-F "name=${asset_name}" \
|
|
-F "attachment=@${file};filename=${asset_name};type=application/octet-stream" \
|
|
"${api}/releases/${release_id}/assets" |