Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: Build and Publish Docker Image

on:
push:
branches:
- main
tags:
- 'v*'
pull_request:
branches:
- main

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for version calculation

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Generate version and tags
id: meta
run: |
# Convert repository name to lowercase
IMAGE_NAME_LOWER=$(echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" | tr '[:upper:]' '[:lower:]')

# Get current date for version generation
DATE=$(date +'%Y%m%d')

# Generate version based on context
if [[ $GITHUB_REF == refs/tags/v* ]]; then
# If this is a tag push, use the tag as version
VERSION=${GITHUB_REF#refs/tags/v}
TAGS="${IMAGE_NAME_LOWER}:${VERSION},${IMAGE_NAME_LOWER}:latest"
elif [[ $GITHUB_REF == refs/heads/main ]]; then
# If this is main branch, generate auto-incrementing version
# Get count of commits to main for auto-incrementing
COMMIT_COUNT=$(git rev-list --count HEAD)
SHORT_SHA=${GITHUB_SHA::8}

# Generate semantic version: 1.0.COMMIT_COUNT-DATE
VERSION="1.0.${COMMIT_COUNT}"
TAGS="${IMAGE_NAME_LOWER}:${VERSION},${IMAGE_NAME_LOWER}:latest,${IMAGE_NAME_LOWER}:${DATE}-${SHORT_SHA}"
else
# For pull requests or other branches
SHORT_SHA=${GITHUB_SHA::8}
VERSION="pr-${SHORT_SHA}"
TAGS="${IMAGE_NAME_LOWER}:${VERSION}"
fi

echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
echo "TAGS=${TAGS}" >> $GITHUB_OUTPUT
echo "IMAGE_NAME_LOWER=${IMAGE_NAME_LOWER}" >> $GITHUB_OUTPUT

# Print for debugging
echo "Generated version: ${VERSION}"
echo "Generated tags: ${TAGS}"

- name: Extract metadata
id: docker_meta
uses: docker/metadata-action@v5
with:
images: ${{ steps.meta.outputs.IMAGE_NAME_LOWER }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=${{ steps.meta.outputs.VERSION }}
type=raw,value=latest,enable={{is_default_branch}}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Generate summary
if: github.event_name != 'pull_request'
run: |
echo "## 🐳 Docker Image Published" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version:** ${{ steps.meta.outputs.VERSION }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Registry:** ${{ env.REGISTRY }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Tags:**" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "${{ steps.docker_meta.outputs.tags }}" | tr ',' '\n' >> $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 ${{ steps.meta.outputs.IMAGE_NAME_LOWER }}:${{ steps.meta.outputs.VERSION }}" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
155 changes: 155 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
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'
- 'example/**'

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 "v0.0.0")
echo "Last tag: $LAST_TAG"
# Check if there are changes in source code since last release
if git diff --quiet $LAST_TAG HEAD -- '*.go' 'go.mod' 'go.sum' 'Dockerfile' '.github/workflows/' 'internal/' 'cmd/'; 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 "v0.0.0")
echo "Last tag: $LAST_TAG"
# 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}
# 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
COMMITS=$(git log $LAST_TAG..HEAD --oneline)
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
create-release:
needs: check-changes
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: 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" > changelog.md
echo "" >> changelog.md
echo "πŸŽ‰ First release of Labelarr!" >> changelog.md
echo "" >> changelog.md
echo "### Features" >> changelog.md
echo "- 🎬 Movie library processing with TMDb integration" >> changelog.md
echo "- πŸ“Ί TV show library processing with TMDb integration" >> changelog.md
echo "- 🏷️ Smart label/genre management" >> changelog.md
echo "- 🐳 Docker container with multi-architecture support" >> changelog.md
fi
echo "" >> changelog.md
echo "### Docker Image" >> changelog.md
echo '```bash' >> changelog.md
echo "docker pull ghcr.io/${{ github.repository_owner }}/$(echo '${{ github.repository }}' | cut -d'/' -f2):${{ needs.check-changes.outputs.version }}" >> changelog.md
echo '```' >> 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
draft: false
prerelease: false
generate_release_notes: true
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ COPY . .
RUN go mod download

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

# Runtime stage
FROM alpine:latest
Expand Down
Loading