Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions .github/labeler.yml

This file was deleted.

5 changes: 0 additions & 5 deletions .github/pr-badge.yml

This file was deleted.

206 changes: 206 additions & 0 deletions .github/workflows/auto-version-bump.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
name: Auto Version Bump

on:
pull_request:
types: [opened, synchronize, labeled]
paths:
- 'pkg/**'
- 'cmd/**'
- 'build/**'
- 'config/**'
- 'deploy/**'

permissions:
contents: write
pull-requests: read

jobs:
auto-bump:
runs-on: ubuntu-latest
steps:
- name: Determine bump type from label
id: label
run: |
LABELS='${{ toJSON(github.event.pull_request.labels.*.name) }}'
if echo "$LABELS" | jq -e 'map(select(. == "bump:major")) | length > 0' > /dev/null; then
echo "type=major" >> "$GITHUB_OUTPUT"
elif echo "$LABELS" | jq -e 'map(select(. == "bump:minor")) | length > 0' > /dev/null; then
echo "type=minor" >> "$GITHUB_OUTPUT"
elif echo "$LABELS" | jq -e 'map(select(. == "bump:patch")) | length > 0' > /dev/null; then
echo "type=patch" >> "$GITHUB_OUTPUT"
else
echo "type=" >> "$GITHUB_OUTPUT"
fi

- name: Checkout PR branch
if: steps.label.outputs.type != ''
uses: actions/checkout@v7
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Fetch base branch
if: steps.label.outputs.type != ''
run: git fetch origin ${{ github.event.pull_request.base.ref }}

- name: Configure git
if: steps.label.outputs.type != ''
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

- name: Resolve version conflict with base
if: steps.label.outputs.type != ''
id: conflict
run: |
BASE_REF="origin/${{ github.event.pull_request.base.ref }}"
VERSION_FILE="pkg/version/version.txt"

# Check if version file has a merge conflict with base
if git merge --no-commit --no-ff "$BASE_REF" 2>/dev/null; then
git merge --abort 2>/dev/null || true
echo "resolved=false" >> "$GITHUB_OUTPUT"
else
CONFLICTED=$(git diff --name-only --diff-filter=U 2>/dev/null || true)
git merge --abort 2>/dev/null || true

# Check if conflicts are only in the version file
VERSION_ONLY=true
for f in $CONFLICTED; do
if [ "$f" != "$VERSION_FILE" ]; then
VERSION_ONLY=false
break
fi
done

if [ "$VERSION_ONLY" = "true" ]; then
echo "🔀 Version file conflict detected — will auto-resolve from base"
echo "resolved=true" >> "$GITHUB_OUTPUT"
else
echo "resolved=false" >> "$GITHUB_OUTPUT"
fi
fi

- name: Merge base into PR (resolve version conflict)
if: steps.label.outputs.type != '' && steps.conflict.outputs.resolved == 'true'
run: |
BASE_REF="origin/${{ github.event.pull_request.base.ref }}"
VERSION_FILE="pkg/version/version.txt"

# Start the merge, accept conflicts
git merge "$BASE_REF" --no-edit || true

# Resolve version file by taking theirs (will be overwritten by bump step)
git checkout --theirs "$VERSION_FILE" 2>/dev/null || true
git add "$VERSION_FILE"

# If there are other conflicts, abort
OTHER_CONFLICTS=$(git diff --name-only --diff-filter=U 2>/dev/null || true)
if [ -n "$OTHER_CONFLICTS" ]; then
echo "::error::Merge has conflicts beyond version file, cannot auto-resolve"
git merge --abort
exit 1
fi

git commit --no-edit

- name: Bump version
if: steps.label.outputs.type != ''
id: bump
run: |
BUMP_TYPE="${{ steps.label.outputs.type }}"
BASE_REF="origin/${{ github.event.pull_request.base.ref }}"
VERSION_FILE="pkg/version/version.txt"

CHANGED_FILES=$(git diff --name-only "$BASE_REF" HEAD)

# Check if code in monitored directories changed (excluding version file)
CODE_CHANGED=$(echo "$CHANGED_FILES" | grep -E '^(pkg|cmd|build|config|deploy)/' | grep -v "^${VERSION_FILE}$" || true)
if [ -z "$CODE_CHANGED" ]; then
echo "No code changes detected, skipping bump"
echo "bumped=false" >> "$GITHUB_OUTPUT"
exit 0
fi

# Read current versions
BASE_VER=$(git show "$BASE_REF:$VERSION_FILE" 2>/dev/null | tr -d '[:space:]' || echo "1.22.0-0")
PR_VER=$(cat "$VERSION_FILE" | tr -d '[:space:]')

# Parse subversioned format: X.Y.Z-N
# Base version
BASE_SEMVER=$(echo "$BASE_VER" | grep -oE '^[0-9]+\.[0-9]+\.[0-9]+')
BASE_SUB=$(echo "$BASE_VER" | grep -oE '\-[0-9]+$' | tr -d '-' || echo "0")
if [ -z "$BASE_SUB" ]; then BASE_SUB=0; fi

# PR version
PR_SEMVER=$(echo "$PR_VER" | grep -oE '^[0-9]+\.[0-9]+\.[0-9]+')
PR_SUB=$(echo "$PR_VER" | grep -oE '\-[0-9]+$' | tr -d '-' || echo "0")
if [ -z "$PR_SUB" ]; then PR_SUB=0; fi

# Compare: if PR version is already higher than base, skip (manual bump)
IFS='.' read -r b1 b2 b3 <<< "$BASE_SEMVER"
IFS='.' read -r p1 p2 p3 <<< "$PR_SEMVER"

