- 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
223 lines
8.2 KiB
YAML
223 lines
8.2 KiB
YAML
name: Build and Release
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- master
|
|
tags:
|
|
- 'v*'
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
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
|
|
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
|
|
run: |
|
|
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
|
|
VERSION=${GITHUB_REF#refs/tags/}
|
|
else
|
|
VERSION=dev-${{ github.sha }}
|
|
fi
|
|
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: Create Release and Upload
|
|
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 }}
|
|
|
|
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
|
|
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
|
|
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
|
|
run: |
|
|
docker --version
|
|
which docker
|
|
|
|
- name: Generate version
|
|
id: version
|
|
run: |
|
|
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
|
|
VERSION=${{ github.ref_name }}
|
|
else
|
|
VERSION=dev-${{ github.sha }}
|
|
fi
|
|
echo "version=${VERSION}" >> $GITHUB_ENV
|
|
|
|
- name: Build Docker images
|
|
run: |
|
|
mkdir -p /tmp/docker-images
|
|
|
|
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
|
|
|
|
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
|