-
Notifications
You must be signed in to change notification settings - Fork 17
167 lines (139 loc) · 5.41 KB
/
Copy pathrelease.yml
File metadata and controls
167 lines (139 loc) · 5.41 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
name: Release
on:
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g., v0.2.2)'
required: true
type: string
permissions:
contents: write
pull-requests: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0 # Fetch all history for changelog generation
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Lint
run: bun lint
- name: Build
run: bun run build
- name: Verify build output
run: |
if [ ! -f dynamic-weather-card.js ]; then
echo "Build failed: dynamic-weather-card.js not found"
exit 1
fi
echo "Build successful: $(wc -l < dynamic-weather-card.js) lines"
- name: Get version from tag or input
id: version
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT
echo "tag=${{ inputs.version }}" >> $GITHUB_OUTPUT
else
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
fi
- name: Generate Changelog
id: changelog
run: |
# Get the previous tag
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
CURRENT_TAG="${{ steps.version.outputs.tag }}"
echo "Generating changelog from ${PREV_TAG} to ${CURRENT_TAG}"
# Generate changelog from commits
if [ -z "$PREV_TAG" ]; then
# First release - get all commits
COMMITS=$(git log --pretty=format:"- %s (%h)" --no-merges)
else
# Get commits since last tag
COMMITS=$(git log ${PREV_TAG}..HEAD --pretty=format:"- %s (%h)" --no-merges)
fi
# Categorize commits
FEATURES=$(echo "$COMMITS" | grep -E "^- (feat|feature):" || echo "")
FIXES=$(echo "$COMMITS" | grep -E "^- (fix|bugfix):" || echo "")
DOCS=$(echo "$COMMITS" | grep -E "^- docs?:" || echo "")
CHORES=$(echo "$COMMITS" | grep -E "^- (chore|build|ci):" || echo "")
OTHERS=$(echo "$COMMITS" | grep -vE "^- (feat|feature|fix|bugfix|docs?|chore|build|ci):" || echo "")
# Build changelog
CHANGELOG="## What's Changed"$'\n'$'\n'
if [ -n "$FEATURES" ]; then
CHANGELOG+="### ✨ Features"$'\n'
CHANGELOG+="$FEATURES"$'\n'$'\n'
fi
if [ -n "$FIXES" ]; then
CHANGELOG+="### 🐛 Bug Fixes"$'\n'
CHANGELOG+="$FIXES"$'\n'$'\n'
fi
if [ -n "$DOCS" ]; then
CHANGELOG+="### 📚 Documentation"$'\n'
CHANGELOG+="$DOCS"$'\n'$'\n'
fi
if [ -n "$CHORES" ]; then
CHANGELOG+="### 🔧 Chores & Maintenance"$'\n'
CHANGELOG+="$CHORES"$'\n'$'\n'
fi
if [ -n "$OTHERS" ]; then
CHANGELOG+="### Other Changes"$'\n'
CHANGELOG+="$OTHERS"$'\n'$'\n'
fi
# Add compare link if there's a previous tag
if [ -n "$PREV_TAG" ]; then
CHANGELOG+="**Full Changelog**: https://github.com/${{ github.repository }}/compare/${PREV_TAG}...${CURRENT_TAG}"
fi
# Save to file for release notes
echo "$CHANGELOG" > /tmp/changelog.md
# Output for GitHub Actions (escape newlines)
echo "changelog<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Update CHANGELOG.md
run: |
CURRENT_TAG="${{ steps.version.outputs.tag }}"
RELEASE_DATE=$(date +%Y-%m-%d)
# Create or update CHANGELOG.md
if [ ! -f CHANGELOG.md ]; then
echo "# Changelog" > CHANGELOG.md
echo "" >> CHANGELOG.md
echo "All notable changes to this project will be documented in this file." >> CHANGELOG.md
echo "" >> CHANGELOG.md
fi
# Add new release section at the top (after the header)
{
head -n 3 CHANGELOG.md
echo ""
echo "## [${CURRENT_TAG}] - ${RELEASE_DATE}"
echo ""
cat /tmp/changelog.md
echo ""
tail -n +4 CHANGELOG.md
} > CHANGELOG.tmp && mv CHANGELOG.tmp CHANGELOG.md
- name: Commit CHANGELOG.md
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add CHANGELOG.md
git commit -m "docs: update CHANGELOG.md for ${{ steps.version.outputs.tag }}" || echo "No changes to commit"
git push origin HEAD:main || echo "Could not push to main"
- name: Create or Update Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.tag }}
name: Release ${{ steps.version.outputs.tag }}
body: ${{ steps.changelog.outputs.changelog }}
files: dynamic-weather-card.js
draft: false
prerelease: false
make_latest: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}