-
Notifications
You must be signed in to change notification settings - Fork 8
194 lines (171 loc) · 6.85 KB
/
release.yml
File metadata and controls
194 lines (171 loc) · 6.85 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
name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: 'Version tag (e.g. v1.2.0)'
required: true
notes:
description: 'Release notes (optional)'
required: false
jobs:
release:
name: Create Release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Resolve version
id: version
run: |
if [ "${{ github.event_name }}" = "push" ]; then
VERSION="${{ github.ref_name }}"
else
VERSION="${{ github.event.inputs.version }}"
fi
if ! echo "$VERSION" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?$'; then
echo "Invalid version format: $VERSION"
exit 1
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Releasing $VERSION"
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: pdo, pgsql, mbstring, zip, gd, bcmath
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Generate changelog since last tag
id: changelog
run: |
VERSION="${{ steps.version.outputs.version }}"
PREV_TAG=$(git tag --sort=-v:refname | grep -v "^${VERSION}$" | head -1 || echo "")
if [ -z "$PREV_TAG" ]; then
LOG=$(git log --pretty=format:"- %s (%h)" | head -30)
else
LOG=$(git log "${PREV_TAG}..HEAD" --pretty=format:"- %s (%h)")
fi
echo "log<<EOF" >> $GITHUB_OUTPUT
echo "$LOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Build release notes
id: notes
run: |
CUSTOM="${{ github.event.inputs.notes }}"
LOG="${{ steps.changelog.outputs.log }}"
BODY=""
if [ -n "$CUSTOM" ]; then
BODY="${CUSTOM}"$'\n\n'
fi
BODY="${BODY}## Changes"$'\n'"${LOG}"
echo "body<<EOF" >> $GITHUB_OUTPUT
echo "$BODY" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Bump version and update CHANGELOG.md
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
DATE=$(date +%Y-%m-%d)
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
git fetch origin main
git checkout main
git pull origin main
# Bump version.php
sed -i "s/'current' => '.*'/'current' => '${VERSION}'/" backend/config/version.php
# Update CHANGELOG.md
if [ -f CHANGELOG.md ]; then
PREV_TAG=$(git tag --sort=-v:refname | grep -v "^${VERSION}$" | head -1 || echo "")
FEATURES=""
FIXES=""
if [ -n "$PREV_TAG" ]; then
FEATURES=$(git log "${PREV_TAG}..HEAD" --pretty=format:"%s" --no-merges | grep -E "^feat" | sed 's/^feat[^:]*: /- /' || true)
FIXES=$(git log "${PREV_TAG}..HEAD" --pretty=format:"%s" --no-merges | grep -E "^fix" | sed 's/^fix[^:]*: /- /' || true)
fi
# Build entry file
echo "## [${VERSION}] - ${DATE}" > /tmp/changelog_entry.md
echo "" >> /tmp/changelog_entry.md
if [ -n "$FEATURES" ]; then
echo "### Added" >> /tmp/changelog_entry.md
echo "$FEATURES" >> /tmp/changelog_entry.md
echo "" >> /tmp/changelog_entry.md
fi
if [ -n "$FIXES" ]; then
echo "### Fixed" >> /tmp/changelog_entry.md
echo "$FIXES" >> /tmp/changelog_entry.md
echo "" >> /tmp/changelog_entry.md
fi
# Insert new version entry after [Unreleased] section
FIRST_VERSION_LINE=$(grep -n "^## \[0\." CHANGELOG.md | head -1 | cut -d: -f1)
if [ -n "$FIRST_VERSION_LINE" ]; then
head -n $((FIRST_VERSION_LINE - 1)) CHANGELOG.md > /tmp/changelog_top.md
echo "" >> /tmp/changelog_top.md
cat /tmp/changelog_entry.md >> /tmp/changelog_top.md
tail -n +${FIRST_VERSION_LINE} CHANGELOG.md >> /tmp/changelog_top.md
mv /tmp/changelog_top.md CHANGELOG.md
fi
sed -i "s|\[Unreleased\]: .*|[Unreleased]: https://github.com/Mes-Open/OpenMes/compare/${VERSION}...develop|" CHANGELOG.md
git add CHANGELOG.md
fi
git add backend/config/version.php
if git diff --cached --quiet; then
echo "Version already set to ${VERSION}, no commit needed."
else
git commit -m "chore: bump version to ${VERSION}, update CHANGELOG"
git push origin main
fi
- name: Install PHP dependencies
working-directory: backend
run: |
composer install --no-dev --optimize-autoloader --no-interaction --ignore-platform-reqs
rm -f vendor/composer/platform_check.php
- name: Install JS dependencies and build assets
working-directory: backend
run: npm ci && npm run build
- name: Build distributable ZIP
run: |
VERSION="${{ steps.version.outputs.version }}"
DIST="openmmes-${VERSION}"
mkdir -p "${DIST}"
# Copy root files
cp index.php "${DIST}/"
cp docker-compose.yml "${DIST}/"
cp Caddyfile "${DIST}/"
cp .env.example "${DIST}/" 2>/dev/null || true
cp README.md "${DIST}/" 2>/dev/null || true
# Copy backend (with vendor and built assets, without dev files)
rsync -a backend/ "${DIST}/backend/" \
--exclude='.env' \
--exclude='node_modules' \
--exclude='tests' \
--exclude='.git' \
--exclude='storage/logs/*.log'
# Ensure storage directories exist
mkdir -p "${DIST}/backend/storage/logs"
mkdir -p "${DIST}/backend/storage/framework/cache"
mkdir -p "${DIST}/backend/storage/framework/sessions"
mkdir -p "${DIST}/backend/storage/framework/views"
touch "${DIST}/backend/storage/logs/.gitkeep"
zip -r "${DIST}.zip" "${DIST}/"
echo "zip_name=${DIST}.zip" >> $GITHUB_ENV
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.version }}
name: OpenMES ${{ steps.version.outputs.version }}
body: ${{ steps.notes.outputs.body }}
draft: false
prerelease: false
files: ${{ env.zip_name }}