-
Notifications
You must be signed in to change notification settings - Fork 130
134 lines (119 loc) · 5.19 KB
/
standardlogicapp-autobump.yml
File metadata and controls
134 lines (119 loc) · 5.19 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
name: StandardLogicApp - Auto-bump VERSION on PR
on:
pull_request:
branches: [master]
paths:
- 'Microsoft.SCIM.LogicAppValidationTemplate/StandardLogicApp/**'
permissions:
contents: write
pull-requests: write
concurrency:
group: standardlogicapp-bump-${{ github.head_ref }}
cancel-in-progress: true
jobs:
autobump:
if: ${{ github.event.pull_request.head.repo.fork == false }}
runs-on: ubuntu-latest
steps:
- name: Checkout PR branch
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Loop guard - skip if last commit was an auto-bump
id: guard
run: |
LAST_MSG=$(git log -1 --pretty=%B)
if echo "$LAST_MSG" | grep -q '\[skip-bump\]'; then
echo "skip=true" >> $GITHUB_OUTPUT
echo "Last commit is an auto-bump. Skipping."
else
echo "skip=false" >> $GITHUB_OUTPUT
fi
- name: Determine bump type from PR labels
if: steps.guard.outputs.skip != 'true'
id: bumptype
env:
LABELS: ${{ toJson(github.event.pull_request.labels.*.name) }}
run: |
if echo "$LABELS" | grep -q '"version:skip"'; then
echo "type=skip" >> $GITHUB_OUTPUT
elif echo "$LABELS" | grep -q '"version:major"'; then
echo "type=major" >> $GITHUB_OUTPUT
elif echo "$LABELS" | grep -q '"version:patch"'; then
echo "type=patch" >> $GITHUB_OUTPUT
else
echo "type=minor" >> $GITHUB_OUTPUT
fi
- name: Read current and base VERSION
if: steps.guard.outputs.skip != 'true' && steps.bumptype.outputs.type != 'skip'
id: ver
run: |
FILE="Microsoft.SCIM.LogicAppValidationTemplate/StandardLogicApp/VERSION"
CURRENT=$(tr -d '[:space:]' < "$FILE")
git fetch origin ${{ github.base_ref }} --depth=1
BASE=$(git show origin/${{ github.base_ref }}:"$FILE" 2>/dev/null | tr -d '[:space:]' || echo "")
echo "current=$CURRENT" >> $GITHUB_OUTPUT
echo "base=$BASE" >> $GITHUB_OUTPUT
echo "Current PR VERSION: $CURRENT"
echo "Base VERSION: $BASE"
- name: Bump VERSION if unchanged
if: steps.guard.outputs.skip != 'true' && steps.bumptype.outputs.type != 'skip' && steps.ver.outputs.current == steps.ver.outputs.base
id: bump
run: |
FILE="Microsoft.SCIM.LogicAppValidationTemplate/StandardLogicApp/VERSION"
CUR="${{ steps.ver.outputs.current }}"
TYPE="${{ steps.bumptype.outputs.type }}"
MAJOR=$(echo "$CUR" | cut -d. -f1)
MINOR=$(echo "$CUR" | cut -d. -f2)
PATCH=$(echo "$CUR" | cut -d. -f3)
[ -z "$MINOR" ] && MINOR=0
[ -z "$PATCH" ] && PATCH=0
case "$TYPE" in
major) NEW="$((MAJOR+1)).0" ;;
minor) NEW="${MAJOR}.$((MINOR+1))" ;;
patch) NEW="${MAJOR}.${MINOR}.$((PATCH+1))" ;;
esac
echo "$NEW" > "$FILE"
echo "new=$NEW" >> $GITHUB_OUTPUT
echo "Bumping $CUR -> $NEW ($TYPE)"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add "$FILE"
git commit -m "chore(StandardLogicApp): bump VERSION to $NEW [skip-bump]"
git push
- name: Comment resulting version on PR
if: steps.bump.outputs.new != ''
uses: actions/github-script@v7
with:
script: |
const v = '${{ steps.bump.outputs.new }}';
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `🔖 Auto-bumped \`StandardLogicApp/VERSION\` to **${v}**.\nOn merge to master, tag \`scim-logicapp-template-v${v}\` will be created.\n\nTo override, add one of: \`version:major\`, \`version:patch\`, \`version:skip\` and re-run.`
});
- name: Note when author already bumped
if: steps.guard.outputs.skip != 'true' && steps.bumptype.outputs.type != 'skip' && steps.ver.outputs.current != steps.ver.outputs.base && steps.bump.outputs.new == ''
run: |
echo "✅ VERSION already bumped from ${{ steps.ver.outputs.base }} to ${{ steps.ver.outputs.current }}. No action needed."
fork-pr-check:
if: ${{ github.event.pull_request.head.repo.fork == true }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Require manual VERSION bump for fork PRs
run: |
FILE="Microsoft.SCIM.LogicAppValidationTemplate/StandardLogicApp/VERSION"
git fetch origin ${{ github.base_ref }} --depth=1
CUR=$(tr -d '[:space:]' < "$FILE")
BASE=$(git show origin/${{ github.base_ref }}:"$FILE" 2>/dev/null | tr -d '[:space:]' || echo "")
if [ "$CUR" = "$BASE" ]; then
echo "::error::Fork PRs cannot be auto-bumped. Please bump $FILE manually."
exit 1
fi
echo "✅ VERSION bumped from $BASE to $CUR."