mirror of
https://github.com/FoxxMD/multi-scrobbler.git
synced 2026-05-05 07:11:45 +00:00
* Ensure pre-release tags don't also get latest tag * Disable alpine builds * Only increases testing and build complexity and there has been no feedback from users about needing it
133 lines
4.5 KiB
YAML
133 lines
4.5 KiB
YAML
name: Publish Docker image to Dockerhub
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
push:
|
|
branches:
|
|
- 'master'
|
|
tags:
|
|
- '*.*.*'
|
|
# don't trigger if just updating docs
|
|
paths-ignore:
|
|
- 'README.md'
|
|
- '.github/**'
|
|
- 'flatpak/**'
|
|
# use release instead of tags once version is correctly parsed
|
|
# https://github.com/docker/metadata-action/issues/422
|
|
# https://github.com/docker/metadata-action/issues/240
|
|
# release:
|
|
# types: [ published ]
|
|
|
|
jobs:
|
|
test:
|
|
name: Run Tests
|
|
if: github.event_name != 'pull_request'
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Check out the repo
|
|
uses: actions/checkout@v4
|
|
- name: Use Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '18.x'
|
|
cache: 'npm'
|
|
- name: Install dev dependencies
|
|
run: npm ci
|
|
- name: Build Backend
|
|
run: 'npm run build:backend'
|
|
- name: Test Backend
|
|
run: npm run test
|
|
|
|
push_to_registry:
|
|
name: Build and push container images
|
|
if: github.event_name != 'pull_request'
|
|
runs-on: ubuntu-latest
|
|
needs: test
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
- dockerfile: ./Dockerfile
|
|
suffix: ''
|
|
platforms: 'linux/amd64,linux/arm64'
|
|
# - dockerfile: ./alpine.Dockerfile
|
|
# suffix: '-alpine'
|
|
# platforms: 'linux/amd64,linux/arm64'
|
|
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
|
|
permissions:
|
|
packages: write
|
|
contents: read
|
|
steps:
|
|
- name: Check out the repo
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set short git commit SHA
|
|
id: vars
|
|
# https://dev.to/hectorleiva/github-actions-and-creating-a-short-sha-hash-8b7
|
|
# short sha available under env.COMMIT_SHORT_SHA
|
|
run: |
|
|
calculatedSha=$(git rev-parse --short HEAD)
|
|
branchName=$(git rev-parse --abbrev-ref HEAD)
|
|
echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV
|
|
echo "COMMIT_BRANCH=$branchName" >> $GITHUB_ENV
|
|
|
|
- name: Log in to Docker Hub
|
|
uses: docker/login-action@v3
|
|
with:
|
|
username: ${{ secrets.DOCKER_USERNAME }}
|
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
|
|
|
- name: Login to GitHub Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.repository_owner }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Extract metadata (tags, labels) for Docker
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: |
|
|
foxxmd/multi-scrobbler
|
|
ghcr.io/foxxmd/multi-scrobbler
|
|
# generate Docker tags based on the following events/attributes
|
|
# https://github.com/docker/metadata-action/issues/247#issuecomment-1511259674 for NOT is default branch, eventually
|
|
tags: |
|
|
type=edge
|
|
type=ref,event=branch,enable=${{ !endsWith(github.ref, 'master') }}
|
|
|
|
# tag non-prelease as latest -- has a higher priority than regular tag so it shows first in registries
|
|
type=semver,pattern={{major}}.{{minor}}.{{patch}},value=latest,priority=901
|
|
|
|
# tag all semver (include pre-release)
|
|
type=semver,pattern={{version}}
|
|
flavor: |
|
|
latest=false
|
|
# suffix=${{ matrix.suffix }},onlatest=false
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Build and push Docker image
|
|
env:
|
|
# use release instead of tags once version is correctly parsed
|
|
#APP_VERSION: ${{ github.event.release.tag_name }}
|
|
|
|
# https://github.com/actions/runner/issues/409#issuecomment-752775072
|
|
# https://stackoverflow.com/a/69919067/1469797
|
|
APP_VERSION: ${{ contains(github.ref, 'refs/tags/') && github.ref_name || format('{0}-{1}', env.COMMIT_BRANCH, env.COMMIT_SHORT_SHA ) }}
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
# https://github.com/docker/build-push-action/issues/1026#issue-2041857786
|
|
build-args: |
|
|
APP_BUILD_VERSION=${{env.APP_VERSION}}
|
|
file: ${{ matrix.dockerfile }}
|
|
push: ${{ !env.ACT}}
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
platforms: ${{ matrix.platforms }}
|