-
Notifications
You must be signed in to change notification settings - Fork 0
218 lines (195 loc) · 8.09 KB
/
release.yml
File metadata and controls
218 lines (195 loc) · 8.09 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
name: Release
on:
push:
tags:
- 'v*.*.*'
workflow_dispatch:
inputs:
version:
description: 'Release version (e.g., 1.0.0)'
required: true
type: string
prerelease:
description: 'Is this a pre-release?'
required: false
type: boolean
default: false
env:
# Package-specific configuration - customize these for each package
PACKAGE_NAME: ${{ vars.PACKAGE_NAME || 'wp-utility' }}
PACKAGE_DISPLAY_NAME: ${{ vars.PACKAGE_DISPLAY_NAME || 'WP Utility' }}
COMPOSER_NAMESPACE: ${{ vars.COMPOSER_NAMESPACE || 'builtnorth/wp-utility' }}
jobs:
release:
name: Create Release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Determine version
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
VERSION="${{ github.event.inputs.version }}"
if [[ ! "$VERSION" =~ ^v ]]; then
VERSION="v$VERSION"
fi
else
VERSION="${{ github.ref_name }}"
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "version_number=${VERSION#v}" >> $GITHUB_OUTPUT
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
tools: composer:v2
# Skip composer.json version update - version tracked via git tags only
# This prevents merge conflicts between branches
- name: Update package.json version
if: contains(fromJSON('["package.json"]'), 'package.json')
run: |
if [ -f package.json ]; then
npm version ${{ steps.version.outputs.version_number }} --no-git-tag-version --allow-same-version
fi
- name: Commit version updates
if: github.event_name == 'workflow_dispatch'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
# Only commit package.json updates if it exists
if [ -f package.json ]; then
git add package.json package-lock.json
if ! git diff --cached --quiet; then
git commit -m "chore: bump version to ${{ steps.version.outputs.version_number }}"
git push origin HEAD:${{ github.ref_name }}
fi
fi
- name: Create and push tag
if: github.event_name == 'workflow_dispatch'
run: |
git tag -a ${{ steps.version.outputs.version }} -m "Release ${{ steps.version.outputs.version }}"
git push origin ${{ steps.version.outputs.version }}
- name: Generate changelog
id: changelog
run: |
# Get the previous tag
PREVIOUS_TAG=$(git describe --tags --abbrev=0 ${{ steps.version.outputs.version }}^ 2>/dev/null || echo "")
if [ -z "$PREVIOUS_TAG" ]; then
echo "No previous tag found, including all commits"
COMMITS=$(git log --pretty=format:"- %s (%h)" --reverse)
else
echo "Generating changelog from $PREVIOUS_TAG to ${{ steps.version.outputs.version }}"
COMMITS=$(git log ${PREVIOUS_TAG}..${{ steps.version.outputs.version }} --pretty=format:"- %s (%h)" --reverse)
fi
# Format changelog
CHANGELOG="## What's Changed in ${{ env.PACKAGE_DISPLAY_NAME }} ${{ steps.version.outputs.version }}"
CHANGELOG="$CHANGELOG"$'\n\n'
# Group commits by type
FEATURES=$(echo "$COMMITS" | grep -E "^- (feat|feature):" || true)
FIXES=$(echo "$COMMITS" | grep -E "^- (fix|bugfix):" || true)
DOCS=$(echo "$COMMITS" | grep -E "^- (docs|documentation):" || true)
STYLE=$(echo "$COMMITS" | grep -E "^- (style|formatting):" || true)
REFACTOR=$(echo "$COMMITS" | grep -E "^- (refactor|refactoring):" || true)
TEST=$(echo "$COMMITS" | grep -E "^- (test|tests):" || true)
CHORE=$(echo "$COMMITS" | grep -E "^- (chore|build|ci):" || true)
OTHER=$(echo "$COMMITS" | grep -vE "^- (feat|feature|fix|bugfix|docs|documentation|style|formatting|refactor|refactoring|test|tests|chore|build|ci):" || true)
if [ -n "$FEATURES" ]; then
CHANGELOG="$CHANGELOG"$'\n'"### Features"$'\n'"$FEATURES"$'\n'
fi
if [ -n "$FIXES" ]; then
CHANGELOG="$CHANGELOG"$'\n'"### Bug Fixes"$'\n'"$FIXES"$'\n'
fi
if [ -n "$DOCS" ]; then
CHANGELOG="$CHANGELOG"$'\n'"### Documentation"$'\n'"$DOCS"$'\n'
fi
if [ -n "$REFACTOR" ]; then
CHANGELOG="$CHANGELOG"$'\n'"### Refactoring"$'\n'"$REFACTOR"$'\n'
fi
if [ -n "$TEST" ]; then
CHANGELOG="$CHANGELOG"$'\n'"### Tests"$'\n'"$TEST"$'\n'
fi
if [ -n "$CHORE" ]; then
CHANGELOG="$CHANGELOG"$'\n'"### Maintenance"$'\n'"$CHORE"$'\n'
fi
if [ -n "$OTHER" ]; then
CHANGELOG="$CHANGELOG"$'\n'"### Other Changes"$'\n'"$OTHER"$'\n'
fi
CHANGELOG="$CHANGELOG"$'\n'"**Full Changelog**: "
if [ -n "$PREVIOUS_TAG" ]; then
CHANGELOG="$CHANGELOG""https://github.com/${{ github.repository }}/compare/${PREVIOUS_TAG}...${{ steps.version.outputs.version }}"
else
CHANGELOG="$CHANGELOG""https://github.com/${{ github.repository }}/commits/${{ steps.version.outputs.version }}"
fi
# Save to file for the release
echo "$CHANGELOG" > release_notes.md
- name: Create release archive
run: |
# Create a clean release directory
mkdir -p release-archive
# Copy all files except those that should be excluded
rsync -av \
--exclude='.git' \
--exclude='.github' \
--exclude='composer.lock' \
--exclude='release-archive' \
--exclude='release_notes.md' \
--exclude='node_modules' \
--exclude='.env' \
--exclude='tests' \
--exclude='docs' \
--exclude='examples' \
--exclude='build' \
--exclude='.vscode' \
--exclude='.idea' \
--exclude='*.log' \
--exclude='.DS_Store' \
--exclude='Thumbs.db' \
--exclude='.gitignore' \
--exclude='.gitattributes' \
--exclude='phpunit.xml*' \
--exclude='phpstan.neon*' \
--exclude='.phpcs.xml*' \
--exclude='Makefile' \
--exclude='*.md' \
. release-archive/
# Create zip archive
cd release-archive
zip -r ../${{ env.PACKAGE_NAME }}-${{ steps.version.outputs.version_number }}.zip .
cd ..
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.version.outputs.version }}
name: ${{ steps.version.outputs.version }}
body_path: release_notes.md
draft: false
prerelease: ${{ github.event.inputs.prerelease == 'true' }}
generate_release_notes: false
files: |
${{ env.PACKAGE_NAME }}-${{ steps.version.outputs.version_number }}.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Release summary
if: success()
run: |
echo "Release created successfully!"
echo ""
echo "To use this version in other packages:"
echo ""
echo " \"require\": {"
echo " \"${{ env.COMPOSER_NAMESPACE }}\": \"${{ steps.version.outputs.version_number }}\""
echo " }"
echo ""
echo "With VCS repository:"
echo " \"repositories\": ["
echo " {"
echo " \"type\": \"vcs\","
echo " \"url\": \"https://github.com/${{ github.repository }}\""
echo " }"
echo " ]"