132 lines
4.4 KiB
YAML
132 lines
4.4 KiB
YAML
name: Build and Release
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- 'v*'
|
|
|
|
jobs:
|
|
build-amd64:
|
|
runs-on: junkpile
|
|
steps:
|
|
- name: Checkout
|
|
run: |
|
|
git init
|
|
git remote add origin ${{ gitea.server_url }}/${{ gitea.repository }}.git
|
|
git fetch --depth=1 origin ${{ gitea.ref }}
|
|
git checkout FETCH_HEAD
|
|
|
|
- name: Build .deb
|
|
run: make deb
|
|
|
|
- name: Publish and release
|
|
run: |
|
|
set -e
|
|
TAG="${{ gitea.ref_name }}"
|
|
API="${{ gitea.server_url }}/api/v1"
|
|
REPO="${{ gitea.repository }}"
|
|
TOKEN="${{ secrets.PACKAGES_TOKEN }}"
|
|
DEB=$(ls build/*.deb)
|
|
FILENAME=$(basename "${DEB}")
|
|
|
|
# Publish to apt
|
|
echo "Publishing to apt..."
|
|
curl --fail -H "Authorization: token ${TOKEN}" \
|
|
--upload-file "${DEB}" \
|
|
"${{ gitea.server_url }}/api/packages/madcat-os/debian/pool/bookworm/main/upload"
|
|
echo "apt: done"
|
|
|
|
# Delete old release if exists
|
|
OLD_ID=$(curl -s -H "Authorization: token ${TOKEN}" \
|
|
"${API}/repos/${REPO}/releases/tags/${TAG}" | jq -r 'if .id then .id else empty end')
|
|
if [ -n "${OLD_ID}" ]; then
|
|
echo "Deleting old release ${OLD_ID}..."
|
|
curl -s -X DELETE -H "Authorization: token ${TOKEN}" \
|
|
"${API}/repos/${REPO}/releases/${OLD_ID}"
|
|
fi
|
|
|
|
# Create release
|
|
echo "Creating release..."
|
|
RESP=$(curl -s -X POST \
|
|
-H "Authorization: token ${TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"tag_name\":\"${TAG}\",\"name\":\"${TAG}\",\"draft\":false,\"prerelease\":false}" \
|
|
"${API}/repos/${REPO}/releases")
|
|
RELEASE_ID=$(echo "${RESP}" | jq -r '.id')
|
|
echo "Release ID: ${RELEASE_ID}"
|
|
|
|
if [ -z "${RELEASE_ID}" ] || [ "${RELEASE_ID}" = "null" ]; then
|
|
echo "ERROR: ${RESP}"
|
|
exit 1
|
|
fi
|
|
|
|
# Attach deb
|
|
echo "Attaching ${FILENAME}..."
|
|
curl --fail -X POST \
|
|
-H "Authorization: token ${TOKEN}" \
|
|
-F "attachment=@${DEB}" \
|
|
"${API}/repos/${REPO}/releases/${RELEASE_ID}/assets?name=${FILENAME}" > /dev/null
|
|
echo "Done: amd64 published and attached"
|
|
|
|
build-arm64:
|
|
runs-on: sin
|
|
steps:
|
|
- name: Checkout
|
|
run: |
|
|
git init
|
|
git remote add origin ${{ gitea.server_url }}/${{ gitea.repository }}.git
|
|
git fetch --depth=1 origin ${{ gitea.ref }}
|
|
git checkout FETCH_HEAD
|
|
|
|
- name: Build .deb
|
|
run: make deb
|
|
|
|
- name: Publish and attach
|
|
run: |
|
|
set -e
|
|
TAG="${{ gitea.ref_name }}"
|
|
API="${{ gitea.server_url }}/api/v1"
|
|
REPO="${{ gitea.repository }}"
|
|
TOKEN="${{ secrets.PACKAGES_TOKEN }}"
|
|
DEB=$(ls build/*.deb)
|
|
FILENAME=$(basename "${DEB}")
|
|
|
|
# Publish to apt
|
|
echo "Publishing to apt..."
|
|
curl --fail -H "Authorization: token ${TOKEN}" \
|
|
--upload-file "${DEB}" \
|
|
"${{ gitea.server_url }}/api/packages/madcat-os/debian/pool/bookworm/main/upload"
|
|
echo "apt: done"
|
|
|
|
# Wait for release to exist (created by amd64 job)
|
|
echo "Waiting for release..."
|
|
for i in $(seq 1 30); do
|
|
RELEASE_ID=$(curl -s -H "Authorization: token ${TOKEN}" \
|
|
"${API}/repos/${REPO}/releases/tags/${TAG}" | jq -r 'if .id then .id else empty end')
|
|
if [ -n "${RELEASE_ID}" ]; then
|
|
break
|
|
fi
|
|
echo " attempt ${i}/30..."
|
|
sleep 10
|
|
done
|
|
|
|
if [ -z "${RELEASE_ID}" ]; then
|
|
echo "Release not found, creating..."
|
|
RESP=$(curl -s -X POST \
|
|
-H "Authorization: token ${TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"tag_name\":\"${TAG}\",\"name\":\"${TAG}\",\"draft\":false,\"prerelease\":false}" \
|
|
"${API}/repos/${REPO}/releases")
|
|
RELEASE_ID=$(echo "${RESP}" | jq -r '.id')
|
|
fi
|
|
|
|
echo "Release ID: ${RELEASE_ID}"
|
|
|
|
# Attach deb
|
|
echo "Attaching ${FILENAME}..."
|
|
curl --fail -X POST \
|
|
-H "Authorization: token ${TOKEN}" \
|
|
-F "attachment=@${DEB}" \
|
|
"${API}/repos/${REPO}/releases/${RELEASE_ID}/assets?name=${FILENAME}" > /dev/null
|
|
echo "Done: arm64 published and attached"
|