-
Notifications
You must be signed in to change notification settings - Fork 0
153 lines (131 loc) · 5.33 KB
/
release.yml
File metadata and controls
153 lines (131 loc) · 5.33 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
name: Create GitHub Release
on:
push:
tags:
- 'v*.*.*'
workflow_dispatch:
inputs:
tag:
description: 'Tag to create release for (e.g., v1.0.0)'
required: true
type: string
env:
REGISTRY: ghcr.io
CORE_IMAGE_NAME: ${{ github.repository_owner }}/simplens-core
DASHBOARD_IMAGE_NAME: ${{ github.repository_owner }}/simplens-dashboard
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch full history for commit analysis
- name: Get release tag
id: get_tag
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
TAG="${{ inputs.tag }}"
else
TAG="${GITHUB_REF#refs/tags/}"
fi
echo "tag=$TAG" >> $GITHUB_OUTPUT
echo "version=${TAG#v}" >> $GITHUB_OUTPUT
echo "Release tag: $TAG"
- name: Get previous tag
id: prev_tag
run: |
CURRENT_TAG="${{ steps.get_tag.outputs.tag }}"
# Get the previous tag (excluding current)
PREV_TAG=$(git tag --sort=-version:refname | grep -v "^$CURRENT_TAG$" | head -n 1)
if [ -z "$PREV_TAG" ]; then
# No previous tag, get all commits
echo "range=" >> $GITHUB_OUTPUT
echo "No previous tag found, will include all commits"
else
echo "range=$PREV_TAG..$CURRENT_TAG" >> $GITHUB_OUTPUT
echo "Commit range: $PREV_TAG..$CURRENT_TAG"
fi
echo "prev_tag=$PREV_TAG" >> $GITHUB_OUTPUT
- name: Generate release notes
id: release_notes
run: |
RANGE="${{ steps.prev_tag.outputs.range }}"
VERSION="${{ steps.get_tag.outputs.version }}"
TAG="${{ steps.get_tag.outputs.tag }}"
PREV_TAG="${{ steps.prev_tag.outputs.prev_tag }}"
OWNER_LOWER=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
CORE_IMAGE="${{ env.REGISTRY }}/${OWNER_LOWER}/simplens-core"
DASHBOARD_IMAGE="${{ env.REGISTRY }}/${OWNER_LOWER}/simplens-dashboard"
# Get commits
if [ -z "$RANGE" ]; then
COMMITS=$(git log --oneline --format="%H %s")
else
COMMITS=$(git log --oneline --format="%H %s" $RANGE)
fi
# Initialize categories
FEATURES=""
BUGFIXES=""
OTHER=""
# Process each commit
while IFS= read -r line; do
if [ -z "$line" ]; then
continue
fi
HASH=$(echo "$line" | awk '{print $1}')
SHORT_HASH=$(echo "$HASH" | cut -c1-7)
MESSAGE=$(echo "$line" | cut -d' ' -f2-)
LOWER_MSG=$(echo "$MESSAGE" | tr '[:upper:]' '[:lower:]')
# Create commit link
COMMIT_LINK="[\`$SHORT_HASH\`](https://github.com/${{ github.repository }}/commit/$HASH)"
# Categorize based on keywords (case-insensitive)
if echo "$LOWER_MSG" | grep -qE "(feature|feat|add|new|implement)"; then
FEATURES="$FEATURES- $MESSAGE ($COMMIT_LINK)"$'\n'
elif echo "$LOWER_MSG" | grep -qE "(fix|bug|bugfix|bug-fix|fixed|resolve|patch)"; then
BUGFIXES="$BUGFIXES- $MESSAGE ($COMMIT_LINK)"$'\n'
else
OTHER="$OTHER- $MESSAGE ($COMMIT_LINK)"$'\n'
fi
done <<< "$COMMITS"
# Build release body
BODY=""
# Add comparison link if there's a previous tag
if [ -n "$PREV_TAG" ]; then
BODY="**Full Changelog**: https://github.com/${{ github.repository }}/compare/$PREV_TAG...$TAG"$'\n\n'
fi
if [ -n "$FEATURES" ]; then
BODY="$BODY## 🚀 Features"$'\n\n'"$FEATURES"$'\n'
fi
if [ -n "$BUGFIXES" ]; then
BODY="$BODY## 🐛 Bug Fixes"$'\n\n'"$BUGFIXES"$'\n'
fi
if [ -n "$OTHER" ]; then
BODY="$BODY## 📦 Other Changes"$'\n\n'"$OTHER"$'\n'
fi
# Add Docker images section
BODY="$BODY---"$'\n\n'
BODY="$BODY## 🐳 Docker Images"$'\n\n'
BODY="$BODY| Service | Image |"$'\n'
BODY="$BODY|---------|-------|"$'\n'
BODY="$BODY| Core | \`${CORE_IMAGE}:$VERSION\` |"$'\n'
BODY="$BODY| Dashboard | \`${DASHBOARD_IMAGE}:$VERSION\` |"$'\n\n'
BODY="$BODY\`\`\`bash"$'\n'
BODY="$BODY# Pull images for this release"$'\n'
BODY="${BODY}docker pull ${CORE_IMAGE}:$VERSION"$'\n'
BODY="${BODY}docker pull ${DASHBOARD_IMAGE}:$VERSION"$'\n'
BODY="$BODY\`\`\`"$'\n'
# Save to file (to handle multiline output)
echo "$BODY" > release_notes.md
cat release_notes.md
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.get_tag.outputs.tag }}
name: Release ${{ steps.get_tag.outputs.tag }}
body_path: release_notes.md
draft: false
prerelease: ${{ contains(steps.get_tag.outputs.tag, '-') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}