ci: simplify workflow structure
Some checks failed
CI/CD / Test (push) Has been cancelled
CI/CD / Lint (push) Has been cancelled
CI/CD / Build (monitor, amd64, darwin) (push) Has been cancelled
CI/CD / Build (monitor, amd64, linux) (push) Has been cancelled
CI/CD / Build (monitor, arm64, darwin) (push) Has been cancelled
CI/CD / Build (monitor, arm64, linux) (push) Has been cancelled
CI/CD / Build (server, amd64, darwin) (push) Has been cancelled
CI/CD / Build (server, amd64, linux) (push) Has been cancelled
CI/CD / Build (server, arm64, darwin) (push) Has been cancelled
CI/CD / Build (server, arm64, linux) (push) Has been cancelled
CI/CD / Docker (push) Has been cancelled

This commit is contained in:
2025-12-11 20:18:36 +01:00
parent a310a5cba9
commit 1dff4df2d6

View File

@@ -1,4 +1,3 @@
# CI/CD Pipeline for hmac-file-server
name: CI/CD name: CI/CD
on: on:
@@ -8,9 +7,6 @@ on:
pull_request: pull_request:
branches: [main, master] branches: [main, master]
env:
GITEA_URL: https://git.uuxo.net
jobs: jobs:
test: test:
name: Test name: Test
@@ -24,20 +20,13 @@ jobs:
- name: Checkout code - name: Checkout code
run: | run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE" git config --global --add safe.directory "$GITHUB_WORKSPACE"
git clone --depth 1 --branch ${GITHUB_REF_NAME} ${{ env.GITEA_URL }}/${GITHUB_REPOSITORY}.git . git clone --depth 1 --branch ${GITHUB_REF_NAME} https://git.uuxo.net/${GITHUB_REPOSITORY}.git .
- name: Download dependencies - name: Download dependencies
run: go mod download run: go mod download
- name: Run tests with race detection - name: Run tests
env: run: GOMAXPROCS=8 go test -race -coverprofile=coverage.out -covermode=atomic ./...
GOMAXPROCS: 8
run: go test -race -coverprofile=coverage.out -covermode=atomic ./...
- name: Generate coverage report
run: |
go tool cover -func=coverage.out
go tool cover -html=coverage.out -o coverage.html
lint: lint:
name: Lint name: Lint
@@ -51,7 +40,7 @@ jobs:
- name: Checkout code - name: Checkout code
run: | run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE" git config --global --add safe.directory "$GITHUB_WORKSPACE"
git clone --depth 1 --branch ${GITHUB_REF_NAME} ${{ env.GITEA_URL }}/${GITHUB_REPOSITORY}.git . git clone --depth 1 --branch ${GITHUB_REF_NAME} https://git.uuxo.net/${GITHUB_REPOSITORY}.git .
- name: Run go vet - name: Run go vet
run: go vet ./... run: go vet ./...
@@ -59,13 +48,13 @@ jobs:
- name: Check formatting - name: Check formatting
run: | run: |
if [ -n "$(gofmt -l .)" ]; then if [ -n "$(gofmt -l .)" ]; then
echo "The following files are not formatted:" echo "Files not formatted:"
gofmt -l . gofmt -l .
exit 1 exit 1
fi fi
build: build:
name: Build ${{ matrix.binary }}-${{ matrix.goos }}-${{ matrix.goarch }} name: Build
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [test, lint] needs: [test, lint]
container: container:
@@ -83,44 +72,20 @@ jobs:
- name: Checkout code - name: Checkout code
run: | run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE" git config --global --add safe.directory "$GITHUB_WORKSPACE"
git clone --depth 1 --branch ${GITHUB_REF_NAME} ${{ env.GITEA_URL }}/${GITHUB_REPOSITORY}.git . git clone --depth 1 --branch ${GITHUB_REF_NAME} https://git.uuxo.net/${GITHUB_REPOSITORY}.git .
- name: Build binary - name: Build binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
GOMAXPROCS: 8
run: | run: |
go build -ldflags="-s -w -X main.Version=${GITHUB_REF_NAME}" \ export GOOS=${{ matrix.goos }}
export GOARCH=${{ matrix.goarch }}
export CGO_ENABLED=0
export GOMAXPROCS=8
go build -ldflags="-s -w" \
-o dist/hmac-file-${{ matrix.binary }}-${{ matrix.goos }}-${{ matrix.goarch }} \ -o dist/hmac-file-${{ matrix.binary }}-${{ matrix.goos }}-${{ matrix.goarch }} \
./cmd/${{ matrix.binary }} ./cmd/${{ matrix.binary }}
sbom:
name: Generate SBOM
runs-on: ubuntu-latest
needs: [test]
container:
image: golang:1.24-bookworm
steps:
- name: Install git
run: apt-get update && apt-get install -y git ca-certificates curl
- name: Checkout code
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
git clone --depth 1 --branch ${GITHUB_REF_NAME} ${{ env.GITEA_URL }}/${GITHUB_REPOSITORY}.git .
- name: Install Syft
run: curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
- name: Generate SBOM
run: |
syft . -o spdx-json=sbom-spdx.json
syft . -o cyclonedx-json=sbom-cyclonedx.json
docker: docker:
name: Build & Push Docker Image name: Docker
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [test, lint] needs: [test, lint]
container: container:
@@ -133,54 +98,23 @@ jobs:
- name: Checkout code - name: Checkout code
run: | run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE" git config --global --add safe.directory "$GITHUB_WORKSPACE"
git clone --depth 1 --branch ${GITHUB_REF_NAME} ${{ env.GITEA_URL }}/${GITHUB_REPOSITORY}.git . git clone --depth 1 --branch ${GITHUB_REF_NAME} https://git.uuxo.net/${GITHUB_REPOSITORY}.git .
- name: Set up Docker Buildx - name: Setup buildx
run: | run: |
docker buildx create --use --name builder --driver docker-container || true docker buildx create --use --name builder --driver docker-container || true
docker buildx inspect --bootstrap docker buildx inspect --bootstrap
- name: Login to Gitea Registry - name: Login to registry
run: | run: |
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login git.uuxo.net -u "${{ secrets.REGISTRY_USER }}" --password-stdin echo "${{ secrets.REGISTRY_TOKEN }}" | docker login git.uuxo.net -u "${{ secrets.REGISTRY_USER }}" --password-stdin
- name: Build and push - name: Build and push
run: | run: |
# Determine tags
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/} VERSION=${GITHUB_REF#refs/tags/}
TAGS="-t git.uuxo.net/uuxo/hmac-file-server:${VERSION} -t git.uuxo.net/uuxo/hmac-file-server:latest" TAGS="-t git.uuxo.net/uuxo/hmac-file-server:${VERSION} -t git.uuxo.net/uuxo/hmac-file-server:latest"
else else
TAGS="-t git.uuxo.net/uuxo/hmac-file-server:${GITHUB_SHA::8} -t git.uuxo.net/uuxo/hmac-file-server:main" TAGS="-t git.uuxo.net/uuxo/hmac-file-server:${GITHUB_SHA::8} -t git.uuxo.net/uuxo/hmac-file-server:main"
fi fi
docker buildx build --platform linux/amd64,linux/arm64 --push --file Dockerfile.multiarch ${TAGS} .
docker buildx build \
--platform linux/amd64,linux/arm64 \
--push \
--file Dockerfile.multiarch \
${TAGS} \
.
release:
name: Release
runs-on: ubuntu-latest
needs: [build, sbom, docker]
container:
image: golang:1.24-bookworm
steps:
- name: Install tools
run: |
apt-get update && apt-get install -y git ca-certificates
curl -sSfL https://github.com/goreleaser/goreleaser/releases/download/v2.4.8/goreleaser_Linux_x86_64.tar.gz | tar xz -C /usr/local/bin goreleaser
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
- name: Checkout code
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
git clone --branch ${GITHUB_REF_NAME} ${{ env.GITEA_URL }}/${GITHUB_REPOSITORY}.git .
git fetch --tags
- name: Run goreleaser
env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
run: goreleaser release --clean