Repository navigation
101 lines (87 loc) · 3.18 KB
/
Copy pathmerge-release.yml
File metadata and controls
101 lines (87 loc) · 3.18 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
name: "Merge Release"
on:
workflow_dispatch:
inputs:
branch:
description: 'Release branch to merge (e.g. "release/v1.1.0"). Auto-detected if omitted.'
required: false
type: string
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false
jobs:
merge-release:
runs-on: ubuntu-latest
steps:
- name: Generate GitHub App token
id: app-token
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
with:
app-id: ${{ secrets.RELEASE_BOT_APP_ID }}
private-key: ${{ secrets.RELEASE_BOT_PRIVATE_KEY }}
- name: Configure git identity
run: |
git config --global user.name "aignostics-release-bot[bot]"
git config --global user.email "aignostics-release-bot[bot]@users.noreply.github.com"
- name: Checkout main
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
token: ${{ steps.app-token.outputs.token }}
ref: main
fetch-depth: 0
- name: Resolve release branch
id: branch
env:
INPUT: ${{ inputs.branch }}
run: |
if [ -n "$INPUT" ]; then
BRANCH="$INPUT"
else
MATCHES=$(git ls-remote --heads origin 'release/v*' | awk '{print $2}' | sed 's|refs/heads/||')
if [ -z "$MATCHES" ]; then
echo "❌ No release/v* branches found."
exit 1
fi
COUNT=$(echo "$MATCHES" | wc -l | tr -d ' ')
if [ "$COUNT" -gt 1 ]; then
echo "❌ Multiple release/v* branches found. Specify one explicitly:"
echo "$MATCHES"
exit 1
fi
BRANCH="$MATCHES"
fi
# Validate branch name pattern
if ! echo "$BRANCH" | grep -qE '^release/v[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "❌ Branch '${BRANCH}' does not match 'release/vX.Y.Z'. Aborting."
exit 1
fi
# Validate branch exists on origin
if ! git ls-remote --exit-code --heads origin "$BRANCH" > /dev/null 2>&1; then
echo "❌ Branch '${BRANCH}' does not exist on origin. Aborting."
exit 1
fi
echo "branch=${BRANCH}" >> "$GITHUB_OUTPUT"
echo "✅ Using release branch: ${BRANCH}"
- name: Fetch remote
run: git fetch origin
- name: Merge release branch into main
run: |
BRANCH="${{ steps.branch.outputs.branch }}"
git merge --no-ff "origin/${BRANCH}" -m "chore: merge ${BRANCH} into main"
- name: Push main
run: git push origin main
- name: Delete remote release branch
run: git push origin --delete "${{ steps.branch.outputs.branch }}"
- name: Print job summary
run: |
BRANCH="${{ steps.branch.outputs.branch }}"
cat >> "$GITHUB_STEP_SUMMARY" << EOF
## ✅ Release merged
| | |
|---|---|
| **Branch** | \`${BRANCH}\` |
| **Merged into** | \`main\` |
The release branch has been merged into \`main\` and deleted.
EOF