Skip to content

feat: add github action for docker release #4

feat: add github action for docker release

feat: add github action for docker release #4

Workflow file for this run

name: Release and Publish
on:
push:
branches:
- feat-docker
# paths:
# - Cargo.toml
permissions:
contents: write
jobs:
tag_and_release:
name: Tag and Release
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version_and_release.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Fetch tags
run: git fetch --tags
- name: Extract version, tag, and release
id: version_and_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION=$(grep -m1 '^version\s*=\s*"' Cargo.toml | sed 's/^[^\"]*\"\([^\"]*\)\"/\1/')
if [ -z "$VERSION" ]; then
echo "Failed to obtain version from Cargo.toml" >&2
exit 1
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
if git rev-parse -q --verify "refs/tags/v$VERSION" >/dev/null; then
echo "Tag v$VERSION already exists; skipping creation." >&2
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag -a "v$VERSION" -m "Release v$VERSION"
git push origin "v$VERSION"
gh release create "v$VERSION" --generate-notes
publish_docker:
name: Publish Docker Image
runs-on: ubuntu-latest
needs: tag_and_release
env:
DOCKER_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/fotobot
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: |
${{ env.DOCKER_IMAGE }}:${{ needs.tag_and_release.outputs.version }}
${{ env.DOCKER_IMAGE }}:latest