-
Notifications
You must be signed in to change notification settings - Fork 0
335 lines (298 loc) · 12.1 KB
/
release.yml
File metadata and controls
335 lines (298 loc) · 12.1 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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
name: Create Release
on:
workflow_dispatch:
inputs:
release_type:
description: 'Release type'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
push:
branches:
- main
paths-ignore:
- 'README*.md'
- 'LICENSE'
- '.gitignore'
- 'IMPLEMENTATION_PLAN.md'
jobs:
check-changes:
runs-on: ubuntu-latest
outputs:
should_release: ${{ steps.changes.outputs.should_release }}
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check for significant changes
id: changes
run: |
# Get the last release tag
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
echo "Last tag: ${LAST_TAG:-'(none)'}"
# Check if there are changes in source code since last release
if [[ -z "$LAST_TAG" ]]; then
# No previous tags, this is the first release
echo "No previous tags found - first release"
echo "should_release=true" >> $GITHUB_OUTPUT
elif git diff --quiet $LAST_TAG HEAD -- '*.go' 'go.mod' 'go.sum' 'Dockerfile' '.github/workflows/' 'internal/' 'cmd/' 'pkg/'; then
echo "No significant changes detected"
echo "should_release=false" >> $GITHUB_OUTPUT
else
echo "Significant changes detected"
echo "should_release=true" >> $GITHUB_OUTPUT
fi
- name: Calculate next version
id: version
if: steps.changes.outputs.should_release == 'true' || github.event_name == 'workflow_dispatch'
run: |
# Get the last release tag
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
echo "Last tag: ${LAST_TAG:-'(none)'}"
# Handle first release vs. subsequent releases
if [[ -z "$LAST_TAG" ]]; then
# First release - start from v0.0.0
MAJOR=0
MINOR=1
PATCH=0
echo "First release - starting from v0.1.0"
else
# Remove 'v' prefix and split version
VERSION_NUMBER=${LAST_TAG#v}
IFS='.' read -r -a VERSION_PARTS <<< "$VERSION_NUMBER"
MAJOR=${VERSION_PARTS[0]:-0}
MINOR=${VERSION_PARTS[1]:-0}
PATCH=${VERSION_PARTS[2]:-0}
fi
# Determine release type
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
RELEASE_TYPE="${{ github.event.inputs.release_type }}"
else
# Auto-determine based on commit messages since last release
if [[ -z "$LAST_TAG" ]]; then
# First release - check all commits
COMMITS=$(git log --oneline)
else
# Subsequent release - check commits since last tag
COMMITS=$(git log $LAST_TAG..HEAD --oneline)
fi
if echo "$COMMITS" | grep -qE "(BREAKING CHANGE|!:)"; then
RELEASE_TYPE="major"
elif echo "$COMMITS" | grep -qE "(feat:|feature:)"; then
RELEASE_TYPE="minor"
else
RELEASE_TYPE="patch"
fi
fi
echo "Release type: $RELEASE_TYPE"
# Increment version based on release type
case $RELEASE_TYPE in
major)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
minor)
MINOR=$((MINOR + 1))
PATCH=0
;;
patch)
PATCH=$((PATCH + 1))
;;
esac
NEW_VERSION="v${MAJOR}.${MINOR}.${PATCH}"
echo "New version: $NEW_VERSION"
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.23'
- name: Cache Go modules
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Download dependencies
run: go mod download
- name: Run tests
run: go test -v ./...
- name: Run go vet
run: go vet ./...
- name: Run go fmt check
run: |
if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then
echo "The following files need to be formatted:"
gofmt -s -l .
exit 1
fi
build:
needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.23'
- name: Build application
run: |
# Build for multiple architectures
GOOS=linux GOARCH=amd64 go build -o syncarr-linux-amd64 ./cmd/syncarr
GOOS=linux GOARCH=arm64 go build -o syncarr-linux-arm64 ./cmd/syncarr
GOOS=windows GOARCH=amd64 go build -o syncarr-windows-amd64.exe ./cmd/syncarr
GOOS=darwin GOARCH=amd64 go build -o syncarr-darwin-amd64 ./cmd/syncarr
GOOS=darwin GOARCH=arm64 go build -o syncarr-darwin-arm64 ./cmd/syncarr
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: syncarr-binaries
path: syncarr-*
create-release:
needs: [check-changes, test, build]
if: needs.check-changes.outputs.should_release == 'true' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: syncarr-binaries
- name: Generate changelog
id: changelog
run: |
# Get the last release tag
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [[ -n "$LAST_TAG" ]]; then
echo "## What's Changed" > changelog.md
echo "" >> changelog.md
# Get commits since last release
git log $LAST_TAG..HEAD --pretty=format:"- %s (%h)" --reverse >> changelog.md
else
echo "## 🎉 Initial Release of SyncArr" > changelog.md
echo "" >> changelog.md
echo "SyncArr synchronizes labeled movies and TV shows between source and destination Plex Media Servers." >> changelog.md
echo "" >> changelog.md
echo "### ✨ Features" >> changelog.md
echo "- 🏷️ Label-based synchronization between Plex servers" >> changelog.md
echo "- 🔄 Bidirectional watched state synchronization" >> changelog.md
echo "- 📁 Secure SSH/SFTP file transfers with key-based authentication" >> changelog.md
echo "- 🔄 Incremental sync with change detection" >> changelog.md
echo "- 🎯 Content filtering by patterns, size, and library rules" >> changelog.md
echo "- 🐳 Docker container with complete configuration via environment variables" >> changelog.md
echo "- 📊 Comprehensive structured logging" >> changelog.md
echo "- ⚡ Force full sync option for resolving inconsistencies" >> changelog.md
echo "- 🔧 Flexible deployment (one-shot or continuous modes)" >> changelog.md
echo "" >> changelog.md
echo "### 🚀 Getting Started" >> changelog.md
echo "1. Set up SSH key-based authentication between servers" >> changelog.md
echo "2. Configure environment variables for source/destination Plex servers" >> changelog.md
echo "3. Add labels to media items you want to sync" >> changelog.md
echo "4. Deploy using Docker Compose" >> changelog.md
fi
echo "" >> changelog.md
echo "### 🐳 Docker Images" >> changelog.md
echo "" >> changelog.md
echo "**Multi-architecture support:** \`linux/amd64\`, \`linux/arm64\`" >> changelog.md
echo "" >> changelog.md
echo '```bash' >> changelog.md
echo "# Latest release" >> changelog.md
echo "docker pull ghcr.io/${{ github.repository_owner }}/syncarr:${{ needs.check-changes.outputs.version }}" >> changelog.md
echo "" >> changelog.md
echo "# Always latest" >> changelog.md
echo "docker pull ghcr.io/${{ github.repository_owner }}/syncarr:latest" >> changelog.md
echo '```' >> changelog.md
echo "" >> changelog.md
echo "### 📥 Binary Downloads" >> changelog.md
echo "" >> changelog.md
echo "Pre-compiled binaries are available for multiple platforms in the release assets below." >> changelog.md
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.check-changes.outputs.version }}
name: Release ${{ needs.check-changes.outputs.version }}
body_path: changelog.md
files: |
syncarr-linux-amd64
syncarr-linux-arm64
syncarr-windows-amd64.exe
syncarr-darwin-amd64
syncarr-darwin-arm64
draft: false
prerelease: false
generate_release_notes: true
publish-docker:
needs: [check-changes, create-release]
if: needs.check-changes.outputs.should_release == 'true' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=raw,value=${{ needs.check-changes.outputs.version }}
type=raw,value=latest
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Generate Docker summary
run: |
echo "## 🐳 Docker Image Published" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version:** ${{ needs.check-changes.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "**Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Registry:** ghcr.io" >> $GITHUB_STEP_SUMMARY
echo "**Platforms:** linux/amd64, linux/arm64" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Tags:**" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "ghcr.io/${{ github.repository }}:${{ needs.check-changes.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "ghcr.io/${{ github.repository }}:latest" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Pull command:**" >> $GITHUB_STEP_SUMMARY
echo '```bash' >> $GITHUB_STEP_SUMMARY
echo "docker pull ghcr.io/${{ github.repository }}:${{ needs.check-changes.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY