loic-go/.forgejo/workflows/pipeline.yml

93 lines
2.7 KiB
YAML
Raw Permalink Normal View History

name: ci
on: push
2025-03-28 11:04:34 +00:00
jobs:
build:
runs-on: ubuntu-22.04
steps:
2025-04-29 15:43:49 +00:00
- name: Checkout Code
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.24'
cache: true
cache-dependency-path: go.sum
- name: Validate Go Modules
run: |
go mod tidy
git diff --exit-code go.sum || echo "go.sum was updated; please commit changes"
go mod download
- name: Run Unit Tests
run: go test ./... -v
2025-04-29 07:40:59 +00:00
- name: Repository meta
id: repository
run: |
registry=${{ github.server_url }}
registry=${registry##http*://}
echo "registry=${registry}" >> "$GITHUB_OUTPUT"
echo "registry=${registry}"
repository="$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')"
echo "repository=${repository}" >> "$GITHUB_OUTPUT"
2025-04-29 07:40:59 +00:00
echo "repository=${repository}"
- name: Docker meta
uses: docker/metadata-action@v5
id: docker
with:
images: ${{ steps.repository.outputs.registry }}/${{ steps.repository.outputs.repository }}
2025-04-29 07:40:59 +00:00
tags: |
# Für push-Events: Tag 'latest'
type=raw,value=latest,enable=${{ github.event_name == 'push' }}
# Für tag-Events: Nutze den Git-Tag (z. B. v1.0.0)
type=ref,event=tag
# Optional: Commit-SHA für alle Events
type=sha,prefix=sha-
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
2025-04-29 07:40:59 +00:00
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: '--allow-insecure-entitlement network.host'
driver-opts: network=host
2025-04-29 07:40:59 +00:00
2025-04-29 08:40:37 +00:00
- name: Build Docker Image
uses: docker/build-push-action@v6
2025-04-29 08:40:37 +00:00
id: build
with:
2025-04-29 08:40:37 +00:00
context: .
push: false
allow: network.host
network: host
platforms: linux/amd64,linux/arm64
tags: ${{ steps.docker.outputs.tags }}
2025-04-29 08:40:37 +00:00
outputs: type=docker
no-cache: false
2025-04-29 08:40:37 +00:00
- name: Run Tests in Docker Image
run: |
docker run --rm \
-v $(pwd):/app \
-w /app \
${{ steps.docker.outputs.tags | split('\n') | first }} \
go test ./... -v
2025-04-29 08:40:37 +00:00
- name: Login to registry
uses: docker/login-action@v3
with:
registry: ${{ steps.repository.outputs.registry }}
username: ${{ secrets.PACKAGES_USER }}
password: ${{ secrets.PACKAGES_TOKEN }}
- name: Push Docker Image
run: |
docker push ${{ steps.docker.outputs.tags | split('\n') | first }}