name: release on: push: tags: - 'v*.*.*' - 'v*.*.*-*' permissions: contents: write jobs: build: name: Build (${{ matrix.os }}/${{ matrix.arch }}) runs-on: ubuntu-latest strategy: fail-fast: false matrix: include: - os: linux arch: amd64 ext: '' - os: linux arch: arm64 ext: '' - os: darwin arch: amd64 ext: '' - os: darwin arch: arm64 ext: '' - os: windows arch: amd64 ext: '.exe' - os: windows arch: arm64 ext: '.exe' steps: - name: Checkout uses: https://github.com/actions/checkout@v4 with: fetch-depth: 0 - name: Setup Go uses: https://github.com/actions/setup-go@v5 with: go-version: '1.26' cache: false - name: Build binary env: VERSION: ${{ gitea.ref_name }} run: | set -euo pipefail mkdir -p dist OUT="dist/rony-llm-agent-${VERSION}-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.ext }}" GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} \ go build -trimpath \ -ldflags "-s -w -X main.version=${VERSION}" \ -o "$OUT" \ ./cmd/rony-llm-agent echo "Built $OUT" ls -lh "$OUT" - name: Upload artifact uses: https://github.com/actions/upload-artifact@v3 with: name: rony-llm-agent-${{ matrix.os }}-${{ matrix.arch }} path: dist/rony-llm-agent-* if-no-files-found: error release: name: Publish release needs: build runs-on: ubuntu-latest permissions: contents: write steps: - name: Download all artifacts uses: https://github.com/actions/download-artifact@v3 with: path: dist - name: Flatten artifacts run: | mkdir -p release find dist -type f -name 'rony-llm-agent-*' -exec mv {} release/ \; ls -lh release/ - name: Generate checksums run: | cd release sha256sum * > SHA256SUMS ls -lh - name: Create Forgejo release and upload assets env: TOKEN: ${{ secrets.FORGEJO_TOKEN }} TAG: ${{ gitea.ref_name }} API_URL: ${{ gitea.api_url }} REPO: ${{ gitea.repository }} run: | set -euo pipefail IS_PRERELEASE="false" if [[ "$TAG" == *-* ]]; then IS_PRERELEASE="true" fi echo "Creating Release $TAG in Forgejo ($REPO)..." RESPONSE=$(curl -sS -X POST \ -H "Authorization: token $TOKEN" \ -H "Content-Type: application/json" \ -d "{\"tag_name\":\"$TAG\",\"name\":\"$TAG\",\"prerelease\":$IS_PRERELEASE}" \ "$API_URL/repos/$REPO/releases") RELEASE_ID=$(echo "$RESPONSE" | jq -r ".id" 2>/dev/null || echo "$RESPONSE" | grep -o '"id":[^,]*' | head -n 1 | cut -d':' -f2 | tr -d ' ') if [[ -z "$RELEASE_ID" || "$RELEASE_ID" == "null" ]]; then echo "Error creating release in Forgejo. Response:" echo "$RESPONSE" exit 1 fi echo "Release created successfully in Forgejo with ID: $RELEASE_ID" for FILE in release/*; do if [ -f "$FILE" ]; then FILENAME=$(basename "$FILE") echo "Uploading $FILENAME to Forgejo release $RELEASE_ID..." curl -sS -X POST \ -H "Authorization: token $TOKEN" \ -F "attachment=@$FILE" \ "$API_URL/repos/$REPO/releases/$RELEASE_ID/assets" echo "" fi done echo "All assets uploaded successfully to Forgejo Release!"