ALREADY_BUMPED=false
if [ "$p1" -gt "$b1" ] 2>/dev/null; then
ALREADY_BUMPED=true
elif [ "$p1" -eq "$b1" ] && [ "$p2" -gt "$b2" ] 2>/dev/null; then
ALREADY_BUMPED=true
elif [ "$p1" -eq "$b1" ] && [ "$p2" -eq "$b2" ] && [ "$p3" -gt "$b3" ] 2>/dev/null; then
ALREADY_BUMPED=true
elif [ "$p1" -eq "$b1" ] && [ "$p2" -eq "$b2" ] && [ "$p3" -eq "$b3" ] && [ "$PR_SUB" -gt "$BASE_SUB" ] 2>/dev/null; then
ALREADY_BUMPED=true
fi

if [ "$ALREADY_BUMPED" = "true" ]; then
echo "✅ Version already bumped ($BASE_VER → $PR_VER), skipping"
echo "bumped=false" >> "$GITHUB_OUTPUT"
exit 0
fi

# Bump based on type
# For this repo: bump:patch increments the -N subversion suffix
# bump:minor and bump:major bump the semver portion (for upstream rebases)
IFS='.' read -r major minor patch <<< "$BASE_SEMVER"
case "$BUMP_TYPE" in
major)
major=$((major + 1)); minor=0; patch=0
NEW_VER="${major}.${minor}.${patch}-1"
;;
minor)
minor=$((minor + 1)); patch=0
NEW_VER="${major}.${minor}.${patch}-1"
;;
patch)
NEW_SUB=$((BASE_SUB + 1))
NEW_VER="${BASE_SEMVER}-${NEW_SUB}"
;;
esac

echo "🔄 Version: $BASE_VER → $NEW_VER ($BUMP_TYPE)"

# Write version file
printf '%s\n' "$NEW_VER" > "$VERSION_FILE"

echo "bumped=true" >> "$GITHUB_OUTPUT"

- name: Ensure trailing newline
if: steps.label.outputs.type != ''
run: |
VERSION_FILE="pkg/version/version.txt"
if [ -n "$(tail -c 1 "$VERSION_FILE")" ]; then
echo "" >> "$VERSION_FILE"
echo "Fixed missing trailing newline in $VERSION_FILE"
fi

- name: Commit and push
if: steps.label.outputs.type != ''
run: |
if git diff --quiet; then
echo "No changes to commit"
else
git add -A
git commit -m "chore: auto-bump version (${{ steps.label.outputs.type }})"
git push
fi
58 changes: 58 additions & 0 deletions .github/workflows/label-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Version Bump Label Check

on:
pull_request:
types: [opened, synchronize, reopened, labeled, unlabeled]

permissions:
contents: read
pull-requests: read

jobs:
check-label:
runs-on: ubuntu-latest
steps:
- name: Check for code changes
id: changes
uses: dorny/paths-filter@v4
with:
filters: |
code:
- 'pkg/**'
- 'cmd/**'
- 'build/**'
- 'config/**'
- 'deploy/**'

- name: Check for bump label
if: steps.changes.outputs.code == 'true'
env:
GH_TOKEN: ${{ github.token }}
run: |
LABELS=$(gh api repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels --jq '[.[].name]')
echo "Labels found: $LABELS"
SKIP=$(echo "$LABELS" | jq 'map(select(. == "skip-release")) | length')

if [ "$SKIP" -gt 0 ]; then
echo "✅ skip-release label found, no version bump required"
exit 0
fi

PATCH=$(echo "$LABELS" | jq 'map(select(. == "bump:patch")) | length')
MINOR=$(echo "$LABELS" | jq 'map(select(. == "bump:minor")) | length')
MAJOR=$(echo "$LABELS" | jq 'map(select(. == "bump:major")) | length')
COUNT=$((PATCH + MINOR + MAJOR))

if [ "$COUNT" -eq 0 ]; then
echo "::error::PR must have exactly one bump label (bump:patch, bump:minor, or bump:major) or skip-release"
exit 1
elif [ "$COUNT" -gt 1 ]; then
echo "::error::PR has multiple bump labels. Use exactly one of: bump:patch, bump:minor, bump:major"
exit 1
fi

echo "✅ Bump label found"

- name: Skip label check
if: steps.changes.outputs.code == 'false'
run: echo "✅ No code changes detected, skipping label check"
28 changes: 0 additions & 28 deletions .github/workflows/labeler.yml

This file was deleted.

21 changes: 0 additions & 21 deletions .github/workflows/renovate.yaml

This file was deleted.

10 changes: 2 additions & 8 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
with:
go-version: '^1.25'
- run: go install -v github.com/incu6us/goimports-reviser/v3@latest
- run: $(go env GOPATH)/bin/goimports-reviser -imports-order "std,general,company,project" -company-prefixes "github.com/percona" ./...
- run: $(go env GOPATH)/bin/goimports-reviser -imports-order "std,general,company,project" -company-prefixes "github.com/objectrocket,github.com/percona" ./...
- uses: reviewdog/action-suggester@v1.24.0
with:
tool_name: goimports-reviser
Expand Down Expand Up @@ -93,13 +93,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: check on release branch
if: ${{ contains(github.head_ref, 'release-') || contains(github.base_ref, 'release-') }}
run: |
make generate manifests VERSION="$(grep -Eo "[0-9]+\.[0-9]+\.[0-9]+" pkg/version/version.txt)" IMAGE_TAG_BASE="percona/percona-server-mongodb-operator"
git diff --exit-code
- name: check on non release branches
if: ${{ ! (contains(github.head_ref, 'release-') || contains(github.base_ref, 'release-')) }}
- name: check manifests are up to date
run: |
make generate manifests VERSION=main
git diff --exit-code
Loading
Loading