Merge pull request #68 from troykelly/67-fix-bad-lexicon #53
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Publish Docker Images | |
on: | |
push: | |
branches: | |
- main | |
release: | |
types: [published] | |
permissions: | |
contents: read | |
packages: write | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
id: buildx | |
- 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 version information | |
if: github.event_name == 'release' | |
id: version | |
run: | | |
echo "Extracting version from release tag" | |
version=$(echo "${{ github.event.release.tag_name }}" | grep -oE '^v?[0-9]+\.[0-9]+\.[0-9]+$' | tr -d 'v') | |
if [ -z "$version" ]; then | |
echo "Could not extract version from tag: ${{ github.event.release.tag_name }}" | |
exit 1 | |
fi | |
sed -i "s/VERSION = \"__VERSION__\"/VERSION = \"${version}\"/" src/main.py | |
echo "version=$version" >> $GITHUB_ENV | |
major=$(echo $version | cut -d. -f1) | |
minor=$(echo $version | cut -d. -f2) | |
patch=$(echo $version | cut -d. -f3) | |
echo "major=$major" >> $GITHUB_ENV | |
echo "minor=$minor" >> $GITHUB_ENV | |
echo "patch=$patch" >> $GITHUB_ENV | |
- name: Get current commit SHA | |
id: git_sha | |
run: echo "sha=$(git rev-parse HEAD)" >> $GITHUB_ENV | |
- name: Extract repository details | |
id: extract_repo | |
run: | | |
REPO_NAME=$(echo "${{ github.repository }}" | awk -F/ '{print $2}') | |
REPO_URL="https://github.com/${{ github.repository }}" | |
echo "repo_name=$REPO_NAME" >> $GITHUB_ENV | |
echo "repo_url=$REPO_URL" >> $GITHUB_ENV | |
- name: Build and push Docker image (main or release) | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: ./Dockerfile | |
builder: ${{ steps.buildx.outputs.name }} | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
labels: | | |
org.opencontainers.image.revision=${{ env.sha }} | |
org.opencontainers.image.created=$GITHUB_EVENT_DATETIME | |
build-args: | | |
BUILD_DATE=$GITHUB_EVENT_DATETIME | |
VCS_REF=${{ env.sha }} | |
VERSION=${{ github.event_name == 'release' && env.version || 'latest' }} | |
REPO_URL=${{ env.repo_url }} | |
tags: | | |
${{ github.event_name == 'release' && github.event.release.tag_name != '' && format('ghcr.io/{0}/{1}:latest', github.repository_owner, env.repo_name) || '' }} | |
${{ github.event_name == 'release' && github.event.release.tag_name != '' && format('ghcr.io/{0}/{1}:{2}', github.repository_owner, env.repo_name, github.event.release.tag_name) || '' }} | |
${{ github.event_name == 'release' && github.event.release.tag_name != '' && format('ghcr.io/{0}/{1}:{2}', github.repository_owner, env.repo_name, env.version) || '' }} | |
${{ github.event_name == 'release' && github.event.release.tag_name != '' && format('ghcr.io/{0}/{1}:{2}', github.repository_owner, env.repo_name, env.major) || '' }} | |
${{ github.event_name == 'release' && github.event.release.tag_name != '' && format('ghcr.io/{0}/{1}:{2}.{3}', github.repository_owner, env.repo_name, env.major, env.minor) || '' }} | |
${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && format('ghcr.io/{0}/{1}:edge', github.repository_owner, env.repo_name) || '' }} | |
outputs: type=image,name=ghcr.io/${{ github.repository_owner }}/${{ env.repo_name }},annotation-index.org.opencontainers.image.description=Extracts media from Emby and syncs to AzuraCast | |
- name: Create release artifact | |
if: github.event_name == 'release' | |
run: | | |
mkdir -p release | |
cp -r src release/ | |
cd release | |
tar -czf ../release_${{ env.version }}.tar.gz . | |
- name: Upload release artifact | |
if: github.event_name == 'release' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: release_${{ env.version }}.tar.gz | |
path: release_${{ env.version }}.tar.gz | |
retention-days: 5 |