Skip to content

fix naming issues

fix naming issues #47

name: Build and Publish Docker Image
on:
workflow_dispatch:
push:
branches: [ '**' ]
tags: [ 'v*.*.*' ]
paths:
- 'app/**/*'
- 'Dockerfile'
- 'requirements.txt'
- '.github/workflows/docker-publish.yml'
pull_request:
branches: [ "main" ]
types: [ closed ]
paths:
- 'app/**/*'
- 'Dockerfile'
- 'requirements.txt'
- '.github/workflows/docker-publish.yml'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write # Needed for GitHub Release creation
packages: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=raw,value=latest,enable={{is_default_branch}}
type=sha
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v5
with:
context: .
target: production
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Create GitHub Release
if: startsWith(github.ref, 'refs/tags/v')
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
body: |
🚀 Docker image published for tag `${{ github.ref_name }}`
Built from commit `${{ github.sha }}`
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Discord notification
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
uses: rjstone/discord-webhook-notify@v1
with:
severity: info
username: MafenBot
color: '#ff00aa'
avatarUrl: https://github.githubassets.com/images/modules/logos_page/Octocat.png
description: A new ${{ github.event.repository.name }} image ${{ steps.meta.outputs.tags }} has been published
details: Based on ${{ github.event.head_commit.url }}
footer: MafenBot became self aware
webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}