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:
push:
branches:
- main
- master
tags:
- 'v*'
@@ -12,12 +13,19 @@ jobs:
runs-on: ubuntu-latest
steps:
- 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
uses: actions/setup-go@v4
with:
go-version: '1.24.4'
run: |
wget https://go.dev/dl/go1.24.4.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.24.4.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
go version
- name: Generate version
id: version
@@ -27,114 +35,188 @@ jobs:
else
VERSION=dev-${{ github.sha }}
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "version=${VERSION}" >> $GITHUB_ENV
- name: Build all binaries
run: |
export PATH=$PATH:/usr/local/go/bin
mkdir -p bin
# Generate templ first
go run github.com/a-h/templ/cmd/templ@latest generate
# 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-agent-linux-amd64 ./cmd/agent
# 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-agent-linux-arm64 ./cmd/agent
# 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-agent-darwin-amd64 ./cmd/agent
# 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-agent-darwin-arm64 ./cmd/agent
# 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-agent-windows-amd64.exe ./cmd/agent
echo "Build complete! Files:"
ls -lh bin/
- name: Create checksums
run: |
cd bin
sha256sum * > SHA256SUMS
cd ..
echo "Checksums:"
cat bin/SHA256SUMS
- name: Upload artifacts
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
- name: Create Release and Upload
if: startsWith(github.ref, 'refs/tags/')
run: |
# This step uploads binaries to the release
# Note: Gitea Actions may require additional configuration
export GITEA_TOKEN="${{ secrets.GITEA_TOKEN }}"
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
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
done
echo ""
echo "Release completed!"
echo "View at: $GITEA_URL/$REPO_OWNER/$REPO_NAME/releases/tag/$TAG"
docker-build:
runs-on: ubuntu-latest
steps:
- 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
uses: docker/setup-buildx-action@v3
- name: Set up Docker
run: |
docker --version
which docker
- name: Generate version
id: version
run: |
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
VERSION=${{ github.ref_name }}
else
VERSION=dev-${{ github.sha }}
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "version=${VERSION}" >> $GITHUB_ENV
- name: Build and push server image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.server
push: false
outputs: type=docker,dest=/tmp/nerd-monitor-server.tar
tags: |
nerd-monitor-server:latest
nerd-monitor-server:${{ steps.version.outputs.version }}
- name: Build Docker images
run: |
mkdir -p /tmp/docker-images
- name: Build and push agent image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.agent
push: false
outputs: type=docker,dest=/tmp/nerd-monitor-agent.tar
tags: |
nerd-monitor-agent:latest
nerd-monitor-agent:${{ steps.version.outputs.version }}
echo "Building server image..."
docker build -t nerd-monitor-server:${{ env.version }} -f Dockerfile.server .
docker save nerd-monitor-server:${{ env.version }} -o /tmp/docker-images/nerd-monitor-server-${{ env.version }}.tar
- name: Upload Docker images
uses: actions/upload-artifact@v4
with:
name: docker-images-${{ steps.version.outputs.version }}
path: /tmp/nerd-monitor-*.tar
retention-days: 30
echo "Building agent image..."
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: Upload Docker images to release
if: startsWith(github.ref, 'refs/tags/')
run: |
export GITEA_TOKEN="${{ secrets.GITEA_TOKEN }}"
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 }}
# Get existing 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 "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