-
Notifications
You must be signed in to change notification settings - Fork 1
154 lines (136 loc) · 5.13 KB
/
bump-version.yml
File metadata and controls
154 lines (136 loc) · 5.13 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
name: 'Bump version'
on:
workflow_dispatch:
inputs:
bump-type:
type: choice
options:
- 'minor'
- 'major'
description: 'Version bump type. Use ''minor'' to add features (keeps API files), ''major'' for breaking changes (resets API files).'
required: true
permissions:
actions: read
contents: write
pull-requests: write
concurrency:
group: bump-version
cancel-in-progress: false
env:
dotnet-sdk-version: '10.x'
jobs:
detect-version:
name: 'Detect current version and calculate next'
runs-on: ubuntu-latest
outputs:
current-version: ${{ steps.detect.outputs.current-version }}
next-version: ${{ steps.calculate.outputs.next-version }}
target-branch: ${{ steps.calculate.outputs.target-branch }}
steps:
- name: 'Checkout main'
uses: actions/checkout@v6
with:
ref: main
fetch-depth: 0
- name: 'Detect highest release branch'
id: detect
run: |
git fetch origin
latest=$(git ls-remote --heads origin 'release/*' | grep -oP 'release/\K\d+\.\d+' | sort -V | tail -1)
if [[ -z "$latest" ]]; then
latest="0.0"
fi
echo "Detected current version: $latest"
echo "current-version=$latest" >> $GITHUB_OUTPUT
- name: 'Calculate next version'
id: calculate
run: |
current="${{ steps.detect.outputs.current-version }}"
major="${current%%.*}"
minor="${current##*.}"
if [[ "${{ inputs.bump-type }}" == "major" ]]; then
next_major=$((major + 1))
next_version="${next_major}.0"
else
next_minor=$((minor + 1))
next_version="${major}.${next_minor}"
fi
echo "Next version: $next_version"
echo "next-version=$next_version" >> $GITHUB_OUTPUT
echo "target-branch=develop/${next_version}" >> $GITHUB_OUTPUT
validate:
name: 'Validate bump'
needs: [detect-version]
runs-on: ubuntu-latest
steps:
- name: 'Checkout main'
uses: actions/checkout@v6
with:
ref: main
fetch-depth: 1
- name: 'Validate workflow is running from main'
if: ${{ github.ref_name != 'main' }}
run: |
echo "This workflow must be run from the 'main' branch. Current branch: '${{ github.ref_name }}'."
exit 1
- name: 'Validate target branch does not exist'
run: |
set +e
git ls-remote --exit-code --heads origin "${{ needs.detect-version.outputs.target-branch }}"
if [[ $? -eq 0 ]]; then
echo "Target branch '${{ needs.detect-version.outputs.target-branch }}' already exists."
exit 1
fi
set -e
create-branch:
name: 'Create ${{ needs.detect-version.outputs.target-branch }}'
needs: [detect-version, validate]
runs-on: ubuntu-latest
env:
next-version: ${{ needs.detect-version.outputs.next-version }}
target-branch: ${{ needs.detect-version.outputs.target-branch }}
steps:
- name: 'Checkout main'
uses: actions/checkout@v6
with:
ref: main
fetch-depth: 0
- name: 'Setup .NET ${{ env.dotnet-sdk-version }}'
uses: actions/setup-dotnet@v5
with:
dotnet-version: ${{ env.dotnet-sdk-version }}
- name: 'Configure git'
uses: './.github/actions/git/configure-identity'
- name: 'Create develop branch from main'
run: |
git checkout -b ${{ env.target-branch }}
- name: 'Reset PublicAPI files for major bump'
if: ${{ inputs.bump-type == 'major' }}
run: |
find . \( -name "PublicAPI.Shipped.txt" -o -name "PublicAPI.Unshipped.txt" \) | while read file; do
printf '\xef\xbb\xbf#nullable enable\n' > "$file"
echo "Reset: $file"
done
- name: 'Commit API file reset'
if: ${{ inputs.bump-type == 'major' }}
run: |
git add .
git diff --staged --quiet || git commit -m "Reset PublicAPI files for major version ${{ env.next-version }}"
- name: 'Push develop branch'
run: |
git push --set-upstream origin ${{ env.target-branch }}
- name: 'Write summary'
run: |
echo "## ✅ Branch created: \`${{ env.target-branch }}\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| | |" >> $GITHUB_STEP_SUMMARY
echo "|---|---|" >> $GITHUB_STEP_SUMMARY
echo "| **Bump type** | ${{ inputs.bump-type }} |" >> $GITHUB_STEP_SUMMARY
echo "| **Previous version** | ${{ needs.detect-version.outputs.current-version }} |" >> $GITHUB_STEP_SUMMARY
echo "| **New version** | ${{ env.next-version }} |" >> $GITHUB_STEP_SUMMARY
echo "| **Target branch** | \`${{ env.target-branch }}\` |" >> $GITHUB_STEP_SUMMARY
if [[ "${{ inputs.bump-type }}" == "major" ]]; then
echo "| **API files** | Reset (major bump) |" >> $GITHUB_STEP_SUMMARY
else
echo "| **API files** | Preserved (minor bump) |" >> $GITHUB_STEP_SUMMARY
fi