From 37bfd30a845ad6d15df2acf32c57b7aa93d0f890 Mon Sep 17 00:00:00 2001 From: Salastil Date: Sun, 23 Nov 2025 05:42:55 -0500 Subject: [PATCH] Unique filenames for builds --- .gitea/workflows/release.yml | 128 ++++++++++++----------------------- 1 file changed, 42 insertions(+), 86 deletions(-) diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index 7d6efd4..9490681 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -1,6 +1,8 @@ name: Build Release Binaries on: + release: + types: [published] push: tags: - "v*" @@ -17,32 +19,19 @@ jobs: runs-on: ubuntu-latest steps: - # ------------------------------------------------------------- - # Checkout - # ------------------------------------------------------------- - name: Checkout repository uses: actions/checkout@v4 - # ------------------------------------------------------------- - # Setup Go - # ------------------------------------------------------------- - name: Set up Go uses: actions/setup-go@v5 with: go-version-file: go.mod cache: true - # ------------------------------------------------------------- - # Bundle Node Modules (important for puppeteer-extra) - # ------------------------------------------------------------- - - name: Bundle node_modules for extractor + - name: Bundle Node.js dependencies run: | - chmod +x scripts/build_node_modules.sh - ./scripts/build_node_modules.sh + bash scripts/build_node_modules.sh - # ------------------------------------------------------------- - # Build all platform binaries - # ------------------------------------------------------------- - name: Build all platform binaries run: | mkdir -p dist @@ -50,110 +39,77 @@ jobs: build() { GOOS=$1 GOARCH=$2 - SUFFIX=$3 - OUT="${BINARY_NAME}${SUFFIX}" - - echo "Building: GOOS=$1 GOARCH=$2 OUTPUT=$OUT" - env GOOS=$1 GOARCH=$2 CGO_ENABLED=0 go build -o "dist/$OUT" . + EXT=$3 + OUT="${BINARY_NAME}_${GOOS}_${GOARCH}${EXT}" + echo "Building $GOOS $GOARCH => $OUT" + env GOOS=$1 GOARCH=$2 CGO_ENABLED=0 go build -o "dist/${OUT}" . } - build linux amd64 "" - build linux arm64 "" - build darwin amd64 "" - build darwin arm64 "" + build linux amd64 "" + build linux arm64 "" + build darwin amd64 "" + build darwin arm64 "" - # ------------------------------------------------------------- - # Create or fetch the Gitea release - # ------------------------------------------------------------- - - name: Ensure release exists (create if missing) + - name: Create release in Gitea id: create_release env: - GITEA_TOKEN: ${{ secrets.CI_TOKEN2 }} + GITEA_TOKEN: ${{ secrets.CI_TOKEN }} TAG: ${{ github.ref_name }} REPO: ${{ github.repository }} - API_BASE: ${{ env.API_BASE }} run: | if [ -z "$GITEA_TOKEN" ]; then - echo "ERROR: Missing CI_TOKEN2 secret" + echo "ERROR: Missing CI_TOKEN secret" exit 1 fi echo "Checking if release exists: $TAG" - EXISTING=$(curl -s -o /dev/null -w "%{http_code}" \ + # Check release existence + CHECK=$(curl -s -o /dev/null -w "%{http_code}" \ -H "Authorization: token ${GITEA_TOKEN}" \ - "${API_BASE}/repos/${REPO}/releases/tags/${TAG}") + "${{ env.API_BASE }}/repos/${REPO}/releases/tags/${TAG}") - if [ "$EXISTING" = "200" ]; then - echo "Release already exists — fetching ID" - BODY=$(curl -s \ + if [ "$CHECK" = "200" ]; then + echo "Release already exists." + RELEASE_ID=$(curl -s \ -H "Authorization: token ${GITEA_TOKEN}" \ - "${API_BASE}/repos/${REPO}/releases/tags/${TAG}") + "${{ env.API_BASE }}/repos/${REPO}/releases/tags/${TAG}" | \ + grep -o '"id":[0-9]*' | grep -o '[0-9]*') + else + echo "Release does not exist — creating" + RESPONSE=$(curl -s -X POST \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -H "Content-Type: application/json" \ + -d "{ + \"tag_name\": \"${TAG}\", + \"name\": \"Release ${TAG}\", + \"body\": \"Automated release ${TAG}\", + \"draft\": false, + \"prerelease\": false + }" \ + "${{ env.API_BASE }}/repos/${REPO}/releases") - RELEASE_ID=$(echo "$BODY" | grep -o '"id":[0-9]*' | head -1 | grep -o '[0-9]*') - echo "Found release ID: $RELEASE_ID" - - echo "release_id=${RELEASE_ID}" >> $GITHUB_OUTPUT - exit 0 + RELEASE_ID=$(echo "$RESPONSE" | grep -o '"id":[0-9]*' | grep -o '[0-9]*') fi - echo "Release does not exist — creating" - - # Create new release, capture body + status code - RESPONSE=$(curl -s -w "\n%{http_code}" -X POST \ - -H "Authorization: token ${GITEA_TOKEN}" \ - -H "Content-Type: application/json" \ - -d "{ - \"tag_name\": \"${TAG}\", - \"name\": \"Release ${TAG}\", - \"body\": \"Automated release ${TAG}\", - \"draft\": false, - \"prerelease\": false - }" \ - "${API_BASE}/repos/${REPO}/releases") - - BODY=$(echo "$RESPONSE" | sed '$d') - CODE=$(echo "$RESPONSE" | tail -n1) - - echo "Gitea API Response Code: $CODE" - echo "Gitea API Response Body:" - echo "$BODY" - - if [ "$CODE" -ne 201 ] && [ "$CODE" -ne 200 ]; then - echo "ERROR: Release creation failed" - exit 1 - fi - - RELEASE_ID=$(echo "$BODY" | grep -o '"id":[0-9]*' | head -1 | grep -o '[0-9]*') - - if [ -z "$RELEASE_ID" ]; then - echo "ERROR: Could not extract release ID" - exit 1 - fi - - echo "Created release ID: $RELEASE_ID" echo "release_id=${RELEASE_ID}" >> $GITHUB_OUTPUT - # ------------------------------------------------------------- - # Upload binaries - # ------------------------------------------------------------- - - name: Upload binaries to Gitea release + - name: Upload release assets env: - GITEA_TOKEN: ${{ secrets.CI_TOKEN2 }} + GITEA_TOKEN: ${{ secrets.CI_TOKEN }} RELEASE_ID: ${{ steps.create_release.outputs.release_id }} API_BASE: ${{ env.API_BASE }} REPO: ${{ github.repository }} run: | - cd dist echo "Uploading binaries..." - for file in *; do + for file in dist/*; do echo "Uploading $file" curl -s -X POST \ -H "Authorization: token ${GITEA_TOKEN}" \ -H "Content-Type: application/octet-stream" \ --data-binary @"$file" \ - "${API_BASE}/repos/${REPO}/releases/${RELEASE_ID}/assets?name=$file" + "${API_BASE}/repos/${REPO}/releases/${RELEASE_ID}/assets?name=$(basename "$file")" done - echo "All binaries uploaded successfully." + echo "Done uploading release artifacts"