From 0c456d9c7819a58b83ce64ac40dc6350724c1044 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Wed, 25 Feb 2026 21:12:40 +0100 Subject: [PATCH] **feat(ci):** introduce release workflow with version bump, Docker image build, and Gitea release automation --- .gitea/workflows/ci.yml | 31 ---------- .gitea/workflows/release.yml | 113 +++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 31 deletions(-) create mode 100644 .gitea/workflows/release.yml diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 54f0f60..fe1cdf8 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -38,34 +38,3 @@ jobs: - name: Build binary run: go build ./... - docker: - runs-on: dind - needs: build-test - if: gitea.event_name == 'push' - env: - DOCKER_HOST: tcp://dind:2375 - steps: - - name: Install dependencies - run: apk add --no-cache git - - name: Checkout - run: | - GITEA_HOST="${{ gitea.server_url }}" - GITEA_HOST="${GITEA_HOST#https://}" - GITEA_HOST="${GITEA_HOST#http://}" - git clone "https://oauth2:${{ secrets.GITEA_TOKEN }}@${GITEA_HOST}/${{ gitea.repository }}.git" . - git checkout ${{ gitea.sha }} - - name: Log in to Gitea registry - run: | - REGISTRY="${{ gitea.server_url }}" - REGISTRY="${REGISTRY#https://}" - REGISTRY="${REGISTRY#http://}" - echo "${{ secrets.REGISTRY_TOKEN }}" | docker login "$REGISTRY" -u "${{ gitea.actor }}" --password-stdin - - name: Build and push - run: | - REGISTRY="${{ gitea.server_url }}" - REGISTRY="${REGISTRY#https://}" - REGISTRY="${REGISTRY#http://}" - IMAGE="$REGISTRY/$(echo '${{ gitea.repository }}' | tr '[:upper:]' '[:lower:]')" - docker build -t "$IMAGE:${{ gitea.sha }}" -t "$IMAGE:latest" . - docker push "$IMAGE:${{ gitea.sha }}" - docker push "$IMAGE:latest" diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml new file mode 100644 index 0000000..cad31cf --- /dev/null +++ b/.gitea/workflows/release.yml @@ -0,0 +1,113 @@ +name: Release +on: + workflow_dispatch: + inputs: + bump: + description: 'Version bump type' + required: true + default: patch + type: choice + options: [patch, minor, major] + +jobs: + build-test: + runs-on: docker + container: + image: gitea.jeanlucmakiola.de/makiolaj/docker-node-and-go:064281efa4401d6f440edd18dc467929b89d7f71 + env: + GOTOOLCHAIN: local + steps: + - name: Checkout code + uses: actions/checkout@v6 + - name: Check formatting + run: | + unformatted=$(gofmt -l .) + if [ -n "$unformatted" ]; then + echo "Unformatted files:" + echo "$unformatted" + exit 1 + fi + + - name: Run go vet + run: go vet ./... + + - name: Run tests with coverage + run: | + go test -v -coverprofile=coverage.out -coverpkg=./... ./... + go tool cover -func=coverage.out | tee coverage.txt + cov=$(go tool cover -func=coverage.out | grep total: | awk '{print substr($3, 1, length($3)-1)}') + cov=${cov%.*} + if [ "$cov" -lt 80 ]; then + echo "::warning::Test coverage is below 80% ($cov%)" + fi + - name: Build binary + run: go build ./... + + release: + runs-on: dind + needs: build-test + env: + DOCKER_HOST: tcp://dind:2375 + steps: + - name: Install dependencies + run: apk add --no-cache git curl + + - name: Checkout with full history + run: | + GITEA_HOST="${{ gitea.server_url }}" + GITEA_HOST="${GITEA_HOST#https://}" + GITEA_HOST="${GITEA_HOST#http://}" + git clone "https://oauth2:${{ secrets.GITEA_TOKEN }}@${GITEA_HOST}/${{ gitea.repository }}.git" . + git fetch --tags + + - name: Compute new version + run: | + LATEST=$(git tag --sort=-version:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -1) + LATEST=${LATEST:-v0.0.0} + VERSION="${LATEST#v}" + MAJOR=$(echo "$VERSION" | cut -d. -f1) + MINOR=$(echo "$VERSION" | cut -d. -f2) + PATCH=$(echo "$VERSION" | cut -d. -f3) + case "${{ gitea.event.inputs.bump }}" in + major) MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;; + minor) MINOR=$((MINOR + 1)); PATCH=0 ;; + patch) PATCH=$((PATCH + 1)) ;; + esac + NEW_VERSION="v${MAJOR}.${MINOR}.${PATCH}" + echo "NEW_VERSION=${NEW_VERSION}" >> $GITEA_ENV + echo "Bumping ${LATEST} → ${NEW_VERSION}" + + - name: Create and push tag + run: | + git config user.name "ci-bot" + git config user.email "ci@noreply.local" + git tag "$NEW_VERSION" + GITEA_HOST="${{ gitea.server_url }}" + GITEA_HOST="${GITEA_HOST#https://}" + GITEA_HOST="${GITEA_HOST#http://}" + git push "https://oauth2:${{ secrets.GITEA_TOKEN }}@${GITEA_HOST}/${{ gitea.repository }}.git" "$NEW_VERSION" + + - name: Log in to Gitea registry + run: | + REGISTRY="${{ gitea.server_url }}" + REGISTRY="${REGISTRY#https://}" + REGISTRY="${REGISTRY#http://}" + echo "${{ secrets.REGISTRY_TOKEN }}" | docker login "$REGISTRY" -u "${{ gitea.actor }}" --password-stdin + + - name: Build and push Docker image + run: | + REGISTRY="${{ gitea.server_url }}" + REGISTRY="${REGISTRY#https://}" + REGISTRY="${REGISTRY#http://}" + IMAGE="$REGISTRY/$(echo '${{ gitea.repository }}' | tr '[:upper:]' '[:lower:]')" + docker build -t "$IMAGE:$NEW_VERSION" -t "$IMAGE:latest" . + docker push "$IMAGE:$NEW_VERSION" + docker push "$IMAGE:latest" + + - name: Create Gitea release + run: | + curl -s -X POST \ + -H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \ + -H "Content-Type: application/json" \ + "${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}/releases" \ + -d "{\"tag_name\": \"$NEW_VERSION\", \"name\": \"$NEW_VERSION\", \"generate_release_notes\": true}"