Author SHA1 Message Date
Test 66fca7a181 ci: install Node.js and Docker for actions runtime 2026-09-06 22:36:51 -07:00
Test a48b6fdb54 ci: fix checkout ref for PR builds
CI / test-build-push (pull_request) Successful in 1m53s
2026-09-06 06:14:23 -07:00
Test bc86fb7242 ci: merge test+build+push into single pipeline
CI / test-build-push (pull_request) Failing after 8s
- Single job: vet → test → build binary → build image → push
- Image build/push only on main push (skip on PR)
- Fixed Dockerfile: golang:1.26, build cmd/worker, removed HTTP healthcheck
- Removed separate build-push.yml
2026-09-06 06:12:16 -07:00
+30 -81
View File
@@ -4,113 +4,62 @@ on:
push:
branches: [main]
pull_request:
branches: [main]
env:
GOPRIVATE: forgejo.riotpiao.com
REGISTRY: forgejo.riotpiao.com
IMAGE: forgejo.riotpiao.com/rock/poimen-workflows
jobs:
test:
name: Test
test-build-push:
runs-on: golang
container:
image: golang:1.26
env:
GOPRIVATE: forgejo.riotpiao.com
REGISTRY: forgejo.riotpiao.com
IMAGE: forgejo.riotpiao.com/rock/poimen-workflows
steps:
- name: Install Node.js for actions runtime
run: apt-get update && apt-get install -y nodejs
- name: Install Node.js and Docker for actions runtime
run: apt-get update && apt-get install -y nodejs docker.io
- name: Configure git authentication
run: |
git config --global url."https://oauth2:${{ secrets.REGISTRY_PAT }}@forgejo.riotpiao.com".insteadOf "https://forgejo.riotpiao.com"
git config --global credential.helper store
echo "https://oauth2:${{ secrets.REGISTRY_PAT }}@forgejo.riotpiao.com" >> ~/.git-credentials
- name: Checkout code
uses: actions/checkout@v4
run: |
git init
git remote add origin https://forgejo.riotpiao.com/rock/poimen-workflows.git
git fetch origin ${{ github.head_ref || github.ref_name }} --depth=1
git checkout FETCH_HEAD
- name: Download dependencies
run: go mod download
- name: Go vet
- name: Vet
run: go vet ./...
- name: Go test
- name: Test
run: go test ./...
- name: Build binary
run: CGO_ENABLED=0 GOOS=linux go build -o /tmp/poimen-worker ./cmd/worker
build-push:
name: Build & Push Image
needs: test
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: golang
steps:
- name: Install Node.js and Docker
run: |
apt-get update
apt-get install -y nodejs docker.io
- name: Checkout code
uses: actions/checkout@v4
- name: Get short SHA
id: sha
run: |
SHORT_SHA=$(git rev-parse --short HEAD)
echo "short_sha=${SHORT_SHA}" >> $GITHUB_OUTPUT
- name: Pre-verify Docker, Registry, and Credentials
run: |
echo "=== Docker Daemon Check ==="
if ! docker version &>/dev/null; then
echo "❌ FAILED: Docker daemon not accessible"
exit 1
fi
echo "✓ Docker daemon is running"
docker version --format "Engine: {{.Server.Version}}"
echo ""
echo "=== Registry Credentials Check ==="
if [ -z "${REGISTRY_USER}" ] || [ -z "${REGISTRY_TOKEN}" ]; then
echo "❌ FAILED: FORGEJO_REGISTRY_USER or FORGEJO_REGISTRY_TOKEN not set"
exit 1
fi
echo "✓ Registry credentials are set"
echo ""
echo "=== Registry Login Test ==="
if ! echo "${REGISTRY_TOKEN}" | docker login "${REGISTRY}" --username "${REGISTRY_USER}" --password-stdin &>/dev/null; then
echo "❌ FAILED: Registry login failed - credentials may be invalid"
exit 1
fi
echo "✓ Registry login successful"
docker logout "${REGISTRY}" &>/dev/null || true
echo ""
echo "=== Dockerfile Check ==="
if [ ! -f Dockerfile ]; then
echo "❌ FAILED: Dockerfile not found"
exit 1
fi
echo "✓ Dockerfile exists"
echo ""
echo "=== All pre-checks passed ==="
env:
REGISTRY_USER: ${{ secrets.FORGEJO_REGISTRY_USER }}
REGISTRY_TOKEN: ${{ secrets.FORGEJO_REGISTRY_TOKEN }}
run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Registry login
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
echo "${REGISTRY_TOKEN}" | docker login "${REGISTRY}" \
--username "${REGISTRY_USER}" --password-stdin
env:
REGISTRY_USER: ${{ secrets.FORGEJO_REGISTRY_USER }}
REGISTRY_TOKEN: ${{ secrets.FORGEJO_REGISTRY_TOKEN }}
echo "${{ secrets.FORGEJO_REGISTRY_TOKEN }}" | docker login "${REGISTRY}" \
--username "${{ secrets.FORGEJO_REGISTRY_USER }}" --password-stdin
- name: Build Docker image
- name: Build and push image
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
docker build --no-cache \
docker build \
-t "${IMAGE}:${{ steps.sha.outputs.short_sha }}" \
-t "${IMAGE}:latest" \
.
- name: Push Docker image
run: |
docker push "${IMAGE}:${{ steps.sha.outputs.short_sha }}"
docker push "${IMAGE}:latest"
echo "✓ Image pushed: ${IMAGE}:${{ steps.sha.outputs.short_sha }}"
- name: Prune unused images
run: docker image prune -a --force 2>&1 | tail -3 || true
echo "✓ Pushed ${IMAGE}:${{ steps.sha.outputs.short_sha }}"