Skip to content

Merge pull request #196 from ptr727/dependabot/nuget/Microsoft.NET.Te… #140

Merge pull request #196 from ptr727/dependabot/nuget/Microsoft.NET.Te…

Merge pull request #196 from ptr727/dependabot/nuget/Microsoft.NET.Te… #140

name: Build and push docker images
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
workflow_dispatch:
schedule:
- cron: '0 2 * * MON'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
# Test
test:
name: Test
runs-on: ubuntu-latest
steps:
# Install .NET SDK
# https://github.com/marketplace/actions/setup-net-core-sdk
- name: Setup .NET SDK 7
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.x
# Checkout code
# https://github.com/marketplace/actions/checkout
- name: Checkout code
uses: actions/checkout@v3
# Run Unit Tests
# https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test
- name: Run unit tests
run: dotnet test ./PlexCleanerTests/PlexCleanerTests.csproj
# Get version information
version:
name: Version
runs-on: ubuntu-latest
needs: test
outputs:
SemVer2: ${{ steps.nbgv.outputs.SemVer2 }}
AssemblyVersion: ${{ steps.nbgv.outputs.AssemblyVersion }}
AssemblyFileVersion: ${{ steps.nbgv.outputs.AssemblyFileVersion }}
AssemblyInformationalVersion: ${{ steps.nbgv.outputs.AssemblyInformationalVersion }}
steps:
# Checkout code
# https://github.com/marketplace/actions/checkout
- name: Checkout
uses: actions/checkout@v3
with:
# Get all history for version calculation
fetch-depth: 0
# Run Nerdbank.GitVersioning
# https://github.com/marketplace/actions/nerdbank-gitversioning
- name: Run Nerdbank.GitVersioning tool
id: nbgv
uses: dotnet/nbgv@master
# Build and push docker images
buildpush:
name: Build and push
runs-on: ubuntu-latest
needs: version
strategy:
# https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs
matrix:
include:
# Debian: linux/amd64,linux/arm64,linux/arm/v7
- file: ./Docker/Debian.dotNET.Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7
cache-scope: debian
secrets: SAVOURY_PPA_AUTH
tags: |
docker.io/ptr727/plexcleaner:${{ endsWith(github.ref, 'refs/heads/main') && 'debian' || 'debian-develop' }}
# Alpine: linux/amd64,linux/arm64
- file: ./Docker/Alpine.dotNET.Dockerfile
platforms: linux/amd64,linux/arm64
cache-scope: alpine
secrets: SAVOURY_PPA_AUTH
tags: |
docker.io/ptr727/plexcleaner:${{ endsWith(github.ref, 'refs/heads/main') && 'alpine' || 'alpine-develop' }}
# Ubuntu: linux/amd64
- file: ./Docker/Ubuntu.dotNET.Savoury.Dockerfile
platforms: linux/amd64
cache-scope: savoury
secrets: SAVOURY_PPA_AUTH
tags: |
docker.io/ptr727/plexcleaner:${{ endsWith(github.ref, 'refs/heads/main') && 'savoury' || 'savoury-develop' }}
docker.io/ptr727/plexcleaner:${{ endsWith(github.ref, 'refs/heads/main') && 'latest' || 'develop' }}
docker.io/ptr727/plexcleaner:${{ needs.version.outputs.SemVer2 }}
# Arch: linux/amd64
- file: ./Docker/Arch.Dockerfile
platforms: linux/amd64
cache-scope: arch
secrets: SAVOURY_PPA_AUTH
tags: |
docker.io/ptr727/plexcleaner:${{ endsWith(github.ref, 'refs/heads/main') && 'arch' || 'arch-develop' }}
steps:
# Checkout code
# https://github.com/marketplace/actions/checkout
- name: Checkout
uses: actions/checkout@v3
# Setup QEMU for multi architecture builds
# https://github.com/marketplace/actions/docker-setup-qemu
- name: Setup QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: linux/amd64,linux/arm64,linux/arm/v7
# Setup docker build
# https://github.com/marketplace/actions/docker-setup-buildx
- name: Setup Buildx
uses: docker/setup-buildx-action@v2
with:
platforms: linux/amd64,linux/arm64,linux/arm/v7
# Login to Docker Hub
# https://github.com/marketplace/actions/docker-login
- name: Login to Docker Hub
if: ${{ github.event_name != 'pull_request' }}
uses: docker/login-action@v2
with:
registry: docker.io
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
# Docker build and push
# https://github.com/marketplace/actions/build-and-push-docker-images
# https://docs.docker.com/build/ci/github-actions/cache/
# https://github.com/moby/buildkit#github-actions-cache-experimental
# Matrix build
- name: Docker build and push
uses: docker/build-push-action@v4
with:
context: .
# GitHub cache as unreliable as posting to GHCR, broken pipe errors
# cache-from: type=gha,scope=${{ matrix.cache-scope }}
# cache-to: type=gha,mode=max,scope=${{ matrix.cache-scope }}
file: ${{ matrix.file }}
push: ${{ (github.event_name != 'pull_request') }}
# TODO: How to test for secret not null and avoid "null= is not a valid secret"
secrets: ${{ matrix.secrets }}=${{ secrets[matrix.secrets] }}
tags: ${{ matrix.tags }}
platforms: ${{ matrix.platforms }}
build-args: |
LABEL_VERSION=${{ needs.version.outputs.SemVer2 }}
BUILD_CONFIGURATION=${{ endsWith(github.ref, 'refs/heads/main') && 'Release' || 'Debug' }}
BUILD_VERSION=${{ needs.version.outputs.AssemblyVersion }}
BUILD_FILE_VERSION=${{ needs.version.outputs.AssemblyFileVersion }}
BUILD_ASSEMBLY_VERSION=${{ needs.version.outputs.AssemblyFileVersion }}
BUILD_INFORMATION_VERSION=${{ needs.version.outputs.AssemblyInformationalVersion }}
BUILD_PACKAGE_VERSION=${{ needs.version.outputs.SemVer2 }}
# Get tool versions in image
toolversions:
name: Tool versions
runs-on: ubuntu-latest
needs: buildpush
if: ${{ github.event_name != 'pull_request' }}
strategy:
# https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs
matrix:
include:
- tag: ${{ endsWith(github.ref, 'refs/heads/main') && 'debian' || 'debian-develop' }}
file: debian.ver
- tag: ${{ endsWith(github.ref, 'refs/heads/main') && 'alpine' || 'alpine-develop' }}
file: alpine.ver
- tag: ${{ endsWith(github.ref, 'refs/heads/main') && 'savoury' || 'savoury-develop' }}
file: savoury.ver
- tag: ${{ endsWith(github.ref, 'refs/heads/main') && 'arch' || 'arch-develop' }}
file: arch.ver
steps:
# https://github.com/marketplace/actions/checkout
- name: Checkout
uses: actions/checkout@v3
# https://github.com/marketplace/actions/docker-run-action
- name: Write image tool versions to file
uses: addnab/docker-run-action@v3
with:
image: docker.io/ptr727/plexcleaner:${{ matrix.tag }}
options: --volume ${{ runner.temp }}/versions:/versions
run: |
echo PlexCleaner: $(/PlexCleaner/PlexCleaner --version) > /versions/${{ matrix.file }}
echo dotNET: $(dotnet --version) >> /versions/${{ matrix.file }}
echo HandBrakeCLI: $(HandBrakeCLI --version) >> /versions/${{ matrix.file }}
echo MediaInfo: $(mediainfo --version) >> /versions/${{ matrix.file }}
echo MkvMerge: $(mkvmerge --version) >> /versions/${{ matrix.file }}
echo FfMpeg: $(ffmpeg -version) >> /versions/${{ matrix.file }}
- name: Print versions
run: cat ${{ runner.temp }}/versions/${{ matrix.file }}
# https://github.com/marketplace/actions/upload-a-build-artifact
- name: Upload version artifacts
uses: actions/upload-artifact@v3
with:
name: versions
path: ${{ runner.temp }}/versions/${{ matrix.file }}
# Update Docker README.md
updatereadme:
name: Create README.md
runs-on: ubuntu-latest
needs: toolversions
if: ${{ github.event_name != 'pull_request' }}
steps:
# https://github.com/marketplace/actions/checkout
- name: Checkout
uses: actions/checkout@v3
# https://github.com/marketplace/actions/download-a-build-artifact
- name: Download version artifacts
uses: actions/download-artifact@v3
with:
name: versions
path: ${{ runner.temp }}/versions
- name: Create README.md from README.m4
run: m4 --include=${{ runner.temp }}/versions ./Docker/README.m4 > ./Docker/README.md
# https://github.com/marketplace/actions/git-auto-commit
- name: Commit generated README.md
uses: stefanzweifel/git-auto-commit-action@v4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
file_pattern: ./Docker/README.md
commit_message: Update generated README.md
# Update Docker Hub description
hubdescription:
name: Update README.md
runs-on: ubuntu-latest
needs: updatereadme
if: ${{ github.event_name != 'pull_request' }}
steps:
# Checkout code
# https://github.com/marketplace/actions/checkout
- name: Checkout
uses: actions/checkout@v3
# https://github.com/marketplace/actions/docker-hub-description
- name: Update Docker Hub README.md
uses: peter-evans/dockerhub-description@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
repository: ptr727/plexcleaner
short-description: ${{ github.event.repository.description }}
readme-filepath: ./Docker/README.md
# Create a custom badge to report the build date
datebadge:
name: Date badge
runs-on: ubuntu-latest
needs: buildpush
if: ${{ github.event_name != 'pull_request' }}
steps:
# Get date from environment as a variable
- id: date
run: |
echo "date=$(date)" >> $GITHUB_OUTPUT
# Create badge
# https://github.com/marketplace/actions/bring-your-own-badge
- name: Build date badge
uses: RubbaBoy/BYOB@v1
with:
name: lastbuild
label: "Last Build"
icon: "github"
status: ${{ steps.date.outputs.date }}
color: "blue"
github_token: ${{ secrets.GITHUB_TOKEN }}