Repository navigation
104 lines (90 loc) · 3.8 KB
/
Copy pathversion-bump-on-release.yml
File metadata and controls
104 lines (90 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
name: Version Bump on Release Branch
on:
push:
branches:
- release/**
jobs:
cherry-pick-version-bump:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout main branch
uses: actions/checkout@v6
with:
ref: main
fetch-depth: 0
token: ${{ secrets.RELEASE_PAT }}
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Fetch release branch
run: git fetch origin ${{ github.ref }}
- name: Find version bump commit
id: find-commit
run: |
# Find commits on the release branch that are not on main and modify pyproject.toml
COMMIT_SHA=$(git log origin/${{ github.ref_name }} ^origin/main --format="%H" --grep="version\|bump" -i -- pyproject.toml | head -1)
# If no commit found with grep, try to find any commit that modified pyproject.toml not on main
if [ -z "$COMMIT_SHA" ]; then
COMMIT_SHA=$(git log origin/${{ github.ref_name }} ^origin/main --format="%H" -- pyproject.toml | head -1)
fi
if [ -z "$COMMIT_SHA" ]; then
echo "No version bump commit found on release branch that isn't already on main"
echo "found=false" >> $GITHUB_OUTPUT
else
echo "Version bump commit found: $COMMIT_SHA"
# Get commit message for logging
COMMIT_MSG=$(git log -1 --format="%s" $COMMIT_SHA)
echo "Commit message: $COMMIT_MSG"
echo "sha=$COMMIT_SHA" >> $GITHUB_OUTPUT
echo "message=$COMMIT_MSG" >> $GITHUB_OUTPUT
echo "found=true" >> $GITHUB_OUTPUT
fi
- name: Create cherry-pick branch
if: steps.find-commit.outputs.found == 'true'
id: create-branch
run: |
BRANCH_NAME="version-bump-from-${{ github.ref_name }}"
git checkout -b $BRANCH_NAME
echo "branch=$BRANCH_NAME" >> $GITHUB_OUTPUT
- name: Cherry-pick version bump commit
if: steps.find-commit.outputs.found == 'true'
run: |
git cherry-pick ${{ steps.find-commit.outputs.sha }} || {
# If cherry-pick fails due to conflicts, try to resolve
if git diff --name-only --diff-filter=U | grep -q "pyproject.toml"; then
# Accept the incoming version change
git checkout --theirs pyproject.toml
git add pyproject.toml
git cherry-pick --continue
else
echo "Cherry-pick failed with non-version conflicts"
exit 1
fi
}
- name: Push cherry-pick branch
if: steps.find-commit.outputs.found == 'true'
run: |
git push origin ${{ steps.create-branch.outputs.branch }} --force
- name: Check if PR already exists
if: steps.find-commit.outputs.found == 'true'
id: check-pr
run: |
PR_EXISTS=$(gh pr list --base main --head ${{ steps.create-branch.outputs.branch }} --json number --jq length)
echo "exists=$PR_EXISTS" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_PAT }}
- name: Create pull request into main
if: steps.find-commit.outputs.found == 'true' && steps.check-pr.outputs.exists == '0'
run: |
gh pr create \
--base main \
--head ${{ steps.create-branch.outputs.branch }} \
--title "${{ steps.find-commit.outputs.message }}" \
--body "This PR cherry-picks the version bump commit from \`${{ github.ref_name }}\`.
Cherry-picked commit: ${{ steps.find-commit.outputs.sha }}"
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_PAT }}