All checks were successful
CI / build-test (push) Successful in 1m2s
- Add `jq` dependency for JSON manipulation - Automatically generate changelog from Git history for releases - Refactor release body to include Docker image details and formatted changelog Changelog: other
131 lines
4.7 KiB
YAML
131 lines
4.7 KiB
YAML
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 jq
|
|
|
|
- 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]+$' || true; } | 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}" >> "${GITHUB_ENV:-$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: |
|
|
REGISTRY="${{ gitea.server_url }}"
|
|
REGISTRY="${REGISTRY#https://}"
|
|
REGISTRY="${REGISTRY#http://}"
|
|
IMAGE="$REGISTRY/$(echo '${{ gitea.repository }}' | tr '[:upper:]' '[:lower:]')"
|
|
|
|
PREV_TAG=$(git tag --sort=-version:refname | { grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' || true; } | sed -n '2p')
|
|
if [ -n "$PREV_TAG" ]; then
|
|
CHANGELOG=$(git log --pretty=format:"- %s" "${PREV_TAG}..HEAD")
|
|
else
|
|
CHANGELOG=$(git log --pretty=format:"- %s")
|
|
fi
|
|
|
|
BODY=$(printf '## Docker Image\n```\ndocker pull %s:%s\n```\n\n## Changelog\n%s' "$IMAGE" "$NEW_VERSION" "$CHANGELOG")
|
|
|
|
jq -n --arg tag "$NEW_VERSION" --arg name "$NEW_VERSION" --arg body "$BODY" \
|
|
'{tag_name: $tag, name: $name, body: $body}' > /tmp/release.json
|
|
|
|
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 @/tmp/release.json
|