-
Notifications
You must be signed in to change notification settings - Fork 0
238 lines (197 loc) · 8.02 KB
/
release.yml
File metadata and controls
238 lines (197 loc) · 8.02 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
name: Release and Docker Publish
on:
pull_request:
types: [closed]
branches:
- dev
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-release:
# Only run if PR was merged and has a release label
if: |
github.event.pull_request.merged == true && (
contains(github.event.pull_request.labels.*.name, 'release:major') ||
contains(github.event.pull_request.labels.*.name, 'release:minor') ||
contains(github.event.pull_request.labels.*.name, 'release:patch')
)
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
id-token: write
pull-requests: read
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
fetch-depth: 0 # Fetch all history for proper versioning
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Determine version bump from PR labels
id: version_bump
env:
PR_LABELS: ${{ toJson(github.event.pull_request.labels.*.name) }}
run: |
echo "PR Labels: $PR_LABELS"
if echo "$PR_LABELS" | grep -q "release:major"; then
echo "bump=major" >> $GITHUB_OUTPUT
echo "Detected: MAJOR release"
elif echo "$PR_LABELS" | grep -q "release:minor"; then
echo "bump=minor" >> $GITHUB_OUTPUT
echo "Detected: MINOR release"
elif echo "$PR_LABELS" | grep -q "release:patch"; then
echo "bump=patch" >> $GITHUB_OUTPUT
echo "Detected: PATCH release"
else
echo "Error: No release label found"
exit 1
fi
- name: Generate version and metadata
id: meta
env:
BUMP_TYPE: ${{ steps.version_bump.outputs.bump }}
run: |
# Get short commit SHA
SHORT_SHA=$(git rev-parse --short HEAD)
# Get version from previous release or default to v0.0.0
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "Latest tag: $LATEST_TAG"
# Strip 'v' prefix and any existing commit hash/suffix
CLEAN_VERSION=$(echo $LATEST_TAG | sed 's/^v//' | sed 's/-.*$//')
# Parse version components
IFS='.' read -r MAJOR MINOR PATCH <<< "$CLEAN_VERSION"
# Bump version based on label
case $BUMP_TYPE in
major)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
minor)
MINOR=$((MINOR + 1))
PATCH=0
;;
patch)
PATCH=$((PATCH + 1))
;;
esac
# Create new version
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
VERSION="v${NEW_VERSION}-${SHORT_SHA}"
CLEAN_VERSION_TAG="v${NEW_VERSION}"
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "clean_version=${CLEAN_VERSION_TAG}" >> $GITHUB_OUTPUT
echo "short_sha=${SHORT_SHA}" >> $GITHUB_OUTPUT
echo "semver=${NEW_VERSION}" >> $GITHUB_OUTPUT
echo "Generated version: ${VERSION}"
echo "Clean version: ${CLEAN_VERSION_TAG}"
- name: Extract Docker metadata
id: docker_meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ steps.meta.outputs.version }}
type=raw,value=${{ steps.meta.outputs.clean_version }}
type=raw,value=latest
type=semver,pattern={{version}},value=${{ steps.meta.outputs.semver }}
type=semver,pattern={{major}}.{{minor}},value=${{ steps.meta.outputs.semver }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Generate release notes
id: release_notes
env:
PR_TITLE: ${{ github.event.pull_request.title }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_URL: ${{ github.event.pull_request.html_url }}
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
run: |
# Get the last release tag
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || git rev-list --max-parents=0 HEAD)
# Generate changelog
CHANGELOG=$(git log ${LAST_TAG}..HEAD --pretty=format:"- %s (%h)" --no-merges)
if [ -z "$CHANGELOG" ]; then
CHANGELOG="- Initial release"
fi
# Create release notes
cat << EOF > release_notes.md
## Release Info
Released from PR [#${PR_NUMBER}](${PR_URL}): ${PR_TITLE}
Author: @${PR_AUTHOR}
## Docker Images
Available tags for this release:
\`\`\`bash
# Semantic version with commit SHA
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
# Clean semantic version
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.clean_version }}
# Latest (always points to most recent release)
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
\`\`\`
## Changes
${CHANGELOG}
## Installation
### Docker Compose
Update your \`docker-compose.yml\`:
\`\`\`yaml
services:
repovault:
image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.clean_version }}
restart: unless-stopped
# ... rest of your config
\`\`\`
### Docker Run
\`\`\`bash
docker run -d \\
--name repovault \\
--restart unless-stopped \\
-v ./config.yaml:/config/config.yaml:ro \\
-v ./backup:/backup:rw \\
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.clean_version }}
\`\`\`
---
**Full Changelog**: https://github.com/${{ github.repository }}/compare/${LAST_TAG}...${{ steps.meta.outputs.clean_version }}
EOF
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.meta.outputs.clean_version }}
name: Release ${{ steps.meta.outputs.clean_version }}
body_path: release_notes.md
draft: false
prerelease: false
generate_release_notes: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Release Summary
run: |
echo "## Release Published Successfully! :rocket:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version:** ${{ steps.meta.outputs.clean_version }}" >> $GITHUB_STEP_SUMMARY
echo "**Commit:** ${{ steps.meta.outputs.short_sha }}" >> $GITHUB_STEP_SUMMARY
echo "**Type:** ${{ steps.version_bump.outputs.bump }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Docker Images" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.clean_version }}" >> $GITHUB_STEP_SUMMARY
echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY