Skip to content

Docker Image CI

Docker Image CI #322

Workflow file for this run

name: Docker Image CI
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
push:
branches: [ "master" ]
paths-ignore:
- '**/README.md'
- 'Ubuntu/**'
- '.github/**'
- '.gitattributes'
- '.gitignore'
jobs:
build-and-push:
runs-on: ubuntu-latest
outputs:
release_exists: ${{ steps.check_release.outputs.release_exists }}
version: ${{ steps.extract_version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: 'all'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract version from main.py
id: extract_version
run: |
VERSION=$(grep -Po "(?<=version = ')[^']+" main.py)
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Set environment variables
run: |
echo "REPO_OWNER_LOWER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
echo "REPO_NAME=$(echo ${{ github.repository }} | cut -d'/' -f2 | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Login 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.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push to Docker Hub and GitHub Registry
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
tags: |
${{ secrets.DOCKER_USERNAME }}/${{ env.REPO_NAME }}:${{ env.VERSION }}
${{ secrets.DOCKER_USERNAME }}/${{ env.REPO_NAME }}:latest
ghcr.io/${{ env.REPO_OWNER_LOWER }}/${{ env.REPO_NAME }}:${{ env.VERSION }}
ghcr.io/${{ env.REPO_OWNER_LOWER }}/${{ env.REPO_NAME }}:latest
- name: Check if Release Exists
id: check_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if gh release view ${{ steps.extract_version.outputs.version }} --repo ${{ github.repository }}; then
echo "Release already exists for version ${{ steps.extract_version.outputs.version }}"
echo "release_exists=true" >> $GITHUB_ENV
echo "release_exists=true" >> $GITHUB_OUTPUT
else
echo "Release does not exist for version ${{ steps.extract_version.outputs.version }}"
echo "release_exists=false" >> $GITHUB_ENV
echo "release_exists=false" >> $GITHUB_OUTPUT
fi
- name: Create Release with CHANGELOG Notes
if: steps.check_release.outputs.release_exists == 'false'
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
RELEASE_NOTES=$(awk '/^## Version \[${{ steps.extract_version.outputs.version }}\]/ {flag=1; next} /^## Version \[/ {flag=0} flag' CHANGELOG.md)
gh release create ${{ steps.extract_version.outputs.version }} \
--repo ${{ github.repository }} \
--title "Release ${{ steps.extract_version.outputs.version }}" \
--notes "$RELEASE_NOTES" \
--draft=false \
--prerelease=false
announce:
needs: build-and-push
if: needs.build-and-push.outputs.release_exists == 'false'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Post announcement to Discord
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
VERSION: ${{ needs.build-and-push.outputs.version }}
run: |
RELEASE_NOTES=$(awk '/^## Version \[${{ env.VERSION }}\]/ {flag=1; next} /^## Version \[/ {flag=0} flag' CHANGELOG.md)
ANNOUNCEMENT_BODY="🚀 **New Release: Version [${{ env.VERSION }}]**${RELEASE_NOTES}"
ESCAPED_BODY=$(echo "$ANNOUNCEMENT_BODY" | jq -Rsa .)
curl -H "Content-Type: application/json" \
-d "{\"content\": $ESCAPED_BODY, \"flags\": 4}" \
$DISCORD_WEBHOOK_URL