fix: CI/CD workflow for Gitea Actions - use proper authentication and fix checkout issues

Updated workflow to:
- Use Gitea token for repository checkout authentication
- Use Gitea repository owner as username for registry login
- Use PACKAGES_TOKEN secret for registry authentication
- Follow proven pattern from working repository
- Only build and push on main/master branches and version tags
- Added proper job dependencies (test → build → docker)
This commit is contained in:
2026-08-05 23:33:27 +03:00
parent 9d24730efa
commit cc04cad6e0
2 changed files with 138 additions and 45 deletions

View File

@@ -1,4 +1,4 @@
name: Build and Push Docker Image
name: CI/CD
on:
push:
@@ -8,70 +8,89 @@ on:
branches: [ main, master ]
env:
# Docker image configuration - using your Gitea registry
GO_VERSION: "1.25"
REGISTRY: gitea.mrixs.me
IMAGE_NAME: naviwatcher
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Cache Go modules
uses: actions/cache@v4
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: go-test-${{ runner.os }}-${{ hashFiles('go.sum') }}
restore-keys: |
go-test-${{ runner.os }}-
- name: Download Go modules
run: go mod download
- name: Run tests
run: go test ./... -v -race -cover
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write # Needed for writing to GitHub Packages registry
needs: test
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: '1.25'
cache: true
go-version: ${{ env.GO_VERSION }}
- name: Verify dependencies
run: |
go mod tidy
go mod verify
- name: Run unit tests
run: go test ./... -v -coverprofile=coverage.out
- name: Upload coverage report
if: always()
uses: actions/upload-artifact@v4
- name: Cache Go modules and build cache
uses: actions/cache@v4
with:
name: coverage-report
path: coverage.out
path: |
~/go/pkg/mod
~/.cache/go-build
key: go-build-${{ runner.os }}-${{ hashFiles('go.sum') }}
restore-keys: |
go-build-${{ runner.os }}-
- name: Download Go modules
run: go mod download
- name: Build binary
run: go build -o naviwatcher ./cmd/naviwatcher
docker:
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Gitea Container Registry
- name: Login to Gitea Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
username: ${{ gitea.repository_owner }}
password: ${{ secrets.PACKAGES_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
- name: Build and push Docker image
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-buildcache
cache-to: type=inline,mode=max
tags: |
${{ env.REGISTRY }}/${{ gitea.repository_owner }}/${{ env.IMAGE_NAME }}:latest
${{ env.REGISTRY }}/${{ gitea.repository_owner }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ gitea.repository_owner }}/${{ env.IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ gitea.repository_owner }}/${{ env.IMAGE_NAME }}:buildcache,mode=max