diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 8a4ea62..488ad9a 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -16,57 +16,31 @@ jobs: git fetch --depth=1 origin ${{ gitea.ref }} git checkout FETCH_HEAD - - name: Build .deb + - name: Build run: make deb - - name: Publish and release + - name: Publish + env: + TOKEN: ${{ secrets.PACKAGES_TOKEN }} + TAG: ${{ gitea.ref_name }} + API: ${{ gitea.server_url }}/api/v1 + REPO: ${{ gitea.repository }} + PKG_URL: ${{ gitea.server_url }}/api/packages/madcat-os/debian/pool/bookworm/main/upload 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" + echo "::group::apt upload" + curl --fail -sS -H "Authorization: token ${TOKEN}" --upload-file "${DEB}" "${PKG_URL}" + echo "" + echo "::endgroup::" + echo "::group::release" + OLD_ID=$(curl -sS -H "Authorization: token ${TOKEN}" "${API}/repos/${REPO}/releases/tags/${TAG}" | jq -r 'if .id then .id else empty end' || true) + test -n "${OLD_ID}" && curl -sS -X DELETE -H "Authorization: token ${TOKEN}" "${API}/repos/${REPO}/releases/${OLD_ID}" || true + RELEASE_ID=$(curl -sS -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" | jq -r '.id') + echo "Release: ${RELEASE_ID}" + curl --fail -sS -X POST -H "Authorization: token ${TOKEN}" -F "attachment=@${DEB}" "${API}/repos/${REPO}/releases/${RELEASE_ID}/assets?name=${FILENAME}" > /dev/null 2>&1 + echo "::endgroup::" + echo "amd64 done" build-arm64: runs-on: sin @@ -78,54 +52,34 @@ jobs: git fetch --depth=1 origin ${{ gitea.ref }} git checkout FETCH_HEAD - - name: Build .deb + - name: Build run: make deb - - name: Publish and attach + - name: Publish + env: + TOKEN: ${{ secrets.PACKAGES_TOKEN }} + TAG: ${{ gitea.ref_name }} + API: ${{ gitea.server_url }}/api/v1 + REPO: ${{ gitea.repository }} + PKG_URL: ${{ gitea.server_url }}/api/packages/madcat-os/debian/pool/bookworm/main/upload 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..." + echo "::group::apt upload" + curl --fail -sS -H "Authorization: token ${TOKEN}" --upload-file "${DEB}" "${PKG_URL}" + echo "" + echo "::endgroup::" + echo "::group::attach to 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..." + RELEASE_ID=$(curl -sS -H "Authorization: token ${TOKEN}" "${API}/repos/${REPO}/releases/tags/${TAG}" | jq -r 'if .id then .id else empty end' || true) + test -n "${RELEASE_ID}" && break + echo " waiting... ${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') + RELEASE_ID=$(curl -sS -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" | 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" + echo "Release: ${RELEASE_ID}" + curl --fail -sS -X POST -H "Authorization: token ${TOKEN}" -F "attachment=@${DEB}" "${API}/repos/${REPO}/releases/${RELEASE_ID}/assets?name=${FILENAME}" > /dev/null 2>&1 + echo "::endgroup::" + echo "arm64 done"