Skip to content

Commit 82c8b94

Browse files
committed
BREAKING CHANGE: add tv processing
also update structure to more maintainable modularized packages.
1 parent b9ffe57 commit 82c8b94

File tree

15 files changed

+2196
-1269
lines changed

15 files changed

+2196
-1269
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
name: Build and Publish Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- 'v*'
9+
pull_request:
10+
branches:
11+
- main
12+
13+
env:
14+
REGISTRY: ghcr.io
15+
IMAGE_NAME: ${{ github.repository }}
16+
17+
jobs:
18+
build-and-push:
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
packages: write
23+
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
27+
with:
28+
fetch-depth: 0 # Fetch all history for version calculation
29+
30+
- name: Set up Docker Buildx
31+
uses: docker/setup-buildx-action@v3
32+
33+
- name: Log in to Container Registry
34+
if: github.event_name != 'pull_request'
35+
uses: docker/login-action@v3
36+
with:
37+
registry: ${{ env.REGISTRY }}
38+
username: ${{ github.actor }}
39+
password: ${{ secrets.GITHUB_TOKEN }}
40+
41+
- name: Generate version and tags
42+
id: meta
43+
run: |
44+
# Convert repository name to lowercase
45+
IMAGE_NAME_LOWER=$(echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" | tr '[:upper:]' '[:lower:]')
46+
47+
# Get current date for version generation
48+
DATE=$(date +'%Y%m%d')
49+
50+
# Generate version based on context
51+
if [[ $GITHUB_REF == refs/tags/v* ]]; then
52+
# If this is a tag push, use the tag as version
53+
VERSION=${GITHUB_REF#refs/tags/v}
54+
TAGS="${IMAGE_NAME_LOWER}:${VERSION},${IMAGE_NAME_LOWER}:latest"
55+
elif [[ $GITHUB_REF == refs/heads/main ]]; then
56+
# If this is main branch, generate auto-incrementing version
57+
# Get count of commits to main for auto-incrementing
58+
COMMIT_COUNT=$(git rev-list --count HEAD)
59+
SHORT_SHA=${GITHUB_SHA::8}
60+
61+
# Generate semantic version: 1.0.COMMIT_COUNT-DATE
62+
VERSION="1.0.${COMMIT_COUNT}"
63+
TAGS="${IMAGE_NAME_LOWER}:${VERSION},${IMAGE_NAME_LOWER}:latest,${IMAGE_NAME_LOWER}:${DATE}-${SHORT_SHA}"
64+
else
65+
# For pull requests or other branches
66+
SHORT_SHA=${GITHUB_SHA::8}
67+
VERSION="pr-${SHORT_SHA}"
68+
TAGS="${IMAGE_NAME_LOWER}:${VERSION}"
69+
fi
70+
71+
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
72+
echo "TAGS=${TAGS}" >> $GITHUB_OUTPUT
73+
echo "IMAGE_NAME_LOWER=${IMAGE_NAME_LOWER}" >> $GITHUB_OUTPUT
74+
75+
# Print for debugging
76+
echo "Generated version: ${VERSION}"
77+
echo "Generated tags: ${TAGS}"
78+
79+
- name: Extract metadata
80+
id: docker_meta
81+
uses: docker/metadata-action@v5
82+
with:
83+
images: ${{ steps.meta.outputs.IMAGE_NAME_LOWER }}
84+
tags: |
85+
type=ref,event=branch
86+
type=ref,event=pr
87+
type=semver,pattern={{version}}
88+
type=semver,pattern={{major}}.{{minor}}
89+
type=raw,value=${{ steps.meta.outputs.VERSION }}
90+
type=raw,value=latest,enable={{is_default_branch}}
91+
92+
- name: Build and push Docker image
93+
uses: docker/build-push-action@v5
94+
with:
95+
context: .
96+
file: ./Dockerfile
97+
platforms: linux/amd64,linux/arm64
98+
push: ${{ github.event_name != 'pull_request' }}
99+
tags: ${{ steps.docker_meta.outputs.tags }}
100+
labels: ${{ steps.docker_meta.outputs.labels }}
101+
cache-from: type=gha
102+
cache-to: type=gha,mode=max
103+
104+
- name: Generate summary
105+
if: github.event_name != 'pull_request'
106+
run: |
107+
echo "## 🐳 Docker Image Published" >> $GITHUB_STEP_SUMMARY
108+
echo "" >> $GITHUB_STEP_SUMMARY
109+
echo "**Version:** ${{ steps.meta.outputs.VERSION }}" >> $GITHUB_STEP_SUMMARY
110+
echo "" >> $GITHUB_STEP_SUMMARY
111+
echo "**Registry:** ${{ env.REGISTRY }}" >> $GITHUB_STEP_SUMMARY
112+
echo "" >> $GITHUB_STEP_SUMMARY
113+
echo "**Tags:**" >> $GITHUB_STEP_SUMMARY
114+
echo '```' >> $GITHUB_STEP_SUMMARY
115+
echo "${{ steps.docker_meta.outputs.tags }}" | tr ',' '\n' >> $GITHUB_STEP_SUMMARY
116+
echo '```' >> $GITHUB_STEP_SUMMARY
117+
echo "" >> $GITHUB_STEP_SUMMARY
118+
echo "**Pull command:**" >> $GITHUB_STEP_SUMMARY
119+
echo '```bash' >> $GITHUB_STEP_SUMMARY
120+
echo "docker pull ${{ steps.meta.outputs.IMAGE_NAME_LOWER }}:${{ steps.meta.outputs.VERSION }}" >> $GITHUB_STEP_SUMMARY
121+
echo '```' >> $GITHUB_STEP_SUMMARY

.github/workflows/release.yml

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
name: Create Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
release_type:
7+
description: 'Release type'
8+
required: true
9+
default: 'patch'
10+
type: choice
11+
options:
12+
- patch
13+
- minor
14+
- major
15+
push:
16+
branches:
17+
- main
18+
paths-ignore:
19+
- 'README*.md'
20+
- 'LICENSE'
21+
- '.gitignore'
22+
- 'example/**'
23+
24+
jobs:
25+
check-changes:
26+
runs-on: ubuntu-latest
27+
outputs:
28+
should_release: ${{ steps.changes.outputs.should_release }}
29+
version: ${{ steps.version.outputs.version }}
30+
steps:
31+
- name: Checkout repository
32+
uses: actions/checkout@v4
33+
with:
34+
fetch-depth: 0
35+
36+
- name: Check for significant changes
37+
id: changes
38+
run: |
39+
# Get the last release tag
40+
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
41+
echo "Last tag: $LAST_TAG"
42+
43+
# Check if there are changes in source code since last release
44+
if git diff --quiet $LAST_TAG HEAD -- '*.go' 'go.mod' 'go.sum' 'Dockerfile' '.github/workflows/' 'internal/' 'cmd/'; then
45+
echo "No significant changes detected"
46+
echo "should_release=false" >> $GITHUB_OUTPUT
47+
else
48+
echo "Significant changes detected"
49+
echo "should_release=true" >> $GITHUB_OUTPUT
50+
fi
51+
52+
- name: Calculate next version
53+
id: version
54+
if: steps.changes.outputs.should_release == 'true' || github.event_name == 'workflow_dispatch'
55+
run: |
56+
# Get the last release tag
57+
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
58+
echo "Last tag: $LAST_TAG"
59+
60+
# Remove 'v' prefix and split version
61+
VERSION_NUMBER=${LAST_TAG#v}
62+
IFS='.' read -r -a VERSION_PARTS <<< "$VERSION_NUMBER"
63+
64+
MAJOR=${VERSION_PARTS[0]:-0}
65+
MINOR=${VERSION_PARTS[1]:-0}
66+
PATCH=${VERSION_PARTS[2]:-0}
67+
68+
# Determine release type
69+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
70+
RELEASE_TYPE="${{ github.event.inputs.release_type }}"
71+
else
72+
# Auto-determine based on commit messages since last release
73+
COMMITS=$(git log $LAST_TAG..HEAD --oneline)
74+
if echo "$COMMITS" | grep -qE "(BREAKING CHANGE|!:)"; then
75+
RELEASE_TYPE="major"
76+
elif echo "$COMMITS" | grep -qE "(feat:|feature:)"; then
77+
RELEASE_TYPE="minor"
78+
else
79+
RELEASE_TYPE="patch"
80+
fi
81+
fi
82+
83+
echo "Release type: $RELEASE_TYPE"
84+
85+
# Increment version based on release type
86+
case $RELEASE_TYPE in
87+
major)
88+
MAJOR=$((MAJOR + 1))
89+
MINOR=0
90+
PATCH=0
91+
;;
92+
minor)
93+
MINOR=$((MINOR + 1))
94+
PATCH=0
95+
;;
96+
patch)
97+
PATCH=$((PATCH + 1))
98+
;;
99+
esac
100+
101+
NEW_VERSION="v${MAJOR}.${MINOR}.${PATCH}"
102+
echo "New version: $NEW_VERSION"
103+
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
104+
105+
create-release:
106+
needs: check-changes
107+
if: needs.check-changes.outputs.should_release == 'true' || github.event_name == 'workflow_dispatch'
108+
runs-on: ubuntu-latest
109+
permissions:
110+
contents: write
111+
steps:
112+
- name: Checkout repository
113+
uses: actions/checkout@v4
114+
with:
115+
fetch-depth: 0
116+
117+
- name: Generate changelog
118+
id: changelog
119+
run: |
120+
# Get the last release tag
121+
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
122+
123+
if [[ -n "$LAST_TAG" ]]; then
124+
echo "## What's Changed" > changelog.md
125+
echo "" >> changelog.md
126+
127+
# Get commits since last release
128+
git log $LAST_TAG..HEAD --pretty=format:"- %s (%h)" --reverse >> changelog.md
129+
else
130+
echo "## Initial Release" > changelog.md
131+
echo "" >> changelog.md
132+
echo "🎉 First release of Labelarr!" >> changelog.md
133+
echo "" >> changelog.md
134+
echo "### Features" >> changelog.md
135+
echo "- 🎬 Movie library processing with TMDb integration" >> changelog.md
136+
echo "- 📺 TV show library processing with TMDb integration" >> changelog.md
137+
echo "- 🏷️ Smart label/genre management" >> changelog.md
138+
echo "- 🐳 Docker container with multi-architecture support" >> changelog.md
139+
fi
140+
141+
echo "" >> changelog.md
142+
echo "### Docker Image" >> changelog.md
143+
echo '```bash' >> changelog.md
144+
echo "docker pull ghcr.io/${{ github.repository_owner }}/$(echo '${{ github.repository }}' | cut -d'/' -f2):${{ needs.check-changes.outputs.version }}" >> changelog.md
145+
echo '```' >> changelog.md
146+
147+
- name: Create Release
148+
uses: softprops/action-gh-release@v1
149+
with:
150+
tag_name: ${{ needs.check-changes.outputs.version }}
151+
name: Release ${{ needs.check-changes.outputs.version }}
152+
body_path: changelog.md
153+
draft: false
154+
prerelease: false
155+
generate_release_notes: true

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ COPY . .
88
RUN go mod download
99

1010
# Build the application
11-
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o labelarr main.go
11+
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o labelarr ./cmd/labelarr
1212

1313
# Runtime stage
1414
FROM alpine:latest

0 commit comments

Comments
 (0)