-
Notifications
You must be signed in to change notification settings - Fork 5
136 lines (116 loc) · 3.99 KB
/
automated-release.yml
File metadata and controls
136 lines (116 loc) · 3.99 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
name: Automated Weekly Release
on:
schedule:
- cron: "0 10 * * 4" # Every Thursday at 10 AM UTC
workflow_dispatch:
permissions:
contents: write
pull-requests: write
checks: write
concurrency:
group: create-release-tag
cancel-in-progress: false
jobs:
check-changes:
name: Check for changes since last release
runs-on: ubuntu-latest
outputs:
has_changes: ${{ steps.check.outputs.has_changes }}
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
ref: main
fetch-depth: 0
token: ${{ secrets.PRO_ACCESS_TOKEN }}
- name: Fetch tags
run: git fetch --tags --force
- name: Check for changes
id: check
run: |
set -euo pipefail
latest_tag="$(git tag --list "v*.*.*" --sort=-v:refname | grep -E "^v[0-9]+\.[0-9]+\.[0-9]+$" | head -n 1 || true)"
if [[ -z "${latest_tag}" ]]; then
echo "No previous tag found, proceeding with release"
echo "has_changes=true" >> "${GITHUB_OUTPUT}"
else
changes="$(git log "${latest_tag}..HEAD" --oneline)"
if [[ -z "${changes}" ]]; then
echo "No changes since ${latest_tag}, skipping release"
echo "has_changes=false" >> "${GITHUB_OUTPUT}"
else
echo "Changes found since ${latest_tag}, proceeding with release"
echo "has_changes=true" >> "${GITHUB_OUTPUT}"
fi
fi
determine-bump:
name: Determine version bump
needs: check-changes
if: needs.check-changes.outputs.has_changes == 'true'
runs-on: ubuntu-latest
outputs:
bump: ${{ steps.bump.outputs.bump }}
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
ref: main
fetch-depth: 0
token: ${{ secrets.PRO_ACCESS_TOKEN }}
- name: Fetch tags
run: git fetch --tags --force
- name: Determine bump type from PR labels
id: bump
env:
GH_TOKEN: ${{ secrets.PRO_ACCESS_TOKEN }}
run: |
set -euo pipefail
latest_tag="$(git tag --list "v*.*.*" --sort=-v:refname | grep -E "^v[0-9]+\.[0-9]+\.[0-9]+$" | head -n 1 || true)"
if [[ -z "${latest_tag}" ]]; then
echo "No previous tag found, defaulting to patch"
echo "bump=patch" >> "${GITHUB_OUTPUT}"
exit 0
fi
# Use git history to find exactly which PRs are part of this release
pr_numbers="$(git log "${latest_tag}..HEAD" --oneline | grep -oE '#[0-9]+' | tr -d '#' | sort -u)"
if [[ -z "${pr_numbers}" ]]; then
echo "No PRs found since ${latest_tag}, defaulting to patch"
echo "bump=patch" >> "${GITHUB_OUTPUT}"
exit 0
fi
bump="patch"
for pr in ${pr_numbers}; do
labels="$(gh pr view "${pr}" --json labels --jq '.labels[].name' 2>/dev/null || true)"
if echo "${labels}" | grep -q "semver: major"; then
bump="major"
break
elif echo "${labels}" | grep -q "semver: minor"; then
bump="minor"
fi
done
echo "Determined bump type: ${bump}"
echo "bump=${bump}" >> "${GITHUB_OUTPUT}"
ci:
name: CI
needs: check-changes
if: needs.check-changes.outputs.has_changes == 'true'
uses: ./.github/workflows/ci.yml
secrets: inherit
create-tag:
name: Create release tag
needs: [check-changes, determine-bump, ci]
if: needs.check-changes.outputs.has_changes == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
ref: main
fetch-depth: 0
token: ${{ secrets.PRO_ACCESS_TOKEN }}
- name: Fetch tags
run: git fetch --tags --force
- name: Create release tag
uses: ./.github/actions/create-release-tag
with:
bump: ${{ needs.determine-bump.outputs.bump }}