Files
todo/.gitea/workflows/docker-build.yml
almazlar b3f09d5dfc
Some checks failed
Release and Build Docker Images / release-and-build (push) Failing after 2m14s
feat: add deployment steps for Backend and Frontend to Dokploy
2026-02-22 18:05:39 +03:00

157 lines
5.1 KiB
YAML

name: Release and Build Docker Images
on:
push:
branches:
- main
# Allow manual trigger
workflow_dispatch:
env:
REGISTRY: git.almazlar.com
OWNER: ${{ gitea.repository_owner }}
jobs:
release-and-build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.ACCESS_TOKEN }}
- name: Git Configuration
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Generate Version and Changelog
id: generate
run: |
# 1. Fetch the latest tag
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "Latest tag: $LATEST_TAG"
# 2. Calculate the next patch version
if [[ $LATEST_TAG == v* ]]; then
VERSION_NUM=${LATEST_TAG:1}
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION_NUM"
PATCH=$((PATCH + 1))
NEW_TAG="v$MAJOR.$MINOR.$PATCH"
else
# Fallback if the tag format is unrecognized
NEW_TAG="v0.0.1"
fi
echo "New tag: $NEW_TAG"
echo "new_tag=$NEW_TAG" >> $GITHUB_OUTPUT
# 3. Create a temporary file for the new changelog entry
TEMP_CHANGELOG=$(mktemp)
DATE=$(date +'%Y-%m-%d')
echo "## [$NEW_TAG] - $DATE" > "$TEMP_CHANGELOG"
echo "" >> "$TEMP_CHANGELOG"
# Fetch all commit messages since the latest tag to HEAD
if [ "$LATEST_TAG" = "v0.0.0" ]; then
git log --pretty=format:"* %s (%h)" >> "$TEMP_CHANGELOG"
else
git log ${LATEST_TAG}..HEAD --pretty=format:"* %s (%h)" >> "$TEMP_CHANGELOG"
fi
echo "" >> "$TEMP_CHANGELOG"
echo "" >> "$TEMP_CHANGELOG"
# 4. Prepend the new entry to the existing CHANGELOG.md
if [ -f CHANGELOG.md ]; then
cat CHANGELOG.md >> "$TEMP_CHANGELOG"
fi
mv "$TEMP_CHANGELOG" CHANGELOG.md
echo "Changelog generated successfully."
- name: Commit and Push Changes
run: |
NEW_TAG=${{ steps.generate.outputs.new_tag }}
# Add the updated changelog
git add CHANGELOG.md
# Only commit if there are changes
if ! git diff-index --quiet HEAD; then
git commit -m "chore(release): bump version to $NEW_TAG and update changelog [skip ci]"
# Create the new tag
git tag -a "$NEW_TAG" -m "Release $NEW_TAG"
# Push the commit and the new tag
git push origin main
git push origin "$NEW_TAG"
else
echo "No changes to commit."
# If we haven't already tagged this commit, do it now
if ! git ls-remote --tags origin | grep -q "refs/tags/$NEW_TAG"; then
git tag -a "$NEW_TAG" -m "Release $NEW_TAG"
git push origin "$NEW_TAG"
fi
fi
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ gitea.actor }}
password: ${{ secrets.ACCESS_TOKEN }}
- name: Extract metadata (tags, labels) for Backend
id: meta-backend
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.OWNER }}/todo-backend
tags: |
type=raw,value=latest
type=raw,value=${{ steps.generate.outputs.new_tag }}
- name: Build and push Backend image
uses: docker/build-push-action@v5
with:
context: ./backend
push: true
tags: ${{ steps.meta-backend.outputs.tags }}
labels: ${{ steps.meta-backend.outputs.labels }}
build-args: |
APP_VERSION=${{ steps.generate.outputs.new_tag }}
- name: Extract metadata (tags, labels) for Frontend
id: meta-frontend
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.OWNER }}/todo-frontend
tags: |
type=raw,value=latest
type=raw,value=${{ steps.generate.outputs.new_tag }}
- name: Build and push Frontend image
uses: docker/build-push-action@v5
with:
context: ./frontend
push: true
tags: ${{ steps.meta-frontend.outputs.tags }}
labels: ${{ steps.meta-frontend.outputs.labels }}
build-args: |
VITE_APP_VERSION=${{ steps.generate.outputs.new_tag }}
VITE_BASE_URL=https://todo.almazlar.com/api
- name: Deploy to Dokploy (Backend)
run: |
curl -X POST "${{ secrets.DOKPLOY_BACKEND_WEBHOOK_URL }}"
- name: Deploy to Dokploy (Frontend)
run: |
curl -X POST "${{ secrets.DOKPLOY_FRONTEND_WEBHOOK_URL }}"