Fix Gitea Actions workflow for compatibility

- Replace GitHub Actions with native Gitea Actions syntax
- Remove dependency on Node.js-based actions
- Use manual git checkout instead of actions/checkout
- Download Go directly instead of using actions/setup-go
- Use native curl/bash for release creation and uploads
- Support both main and master branch pushes
- Simplify Docker image building without external actions
- Add proper Gitea API token handling for releases
This commit is contained in:
Ducky SSH User
2025-12-20 06:05:29 +00:00
parent b87c61ea99
commit 5664105111

View File

@@ -3,6 +3,7 @@ name: Build and Release
on: on:
push: push:
branches: branches:
- main
- master - master
tags: tags:
- 'v*' - 'v*'
@@ -12,12 +13,19 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 run: |
cd $GITHUB_WORKSPACE
git init
git remote add origin ${{ github.server_url }}/${{ github.repository }}.git
git fetch origin ${{ github.ref }}
git checkout -b ${{ github.ref_name }} origin/${{ github.ref_name }}
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v4 run: |
with: wget https://go.dev/dl/go1.24.4.linux-amd64.tar.gz
go-version: '1.24.4' tar -C /usr/local -xzf go1.24.4.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
go version
- name: Generate version - name: Generate version
id: version id: version
@@ -27,114 +35,188 @@ jobs:
else else
VERSION=dev-${{ github.sha }} VERSION=dev-${{ github.sha }}
fi fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT echo "version=${VERSION}" >> $GITHUB_ENV
- name: Build all binaries - name: Build all binaries
run: | run: |
export PATH=$PATH:/usr/local/go/bin
mkdir -p bin mkdir -p bin
# Generate templ first # Generate templ first
go run github.com/a-h/templ/cmd/templ@latest generate go run github.com/a-h/templ/cmd/templ@latest generate
# Linux AMD64 # Linux AMD64
echo "Building Linux AMD64..."
GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o bin/nerd-monitor-server-linux-amd64 ./cmd/server GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o bin/nerd-monitor-server-linux-amd64 ./cmd/server
GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o bin/nerd-monitor-agent-linux-amd64 ./cmd/agent GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o bin/nerd-monitor-agent-linux-amd64 ./cmd/agent
# Linux ARM64 # Linux ARM64
echo "Building Linux ARM64..."
GOOS=linux GOARCH=arm64 go build -ldflags="-w -s" -o bin/nerd-monitor-server-linux-arm64 ./cmd/server GOOS=linux GOARCH=arm64 go build -ldflags="-w -s" -o bin/nerd-monitor-server-linux-arm64 ./cmd/server
GOOS=linux GOARCH=arm64 go build -ldflags="-w -s" -o bin/nerd-monitor-agent-linux-arm64 ./cmd/agent GOOS=linux GOARCH=arm64 go build -ldflags="-w -s" -o bin/nerd-monitor-agent-linux-arm64 ./cmd/agent
# macOS AMD64 # macOS AMD64
echo "Building macOS AMD64..."
GOOS=darwin GOARCH=amd64 go build -ldflags="-w -s" -o bin/nerd-monitor-server-darwin-amd64 ./cmd/server GOOS=darwin GOARCH=amd64 go build -ldflags="-w -s" -o bin/nerd-monitor-server-darwin-amd64 ./cmd/server
GOOS=darwin GOARCH=amd64 go build -ldflags="-w -s" -o bin/nerd-monitor-agent-darwin-amd64 ./cmd/agent GOOS=darwin GOARCH=amd64 go build -ldflags="-w -s" -o bin/nerd-monitor-agent-darwin-amd64 ./cmd/agent
# macOS ARM64 # macOS ARM64
echo "Building macOS ARM64..."
GOOS=darwin GOARCH=arm64 go build -ldflags="-w -s" -o bin/nerd-monitor-server-darwin-arm64 ./cmd/server GOOS=darwin GOARCH=arm64 go build -ldflags="-w -s" -o bin/nerd-monitor-server-darwin-arm64 ./cmd/server
GOOS=darwin GOARCH=arm64 go build -ldflags="-w -s" -o bin/nerd-monitor-agent-darwin-arm64 ./cmd/agent GOOS=darwin GOARCH=arm64 go build -ldflags="-w -s" -o bin/nerd-monitor-agent-darwin-arm64 ./cmd/agent
# Windows AMD64 # Windows AMD64
echo "Building Windows AMD64..."
GOOS=windows GOARCH=amd64 go build -ldflags="-w -s" -o bin/nerd-monitor-server-windows-amd64.exe ./cmd/server GOOS=windows GOARCH=amd64 go build -ldflags="-w -s" -o bin/nerd-monitor-server-windows-amd64.exe ./cmd/server
GOOS=windows GOARCH=amd64 go build -ldflags="-w -s" -o bin/nerd-monitor-agent-windows-amd64.exe ./cmd/agent GOOS=windows GOARCH=amd64 go build -ldflags="-w -s" -o bin/nerd-monitor-agent-windows-amd64.exe ./cmd/agent
echo "Build complete! Files:"
ls -lh bin/
- name: Create checksums - name: Create checksums
run: | run: |
cd bin cd bin
sha256sum * > SHA256SUMS sha256sum * > SHA256SUMS
cd .. cd ..
echo "Checksums:"
cat bin/SHA256SUMS
- name: Upload artifacts - name: Create Release and Upload
uses: actions/upload-artifact@v4
with:
name: binaries-${{ steps.version.outputs.version }}
path: bin/
retention-days: 30
- name: Create Release
if: startsWith(github.ref, 'refs/tags/')
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
- name: Upload release assets
if: startsWith(github.ref, 'refs/tags/') if: startsWith(github.ref, 'refs/tags/')
run: | run: |
# This step uploads binaries to the release export GITEA_TOKEN="${{ secrets.GITEA_TOKEN }}"
# Note: Gitea Actions may require additional configuration export GITEA_URL="${{ github.server_url }}"
export REPO_OWNER="${{ github.repository_owner }}"
export REPO_NAME="${{ github.repository }}"
export REPO_NAME=${REPO_NAME#*/}
TAG=${{ github.ref_name }}
echo "Creating release for tag: $TAG"
echo "Repository: $REPO_OWNER/$REPO_NAME"
# Get or create release
RELEASE_JSON=$(curl -s -X GET \
-H "Authorization: token $GITEA_TOKEN" \
"$GITEA_URL/api/v1/repos/$REPO_OWNER/$REPO_NAME/releases/tags/$TAG" 2>/dev/null || echo "{}")
RELEASE_ID=$(echo "$RELEASE_JSON" | jq -r '.id // empty' 2>/dev/null)
if [ -z "$RELEASE_ID" ]; then
echo "Creating new release..."
RELEASE_JSON=$(curl -s -X POST \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"tag_name\":\"$TAG\",\"name\":\"Release $TAG\",\"draft\":false,\"prerelease\":false}" \
"$GITEA_URL/api/v1/repos/$REPO_OWNER/$REPO_NAME/releases")
RELEASE_ID=$(echo "$RELEASE_JSON" | jq -r '.id')
echo "Created release ID: $RELEASE_ID"
else
echo "Using existing release ID: $RELEASE_ID"
fi
# Upload all binaries
echo "Uploading release artifacts..."
for file in bin/*; do for file in bin/*; do
if [ -f "$file" ]; then if [ -f "$file" ]; then
echo "Uploading $file to release" filename=$(basename "$file")
echo " Uploading: $filename"
curl -s -X POST \
-H "Authorization: token $GITEA_TOKEN" \
-F "attachment=@$file" \
"$GITEA_URL/api/v1/repos/$REPO_OWNER/$REPO_NAME/releases/$RELEASE_ID/assets" > /dev/null
if [ $? -eq 0 ]; then
echo " ✓ $filename uploaded"
else
echo " ✗ Failed to upload $filename"
fi
fi fi
done done
echo ""
echo "Release completed!"
echo "View at: $GITEA_URL/$REPO_OWNER/$REPO_NAME/releases/tag/$TAG"
docker-build: docker-build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 run: |
cd $GITHUB_WORKSPACE
git init
git remote add origin ${{ github.server_url }}/${{ github.repository }}.git
git fetch origin ${{ github.ref }}
git checkout -b ${{ github.ref_name }} origin/${{ github.ref_name }}
- name: Set up Docker Buildx - name: Set up Docker
uses: docker/setup-buildx-action@v3 run: |
docker --version
which docker
- name: Generate version - name: Generate version
id: version id: version
run: | run: |
if [[ "${{ github.ref }}" == refs/tags/* ]]; then if [[ "${{ github.ref }}" == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/} VERSION=${{ github.ref_name }}
else else
VERSION=dev-${{ github.sha }} VERSION=dev-${{ github.sha }}
fi fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT echo "version=${VERSION}" >> $GITHUB_ENV
- name: Build and push server image - name: Build Docker images
uses: docker/build-push-action@v5 run: |
with: mkdir -p /tmp/docker-images
context: .
file: ./Dockerfile.server echo "Building server image..."
push: false docker build -t nerd-monitor-server:${{ env.version }} -f Dockerfile.server .
outputs: type=docker,dest=/tmp/nerd-monitor-server.tar docker save nerd-monitor-server:${{ env.version }} -o /tmp/docker-images/nerd-monitor-server-${{ env.version }}.tar
tags: |
nerd-monitor-server:latest echo "Building agent image..."
nerd-monitor-server:${{ steps.version.outputs.version }} docker build -t nerd-monitor-agent:${{ env.version }} -f Dockerfile.agent .
docker save nerd-monitor-agent:${{ env.version }} -o /tmp/docker-images/nerd-monitor-agent-${{ env.version }}.tar
echo "Docker images built:"
ls -lh /tmp/docker-images/
- name: Build and push agent image - name: Upload Docker images to release
uses: docker/build-push-action@v5 if: startsWith(github.ref, 'refs/tags/')
with: run: |
context: . export GITEA_TOKEN="${{ secrets.GITEA_TOKEN }}"
file: ./Dockerfile.agent export GITEA_URL="${{ github.server_url }}"
push: false export REPO_OWNER="${{ github.repository_owner }}"
outputs: type=docker,dest=/tmp/nerd-monitor-agent.tar export REPO_NAME="${{ github.repository }}"
tags: | export REPO_NAME=${REPO_NAME#*/}
nerd-monitor-agent:latest
nerd-monitor-agent:${{ steps.version.outputs.version }} TAG=${{ github.ref_name }}
- name: Upload Docker images # Get existing release
uses: actions/upload-artifact@v4 RELEASE_JSON=$(curl -s -X GET \
with: -H "Authorization: token $GITEA_TOKEN" \
name: docker-images-${{ steps.version.outputs.version }} "$GITEA_URL/api/v1/repos/$REPO_OWNER/$REPO_NAME/releases/tags/$TAG" 2>/dev/null || echo "{}")
path: /tmp/nerd-monitor-*.tar
retention-days: 30 RELEASE_ID=$(echo "$RELEASE_JSON" | jq -r '.id // empty' 2>/dev/null)
if [ -z "$RELEASE_ID" ]; then
echo "Release not found, skipping Docker image upload"
else
echo "Uploading Docker images to release $RELEASE_ID..."
for file in /tmp/docker-images/*; do
if [ -f "$file" ]; then
filename=$(basename "$file")
echo " Uploading: $filename"
curl -s -X POST \
-H "Authorization: token $GITEA_TOKEN" \
-F "attachment=@$file" \
"$GITEA_URL/api/v1/repos/$REPO_OWNER/$REPO_NAME/releases/$RELEASE_ID/assets" > /dev/null
if [ $? -eq 0 ]; then
echo " ✓ $filename uploaded"
else
echo " ✗ Failed to upload $filename"
fi
fi
done
fi