feat: Add git tagging and remove emojis from Gitea Actions workflows
- Add automatic git tag creation after successful builds/deployments - Tags match VERSION file and include deployment metadata - Remove emojis from all Discord notifications and console output - Add git tag links to Discord success notifications - Update troubleshooting section with git tag issues - Add customization checklist for git email configuration Benefits: - Immutable version markers in git history - Easy version checkout and rollback (git checkout v1.2.3) - Clean, professional notification messages - Enable changelog generation between tags Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
744be40ced
commit
201aa9ee32
@ -1,12 +1,14 @@
|
||||
# Gitea Actions: Docker Build, Push, and Notify
|
||||
# Gitea Actions: Docker Build, Push, Tag, and Notify
|
||||
#
|
||||
# This workflow provides a complete CI/CD pipeline for Docker-based projects:
|
||||
# - Validates semantic versioning on PRs
|
||||
# - Builds Docker images on every push/PR
|
||||
# - Pushes to Docker Hub on main branch merges
|
||||
# - Creates git tags for releases
|
||||
# - Sends Discord notifications on success/failure
|
||||
#
|
||||
# Template created: 2026-02-04
|
||||
# Updated: 2026-02-05 (added git tagging)
|
||||
# For: Paper Dynasty Discord bot (reference implementation)
|
||||
|
||||
name: Build Docker Image
|
||||
@ -58,7 +60,7 @@ jobs:
|
||||
git fetch origin main:main
|
||||
MAIN_VERSION=$(git show main:VERSION 2>/dev/null || echo "0.0.0")
|
||||
|
||||
echo "📋 Semantic Version Check"
|
||||
echo "Semantic Version Check"
|
||||
echo "Main branch version: $MAIN_VERSION"
|
||||
echo "PR branch version: $PR_VERSION"
|
||||
echo ""
|
||||
@ -77,7 +79,7 @@ jobs:
|
||||
|
||||
# Check if VERSION unchanged
|
||||
if [ "$PR_VERSION" = "$MAIN_VERSION" ]; then
|
||||
echo "❌ ERROR: VERSION file has not been updated!"
|
||||
echo "ERROR: VERSION file has not been updated!"
|
||||
echo ""
|
||||
echo "Please update the VERSION file in your PR."
|
||||
echo "Current version: $MAIN_VERSION"
|
||||
@ -103,9 +105,9 @@ jobs:
|
||||
fi
|
||||
|
||||
if [ "$VALID" = true ]; then
|
||||
echo "✅ Valid $BUMP_TYPE version bump: $MAIN_VERSION → $PR_VERSION"
|
||||
echo "Valid $BUMP_TYPE version bump: $MAIN_VERSION → $PR_VERSION"
|
||||
else
|
||||
echo "❌ ERROR: Invalid semantic version change!"
|
||||
echo "ERROR: Invalid semantic version change!"
|
||||
echo ""
|
||||
echo "Current version: $MAIN_VERSION"
|
||||
echo "PR version: $PR_VERSION"
|
||||
@ -116,9 +118,9 @@ jobs:
|
||||
echo " - Major: $((MAIN_MAJOR + 1)).0.0"
|
||||
echo ""
|
||||
echo "Common issues:"
|
||||
echo " ❌ Skipping versions (e.g., 2.5.0 → 2.7.0)"
|
||||
echo " ❌ Going backwards (e.g., 2.5.0 → 2.4.0)"
|
||||
echo " ❌ Not resetting lower components (e.g., 2.5.0 → 2.6.1)"
|
||||
echo " - Skipping versions (e.g., 2.5.0 → 2.7.0)"
|
||||
echo " - Going backwards (e.g., 2.5.0 → 2.4.0)"
|
||||
echo " - Not resetting lower components (e.g., 2.5.0 → 2.6.1)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@ -207,7 +209,7 @@ jobs:
|
||||
#
|
||||
- name: Build Summary
|
||||
run: |
|
||||
echo "## 🐳 Docker Build Successful! ✅" >> $GITHUB_STEP_SUMMARY
|
||||
echo "## Docker Build Successful" >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
echo "**Image Tags:**" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- \`yourusername/yourrepo:latest\`" >> $GITHUB_STEP_SUMMARY
|
||||
@ -220,7 +222,7 @@ jobs:
|
||||
echo "- Timestamp: \`${{ steps.meta.outputs.timestamp }}\`" >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
|
||||
echo "🚀 **Pushed to Docker Hub!**" >> $GITHUB_STEP_SUMMARY
|
||||
echo "**Pushed to Docker Hub**" >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
echo "Pull with: \`docker pull yourusername/yourrepo:latest\`" >> $GITHUB_STEP_SUMMARY
|
||||
else
|
||||
@ -228,7 +230,44 @@ jobs:
|
||||
fi
|
||||
|
||||
# ==============================================
|
||||
# 8. DISCORD NOTIFICATION - SUCCESS
|
||||
# 8. CREATE GIT TAG
|
||||
# ==============================================
|
||||
# Creates immutable git tag after successful build
|
||||
# - Only tags when pushed to Docker Hub (main branch)
|
||||
# - Tag matches VERSION file (single source of truth)
|
||||
# - Enables version history: git tag -l
|
||||
# - Allows version checkout: git checkout v1.2.3
|
||||
# - Can trigger additional workflows (releases, changelogs)
|
||||
#
|
||||
# Note: If using deployment workflow, you may want to move
|
||||
# tagging to after successful deployment instead of after build
|
||||
#
|
||||
- name: Create Git Tag
|
||||
if: success() && github.ref == 'refs/heads/main'
|
||||
run: |
|
||||
VERSION=$(cat VERSION)
|
||||
|
||||
# Configure git
|
||||
git config user.name "Gitea Actions"
|
||||
git config user.email "actions@git.manticorum.com"
|
||||
|
||||
# Create annotated tag with build info
|
||||
git tag -a "v${VERSION}" -m "Release v${VERSION}
|
||||
|
||||
Built: ${{ steps.meta.outputs.timestamp }}
|
||||
Commit: ${{ github.sha }}
|
||||
Author: ${{ github.actor }}
|
||||
|
||||
Docker image: yourusername/yourrepo:v${VERSION}
|
||||
Built and tagged via Gitea Actions"
|
||||
|
||||
# Push tag to repository
|
||||
git push origin "v${VERSION}"
|
||||
|
||||
echo "Created and pushed tag v${VERSION}"
|
||||
|
||||
# ==============================================
|
||||
# 9. DISCORD NOTIFICATION - SUCCESS
|
||||
# ==============================================
|
||||
# Sends green embed to Discord on successful builds
|
||||
#
|
||||
@ -251,8 +290,8 @@ jobs:
|
||||
curl -H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"embeds": [{
|
||||
"title": "✅ Your Project Build Successful",
|
||||
"description": "Docker image built and pushed to Docker Hub!",
|
||||
"title": "Your Project Build Successful",
|
||||
"description": "Docker image built, tagged, and pushed to Docker Hub",
|
||||
"color": 3066993,
|
||||
"fields": [
|
||||
{
|
||||
@ -260,6 +299,11 @@ jobs:
|
||||
"value": "`v${{ steps.meta.outputs.version }}`",
|
||||
"inline": true
|
||||
},
|
||||
{
|
||||
"name": "Git Tag",
|
||||
"value": "[v${{ steps.meta.outputs.version }}](${{ github.server_url }}/${{ github.repository }}/releases/tag/v${{ steps.meta.outputs.version }})",
|
||||
"inline": true
|
||||
},
|
||||
{
|
||||
"name": "Image Tag",
|
||||
"value": "`${{ steps.meta.outputs.version_sha }}`",
|
||||
@ -297,7 +341,7 @@ jobs:
|
||||
YOUR_DISCORD_WEBHOOK_URL_HERE
|
||||
|
||||
# ==============================================
|
||||
# 9. DISCORD NOTIFICATION - FAILURE
|
||||
# 10. DISCORD NOTIFICATION - FAILURE
|
||||
# ==============================================
|
||||
# Sends red embed to Discord on build failures
|
||||
#
|
||||
@ -314,8 +358,8 @@ jobs:
|
||||
curl -H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"embeds": [{
|
||||
"title": "❌ Your Project Build Failed",
|
||||
"description": "Docker build encountered an error.",
|
||||
"title": "Your Project Build Failed",
|
||||
"description": "Docker build encountered an error",
|
||||
"color": 15158332,
|
||||
"fields": [
|
||||
{
|
||||
@ -349,9 +393,10 @@ jobs:
|
||||
# ==============================================
|
||||
# Before using this template in a new project:
|
||||
#
|
||||
# ✅ Replace "yourusername/yourrepo" with your Docker Hub repository
|
||||
# ✅ Replace "yourusername/yourrepo" with your Docker Hub repository (3 locations)
|
||||
# ✅ Replace "Your Project" in Discord notification titles
|
||||
# ✅ Replace Discord webhook URLs (both success and failure)
|
||||
# ✅ Replace git config email in Create Git Tag step
|
||||
# ✅ Add secrets to Gitea repo: DOCKERHUB_USERNAME, DOCKERHUB_TOKEN
|
||||
# ✅ Create VERSION file in repo root with initial version (e.g., "1.0.0")
|
||||
# ✅ Update branch name if not using "main"
|
||||
@ -360,7 +405,7 @@ jobs:
|
||||
# - Adjust runner labels (runs-on) if using self-hosted runners
|
||||
# - Modify version validation rules if you don't want strict semver
|
||||
# - Add additional notification channels (Slack, email, etc.)
|
||||
# - Add deployment steps after Docker push
|
||||
# - Move git tagging to after deployment if using deployment workflow
|
||||
# - Customize Discord embed colors, fields, or formatting
|
||||
#
|
||||
# ==============================================
|
||||
@ -378,13 +423,21 @@ jobs:
|
||||
# - Check Docker Hub token has push permissions
|
||||
# - Ensure repository name matches your Docker Hub repo exactly
|
||||
#
|
||||
# 3. Discord notifications not appearing
|
||||
# 3. Git tag push failing
|
||||
# - Error "tag already exists": You're trying to release the same version twice
|
||||
# Solution: Bump VERSION file to next version
|
||||
# - Error "permission denied": Gitea Actions may not have push permissions
|
||||
# Solution: Check repo settings → Actions → Allow push to repository
|
||||
# - Tag created but not visible: Check you pushed to correct remote
|
||||
# Solution: Verify with "git ls-remote --tags origin"
|
||||
#
|
||||
# 4. Discord notifications not appearing
|
||||
# - Test webhook URL manually with curl
|
||||
# - Check webhook still exists in Discord channel settings
|
||||
# - Verify timestamp format is ISO 8601 (YYYY-MM-DDTHH:MM:SSZ)
|
||||
# - Look for HTTP error codes in Actions logs
|
||||
#
|
||||
# 4. Build cache not working
|
||||
# 5. Build cache not working
|
||||
# - GitHub Actions cache is stored per repository
|
||||
# - Cache is shared across branches
|
||||
# - May need to clear cache if corrupted
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
chmod 600 ~/.ssh/deploy_key
|
||||
ssh-keyscan -H ${{ secrets.PRODUCTION_HOST }} >> ~/.ssh/known_hosts
|
||||
|
||||
echo "🚀 Deploying Paper Dynasty v${{ steps.meta.outputs.version }} to production..."
|
||||
echo "Deploying Paper Dynasty v${{ steps.meta.outputs.version }} to production..."
|
||||
DEPLOY_START=$(date +%s)
|
||||
|
||||
# Deploy with health check and rollback
|
||||
@ -29,28 +29,28 @@
|
||||
echo "Current image: $CURRENT_IMAGE"
|
||||
|
||||
# Pull new image
|
||||
echo "📥 Pulling new image..."
|
||||
echo "Pulling new image..."
|
||||
docker compose pull
|
||||
|
||||
# Stop old container
|
||||
echo "🛑 Stopping old container..."
|
||||
echo "Stopping old container..."
|
||||
docker compose down
|
||||
|
||||
# Start new container
|
||||
echo "▶️ Starting new container..."
|
||||
echo "Starting new container..."
|
||||
docker compose up -d
|
||||
|
||||
# Health check with retry
|
||||
echo "🏥 Running health check..."
|
||||
echo "Running health check..."
|
||||
for i in {1..10}; do
|
||||
sleep 3
|
||||
if docker compose ps | grep -q "Up"; then
|
||||
echo "✅ Container is up!"
|
||||
echo "Container is up!"
|
||||
|
||||
# Additional health check: check bot is responding
|
||||
# Adjust this based on your bot's health endpoint
|
||||
# if curl -f http://localhost:YOUR_PORT/health; then
|
||||
# echo "✅ Health check passed!"
|
||||
# echo "Health check passed!"
|
||||
# exit 0
|
||||
# fi
|
||||
|
||||
@ -60,7 +60,7 @@
|
||||
done
|
||||
|
||||
# If we get here, deployment failed
|
||||
echo "❌ Health check failed! Rolling back..."
|
||||
echo "Health check failed! Rolling back..."
|
||||
|
||||
# Rollback to previous image
|
||||
if [ "$CURRENT_IMAGE" != "none" ]; then
|
||||
@ -68,10 +68,10 @@
|
||||
# This assumes you have the old image still cached
|
||||
# In production, you might want to keep the last N images
|
||||
docker compose up -d
|
||||
echo "⏪ Rolled back to previous version"
|
||||
echo "Rolled back to previous version"
|
||||
exit 1
|
||||
else
|
||||
echo "⚠️ No previous image to rollback to!"
|
||||
echo "WARNING: No previous image to rollback to!"
|
||||
exit 1
|
||||
fi
|
||||
EOF
|
||||
@ -81,12 +81,45 @@
|
||||
DEPLOY_TIME=$((DEPLOY_END - DEPLOY_START))
|
||||
|
||||
if [ $DEPLOY_STATUS -eq 0 ]; then
|
||||
echo "✅ Deployment successful! (${DEPLOY_TIME}s)"
|
||||
echo "Deployment successful! (${DEPLOY_TIME}s)"
|
||||
else
|
||||
echo "❌ Deployment failed after ${DEPLOY_TIME}s"
|
||||
echo "Deployment failed after ${DEPLOY_TIME}s"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# ==============================================
|
||||
# CREATE GIT TAG - MARK DEPLOYED VERSION
|
||||
# ==============================================
|
||||
# Creates immutable git tag after successful deployment
|
||||
# - Only tags after deployment health check passes
|
||||
# - Tag matches VERSION file (single source of truth)
|
||||
# - Represents what's actually running in production
|
||||
# - Enables version history and rollback references
|
||||
#
|
||||
- name: Create Git Tag
|
||||
if: success() && github.ref == 'refs/heads/main'
|
||||
run: |
|
||||
VERSION=$(cat VERSION)
|
||||
|
||||
# Configure git
|
||||
git config user.name "Gitea Actions"
|
||||
git config user.email "actions@git.manticorum.com"
|
||||
|
||||
# Create annotated tag with deployment info
|
||||
git tag -a "v${VERSION}" -m "Release v${VERSION}
|
||||
|
||||
Deployed: ${{ steps.meta.outputs.timestamp }}
|
||||
Commit: ${{ github.sha }}
|
||||
Author: ${{ github.actor }}
|
||||
|
||||
Deployed to production and health check passed
|
||||
Built and deployed via Gitea Actions"
|
||||
|
||||
# Push tag to repository
|
||||
git push origin "v${VERSION}"
|
||||
|
||||
echo "Created and pushed tag v${VERSION}"
|
||||
|
||||
# ==============================================
|
||||
# DEPLOYMENT NOTIFICATION - SUCCESS
|
||||
# ==============================================
|
||||
@ -96,8 +129,8 @@
|
||||
curl -H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"embeds": [{
|
||||
"title": "🚀 Paper Dynasty Deployed to Production",
|
||||
"description": "New version is live and healthy!",
|
||||
"title": "Paper Dynasty Deployed to Production",
|
||||
"description": "New version is live and healthy",
|
||||
"color": 5793266,
|
||||
"fields": [
|
||||
{
|
||||
@ -105,6 +138,11 @@
|
||||
"value": "`v${{ steps.meta.outputs.version }}`",
|
||||
"inline": true
|
||||
},
|
||||
{
|
||||
"name": "Git Tag",
|
||||
"value": "[v${{ steps.meta.outputs.version }}](${{ github.server_url }}/${{ github.repository }}/releases/tag/v${{ steps.meta.outputs.version }})",
|
||||
"inline": true
|
||||
},
|
||||
{
|
||||
"name": "Deployed By",
|
||||
"value": "${{ github.actor }}",
|
||||
@ -117,7 +155,7 @@
|
||||
},
|
||||
{
|
||||
"name": "Status",
|
||||
"value": "✅ Health check passed",
|
||||
"value": "Health check passed",
|
||||
"inline": false
|
||||
}
|
||||
],
|
||||
@ -136,8 +174,8 @@
|
||||
curl -H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"embeds": [{
|
||||
"title": "⚠️ Paper Dynasty Deployment Failed",
|
||||
"description": "Deployment failed and was rolled back to previous version.",
|
||||
"title": "Paper Dynasty Deployment Failed",
|
||||
"description": "Deployment failed and was rolled back to previous version",
|
||||
"color": 16776960,
|
||||
"fields": [
|
||||
{
|
||||
@ -152,7 +190,7 @@
|
||||
},
|
||||
{
|
||||
"name": "Action",
|
||||
"value": "🔄 Rolled back to previous version",
|
||||
"value": "Rolled back to previous version",
|
||||
"inline": false
|
||||
},
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user