-
Notifications
You must be signed in to change notification settings - Fork 0
139 lines (125 loc) · 4.87 KB
/
Copy pathmonthly-release.yml
File metadata and controls
139 lines (125 loc) · 4.87 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
name: Monthly Release
on:
schedule:
# 1st of month, 6 AM UTC
- cron: '0 6 1 * *'
workflow_dispatch:
inputs:
version_override:
description: 'Override version (e.g., v1.3.0). Leave empty for auto-increment.'
required: false
type: string
# Prevent overlap if a manual dispatch races with the cron trigger.
concurrency:
group: monthly-release
cancel-in-progress: false
permissions: {}
jobs:
monthly-release:
name: Monthly Automated Release
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
id-token: write
attestations: write
security-events: write
steps:
- name: Harden runner
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2
with:
egress-policy: audit
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 0
- name: Determine version
id: version
env:
VERSION_OVERRIDE: ${{ github.event.inputs.version_override }}
run: |
if [ -n "$VERSION_OVERRIDE" ]; then
# Validate format so a typo doesn't push a malformed tag.
if ! [[ "$VERSION_OVERRIDE" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then
echo "::error::Invalid version_override '$VERSION_OVERRIDE'. Expected vMAJOR.MINOR.PATCH[-prerelease]."
exit 1
fi
VERSION="$VERSION_OVERRIDE"
else
# Get latest tag and auto-increment patch
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "Latest tag: $LATEST_TAG"
# Parse version components
VERSION_NUM="${LATEST_TAG#v}"
MAJOR=$(echo "$VERSION_NUM" | cut -d. -f1)
MINOR=$(echo "$VERSION_NUM" | cut -d. -f2)
PATCH=$(echo "$VERSION_NUM" | cut -d. -f3)
# Increment patch
PATCH=$((PATCH + 1))
VERSION="v${MAJOR}.${MINOR}.${PATCH}"
fi
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "Releasing version: $VERSION"
- name: Check for changes since last release
id: changes
run: |
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$LATEST_TAG" ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "No previous tags found, proceeding with release."
else
COMMIT_COUNT=$(git rev-list "${LATEST_TAG}..HEAD" --count)
echo "Commits since $LATEST_TAG: $COMMIT_COUNT"
if [ "$COMMIT_COUNT" -gt 0 ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
else
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "No changes since last release, skipping."
fi
fi
- name: Generate changelog
if: steps.changes.outputs.has_changes == 'true'
id: changelog
run: |
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
{
echo "CHANGELOG<<EOF"
echo "## Monthly Automated Release"
echo ""
echo "This is an automated monthly release that includes updated system packages and all changes merged since the last release."
echo ""
if [ -n "$LATEST_TAG" ]; then
echo "### Changes since $LATEST_TAG"
echo ""
git log "${LATEST_TAG}..HEAD" --pretty=format:"- %s (%h)" --no-merges
echo ""
echo ""
echo "### Dependency Updates"
echo ""
git log "${LATEST_TAG}..HEAD" --pretty=format:"- %s (%h)" --no-merges --grep="chore(deps)"
else
echo "### Initial Release"
echo ""
git log --pretty=format:"- %s (%h)" --no-merges -20
fi
echo ""
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Create and push tag
if: steps.changes.outputs.has_changes == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "${{ steps.version.outputs.VERSION }}" -m "Monthly release ${{ steps.version.outputs.VERSION }}"
git push origin "${{ steps.version.outputs.VERSION }}"
- name: Create GitHub Release
if: steps.changes.outputs.has_changes == 'true'
uses: softprops/action-gh-release@b4309332981a82ec1c5618f44dd2e27cc8bfbfda # v2
with:
tag_name: ${{ steps.version.outputs.VERSION }}
name: ${{ steps.version.outputs.VERSION }} (Monthly)
body: ${{ steps.changelog.outputs.CHANGELOG }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}