You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
recyclarr/.github/workflows/docker.yml

105 lines
3.2 KiB

# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: Docker Image
on:
push:
# Tags are explicitly ignored on push. We still want branches to be processed, but they won't if
# the `branches` property is missing. See more detail here:
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#onpushbranchestagsbranches-ignoretags-ignore
tags-ignore: ["*"]
branches: ["*"]
paths:
- docker/**
- .github/workflows/docker.yml
pull_request:
paths:
- docker/**
- .github/workflows/docker.yml
release:
types: [published]
workflow_dispatch:
inputs:
release_tag:
description: Release Tag
required: true
type: string
should_publish:
description: Publish Image to GHCR?
required: false
default: false
type: boolean
env:
SHOULD_PUBLISH: ${{ github.event_name == 'release' || inputs.should_publish == 'true' || github.event.ref == 'refs/heads/master' }}
VERSION: ${{ github.event.release.tag_name || inputs.release_tag }}
jobs:
docker:
name: Build & Push Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Buildx
uses: docker/setup-buildx-action@v2
with:
buildkitd-flags: --debug
- name: Check if tag is a version number
id: check_version
run: |
regex="[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+"
if [[ '${{ env.VERSION }}' =~ $regex ]]; then
echo '::set-output name=match::true'
else
echo '::set-output name=match::false'
fi
- name: Set Version Tags
id: meta
uses: docker/metadata-action@v4
env:
SEMVER: type=semver,enable=${{ steps.check_version.outputs.match }},value=${{ env.VERSION }}
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=edge,branch=master
${{ env.SEMVER }},pattern={{major}}.{{minor}}.{{patch}}
${{ env.SEMVER }},pattern={{major}}.{{minor}}
${{ env.SEMVER }},pattern={{major}}
- name: Enable building from source
id: info
if: ${{ github.event.ref == 'refs/heads/master' }}
run: echo '::set-output name=build_from_branch::master'
- name: Login to GHCR
if: env.SHOULD_PUBLISH
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build & Push Image
uses: docker/build-push-action@v3
with:
context: ./docker
push: ${{ env.SHOULD_PUBLISH }}
no-cache: true
build-args: |
REPOSITORY=${{ github.repository }}
${{ env.VERSION && format('RELEASE_TAG={0}', env.VERSION) }}
BUILD_FROM_BRANCH=${{ steps.info.outputs.build_from_branch }}
platforms: linux/arm/v7,linux/arm64,linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}