Run builds in parallel, robust release handling
This commit is contained in:
+56
-40
@@ -19,16 +19,9 @@ jobs:
|
|||||||
- name: Build .deb
|
- name: Build .deb
|
||||||
run: make deb
|
run: make deb
|
||||||
|
|
||||||
- name: Publish to apt registry
|
- name: Publish and release
|
||||||
run: |
|
|
||||||
DEB=$(ls build/*.deb)
|
|
||||||
echo "Publishing ${DEB}..."
|
|
||||||
curl --fail -H "Authorization: token ${{ secrets.PACKAGES_TOKEN }}" \
|
|
||||||
--upload-file "${DEB}" \
|
|
||||||
"${{ gitea.server_url }}/api/packages/madcat-os/debian/pool/bookworm/main/upload"
|
|
||||||
|
|
||||||
- name: Create release and attach
|
|
||||||
run: |
|
run: |
|
||||||
|
set -e
|
||||||
TAG="${{ gitea.ref_name }}"
|
TAG="${{ gitea.ref_name }}"
|
||||||
API="${{ gitea.server_url }}/api/v1"
|
API="${{ gitea.server_url }}/api/v1"
|
||||||
REPO="${{ gitea.repository }}"
|
REPO="${{ gitea.repository }}"
|
||||||
@@ -36,38 +29,47 @@ jobs:
|
|||||||
DEB=$(ls build/*.deb)
|
DEB=$(ls build/*.deb)
|
||||||
FILENAME=$(basename "${DEB}")
|
FILENAME=$(basename "${DEB}")
|
||||||
|
|
||||||
# Delete existing release for this tag if any
|
# 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}" \
|
OLD_ID=$(curl -s -H "Authorization: token ${TOKEN}" \
|
||||||
"${API}/repos/${REPO}/releases/tags/${TAG}" | jq -r '.id // empty')
|
"${API}/repos/${REPO}/releases/tags/${TAG}" | jq -r 'if .id then .id else empty end')
|
||||||
if [ -n "${OLD_ID}" ] && [ "${OLD_ID}" != "null" ]; then
|
if [ -n "${OLD_ID}" ]; then
|
||||||
echo "Deleting existing release ${OLD_ID}..."
|
echo "Deleting old release ${OLD_ID}..."
|
||||||
curl -s -X DELETE -H "Authorization: token ${TOKEN}" \
|
curl -s -X DELETE -H "Authorization: token ${TOKEN}" \
|
||||||
"${API}/repos/${REPO}/releases/${OLD_ID}"
|
"${API}/repos/${REPO}/releases/${OLD_ID}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create release
|
# Create release
|
||||||
RELEASE_ID=$(curl -s -X POST \
|
echo "Creating release..."
|
||||||
|
RESP=$(curl -s -X POST \
|
||||||
-H "Authorization: token ${TOKEN}" \
|
-H "Authorization: token ${TOKEN}" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "{\"tag_name\":\"${TAG}\",\"name\":\"${TAG}\",\"draft\":false,\"prerelease\":false}" \
|
-d "{\"tag_name\":\"${TAG}\",\"name\":\"${TAG}\",\"draft\":false,\"prerelease\":false}" \
|
||||||
"${API}/repos/${REPO}/releases" | jq -r '.id')
|
"${API}/repos/${REPO}/releases")
|
||||||
|
RELEASE_ID=$(echo "${RESP}" | jq -r '.id')
|
||||||
echo "Release ID: ${RELEASE_ID}"
|
echo "Release ID: ${RELEASE_ID}"
|
||||||
|
|
||||||
if [ -z "${RELEASE_ID}" ] || [ "${RELEASE_ID}" = "null" ]; then
|
if [ -z "${RELEASE_ID}" ] || [ "${RELEASE_ID}" = "null" ]; then
|
||||||
echo "ERROR: Failed to create release"
|
echo "ERROR: ${RESP}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Attach amd64 deb
|
# Attach deb
|
||||||
|
echo "Attaching ${FILENAME}..."
|
||||||
curl --fail -X POST \
|
curl --fail -X POST \
|
||||||
-H "Authorization: token ${TOKEN}" \
|
-H "Authorization: token ${TOKEN}" \
|
||||||
-F "attachment=@${DEB}" \
|
-F "attachment=@${DEB}" \
|
||||||
"${API}/repos/${REPO}/releases/${RELEASE_ID}/assets?name=${FILENAME}"
|
"${API}/repos/${REPO}/releases/${RELEASE_ID}/assets?name=${FILENAME}" > /dev/null
|
||||||
echo "Attached: ${FILENAME}"
|
echo "Done: amd64 published and attached"
|
||||||
|
|
||||||
build-arm64:
|
build-arm64:
|
||||||
runs-on: sin
|
runs-on: sin
|
||||||
needs: [build-amd64]
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
run: |
|
run: |
|
||||||
@@ -79,16 +81,9 @@ jobs:
|
|||||||
- name: Build .deb
|
- name: Build .deb
|
||||||
run: make deb
|
run: make deb
|
||||||
|
|
||||||
- name: Publish to apt registry
|
- name: Publish and attach
|
||||||
run: |
|
|
||||||
DEB=$(ls build/*.deb)
|
|
||||||
echo "Publishing ${DEB}..."
|
|
||||||
curl --fail -H "Authorization: token ${{ secrets.PACKAGES_TOKEN }}" \
|
|
||||||
--upload-file "${DEB}" \
|
|
||||||
"${{ gitea.server_url }}/api/packages/madcat-os/debian/pool/bookworm/main/upload"
|
|
||||||
|
|
||||||
- name: Attach to release
|
|
||||||
run: |
|
run: |
|
||||||
|
set -e
|
||||||
TAG="${{ gitea.ref_name }}"
|
TAG="${{ gitea.ref_name }}"
|
||||||
API="${{ gitea.server_url }}/api/v1"
|
API="${{ gitea.server_url }}/api/v1"
|
||||||
REPO="${{ gitea.repository }}"
|
REPO="${{ gitea.repository }}"
|
||||||
@@ -96,20 +91,41 @@ jobs:
|
|||||||
DEB=$(ls build/*.deb)
|
DEB=$(ls build/*.deb)
|
||||||
FILENAME=$(basename "${DEB}")
|
FILENAME=$(basename "${DEB}")
|
||||||
|
|
||||||
# Find existing release by tag
|
# Publish to apt
|
||||||
RELEASE_ID=$(curl -s \
|
echo "Publishing to apt..."
|
||||||
-H "Authorization: token ${TOKEN}" \
|
curl --fail -H "Authorization: token ${TOKEN}" \
|
||||||
"${API}/repos/${REPO}/releases/tags/${TAG}" | jq -r '.id')
|
--upload-file "${DEB}" \
|
||||||
echo "Release ID: ${RELEASE_ID}"
|
"${{ gitea.server_url }}/api/packages/madcat-os/debian/pool/bookworm/main/upload"
|
||||||
|
echo "apt: done"
|
||||||
|
|
||||||
if [ -z "${RELEASE_ID}" ] || [ "${RELEASE_ID}" = "null" ]; then
|
# Wait for release to exist (created by amd64 job)
|
||||||
echo "ERROR: Release not found for tag ${TAG}"
|
echo "Waiting for release..."
|
||||||
exit 1
|
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
|
fi
|
||||||
|
|
||||||
# Attach arm64 deb
|
echo "Release ID: ${RELEASE_ID}"
|
||||||
|
|
||||||
|
# Attach deb
|
||||||
|
echo "Attaching ${FILENAME}..."
|
||||||
curl --fail -X POST \
|
curl --fail -X POST \
|
||||||
-H "Authorization: token ${TOKEN}" \
|
-H "Authorization: token ${TOKEN}" \
|
||||||
-F "attachment=@${DEB}" \
|
-F "attachment=@${DEB}" \
|
||||||
"${API}/repos/${REPO}/releases/${RELEASE_ID}/assets?name=${FILENAME}"
|
"${API}/repos/${REPO}/releases/${RELEASE_ID}/assets?name=${FILENAME}" > /dev/null
|
||||||
echo "Attached: ${FILENAME}"
|
echo "Done: arm64 published and attached"
|
||||||
|
|||||||
Reference in New Issue
Block a user