Files
trip-planner/.gitea/workflows/deploy.yml
Vladimir Zagainov 6396f4e6ab
Some checks failed
CI / lint (push) Successful in 14s
CI / test (push) Failing after 1m48s
CI / build (push) Has been skipped
CI / docker (push) Has been skipped
fix(ci): add Redis service to test and build jobs to resolve connection refused errors
2026-08-20 17:40:37 +03:00

184 lines
4.5 KiB
YAML

name: CI
# Required repo secret: PACKAGES_TOKEN
# Generate at: Gitea → User Settings → Applications → Generate New Token
# Scopes: read:package, write:package
# Save as: Repository → Settings → Actions → Secrets → PACKAGES_TOKEN
# Note: GITHUB_TOKEN is read-only for packages in Gitea (issue #23642).
on:
push:
branches: ["**"]
pull_request:
branches: ["master"]
env:
GO_VERSION: "1.26.4"
jobs:
lint:
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-lint-${{ runner.os }}-${{ hashFiles('go.sum') }}
restore-keys: |
go-lint-${{ runner.os }}-
- name: Download Go modules
run: go mod download
- name: go vet
run: go vet ./...
- name: gofmt check
run: |
fmt=$(gofmt -l .)
if [ -n "$fmt" ]; then
echo "Files needing formatting:"
echo "$fmt"
exit 1
fi
test:
runs-on: ubuntu-latest
services:
redis:
image: redis:7-alpine
ports:
- 6379:6379
# Set health checks to wait until redis is ready
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
needs: lint
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Cache Go modules and build cache
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: Set up Redis
run: |
# Wait for Redis to be ready
for i in {1..30}; do
if redis-cli ping | grep -q PONG; then
echo "Redis is ready"
break
fi
echo "Waiting for Redis..."
sleep 1
done
- name: Run tests
env:
REDIS_ADDR: localhost:6379
run: go test ./... -v -race -cover
build:
runs-on: ubuntu-latest
services:
redis:
image: redis:7-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
needs: test
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Cache Go modules and build cache
uses: actions/cache@v4
with:
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: Set up Redis
run: |
# Wait for Redis to be ready
for i in {1..30}; do
if redis-cli ping | grep -q PONG; then
echo "Redis is ready"
break
fi
echo "Waiting for Redis..."
sleep 1
done
- name: Build binary
env:
REDIS_ADDR: localhost:6379
run: go build -o api ./cmd/api
docker:
runs-on: ubuntu-latest
needs: build
if: github.ref_name == 'master'
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 Registry
uses: docker/login-action@v3
with:
registry: gitea.mrixs.me
username: ${{ gitea.repository_owner }}
password: ${{ secrets.PACKAGES_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
gitea.mrixs.me/mrixs/trip-planner:latest
gitea.mrixs.me/mrixs/trip-planner:${{ github.sha }}
cache-from: type=registry,ref=gitea.mrixs.me/mrixs/trip-planner:buildcache
cache-to: type=registry,ref=gitea.mrixs.me/mrixs/trip-planner:buildcache,mode=max