Skip to content

Commit

Permalink
Update docker publish job
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Dec 2, 2024
1 parent 73159c9 commit 4540ed6
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ name: Create container for latest version

on:
release:
types: [published]
workflow_dispatch:
types: [released]

env:
# Use docker.io for Docker Hub if empty
Expand All @@ -17,6 +16,7 @@ env:

jobs:
build-container:
if: ${{ startsWith(github.ref, 'refs/tags/fercord_') && startsWith(github.event.release.tag_name, 'fercord_bot') }}
runs-on: ubuntu-latest
permissions:
contents: read
Expand All @@ -29,7 +29,7 @@ jobs:
uses: actions/checkout@v4
with:
fetch-tags: true
fetch-depth: 1
fetch-depth: 0

# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
Expand All @@ -42,15 +42,20 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GHCR_DEPLOY_TOKEN }}

- name: Get Latest Tag
- name: Get Tag name and version
id: latestTag
run: |
latest_tag=$(git describe --tags $(git rev-list --tags --max-count=1))
latest_tag=$(git describe --tags $(git rev-list --tags="${{ github.event.release.tag_name }}" --max-count=1))
if [ -z "$latest_tag" ]; then
echo "::error::No tags found"
exit 1
fi
IFS='-'
read -r $tag_name $tag_version << "$latest_tag"
IFS=' '
echo "tag=$latest_tag" >> "$GITHUB_OUTPUT"
echo "tagVersion=$tag_version" >> "$GITHUB_OUTPUT"
echo "tagName=$tag_name" >> "$GITHUB_OUTPUT"
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
Expand All @@ -61,7 +66,7 @@ jobs:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=${{ steps.latestTag.outputs.tag }},enable={{is_default_branch}}
type=raw,value=${{ steps.latestTag.outputs.Version }},enable={{is_default_branch}}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
Expand All @@ -71,6 +76,6 @@ jobs:
with:
context: .
file: Docker/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
push: ${{ github.event_name == 'release' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

0 comments on commit 4540ed6

Please sign in to comment.