All checks were successful
Build Docker Image / build (pull_request) Successful in 1m22s
Remove manual semver validation from PR checks. Versions are now auto-generated on merge to main by counting existing monthly tags. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
201 lines
7.9 KiB
YAML
201 lines
7.9 KiB
YAML
# Gitea Actions: Docker Build, Push, and Notify
|
|
#
|
|
# CI/CD pipeline for Paper Dynasty Discord Bot:
|
|
# - Builds Docker images on every push/PR
|
|
# - Auto-generates CalVer version (YYYY.MM.BUILD) on main branch merges
|
|
# - Pushes to Docker Hub and creates git tag on main
|
|
# - Sends Discord notifications on success/failure
|
|
|
|
name: Build Docker Image
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0 # Full history for tag counting
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Login to Docker Hub
|
|
uses: docker/login-action@v3
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
# Generate CalVer: YYYY.MM.BUILD
|
|
# BUILD = count of tags matching current month + 1
|
|
- name: Generate CalVer version
|
|
id: meta
|
|
run: |
|
|
YEAR=$(date -u +%Y)
|
|
MONTH=$(date -u +%-m)
|
|
PREFIX="${YEAR}.${MONTH}."
|
|
|
|
# Count existing tags for this month
|
|
git fetch --tags
|
|
BUILD=$(git tag -l "${PREFIX}*" | wc -l)
|
|
BUILD=$((BUILD + 1))
|
|
|
|
VERSION="${PREFIX}${BUILD}"
|
|
SHA_SHORT=$(echo ${{ github.sha }} | cut -c1-7)
|
|
|
|
echo "version=${VERSION}" >> $GITHUB_OUTPUT
|
|
echo "sha_short=${SHA_SHORT}" >> $GITHUB_OUTPUT
|
|
echo "version_sha=${VERSION}-${SHA_SHORT}" >> $GITHUB_OUTPUT
|
|
echo "branch=${{ github.ref_name }}" >> $GITHUB_OUTPUT
|
|
echo "timestamp=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
|
|
|
|
echo "CalVer version: ${VERSION}"
|
|
|
|
# Dev build: push with dev + dev-SHA tags (PR/feature branches)
|
|
- name: Build Docker image (dev)
|
|
if: github.ref != 'refs/heads/main'
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
push: true
|
|
tags: |
|
|
manticorum67/paper-dynasty-discordapp:dev
|
|
manticorum67/paper-dynasty-discordapp:dev-${{ steps.meta.outputs.sha_short }}
|
|
cache-from: type=registry,ref=manticorum67/paper-dynasty-discordapp:buildcache
|
|
cache-to: type=registry,ref=manticorum67/paper-dynasty-discordapp:buildcache,mode=max
|
|
|
|
# Production build: push with latest + CalVer tags (main only)
|
|
- name: Build Docker image (production)
|
|
if: github.ref == 'refs/heads/main'
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
push: true
|
|
tags: |
|
|
manticorum67/paper-dynasty-discordapp:latest
|
|
manticorum67/paper-dynasty-discordapp:${{ steps.meta.outputs.version }}
|
|
manticorum67/paper-dynasty-discordapp:${{ steps.meta.outputs.version_sha }}
|
|
cache-from: type=registry,ref=manticorum67/paper-dynasty-discordapp:buildcache
|
|
cache-to: type=registry,ref=manticorum67/paper-dynasty-discordapp:buildcache,mode=max
|
|
|
|
# Create git tag and update VERSION file on successful push
|
|
- name: Tag release
|
|
if: success() && github.ref == 'refs/heads/main'
|
|
run: |
|
|
git config user.name "Gitea Actions"
|
|
git config user.email "actions@git.manticorum.com"
|
|
echo "${{ steps.meta.outputs.version }}" > VERSION
|
|
git add VERSION
|
|
git commit -m "chore: bump version to ${{ steps.meta.outputs.version }} [skip ci]" || true
|
|
git tag "${{ steps.meta.outputs.version }}"
|
|
git push origin main --tags
|
|
|
|
- name: Build Summary
|
|
run: |
|
|
echo "## Docker Build Successful" >> $GITHUB_STEP_SUMMARY
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
echo "**Image Tags:**" >> $GITHUB_STEP_SUMMARY
|
|
echo "- \`manticorum67/paper-dynasty-discordapp:latest\`" >> $GITHUB_STEP_SUMMARY
|
|
echo "- \`manticorum67/paper-dynasty-discordapp:${{ steps.meta.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY
|
|
echo "- \`manticorum67/paper-dynasty-discordapp:${{ steps.meta.outputs.version_sha }}\`" >> $GITHUB_STEP_SUMMARY
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
echo "**Build Details:**" >> $GITHUB_STEP_SUMMARY
|
|
echo "- Branch: \`${{ steps.meta.outputs.branch }}\`" >> $GITHUB_STEP_SUMMARY
|
|
echo "- Commit: \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY
|
|
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 "" >> $GITHUB_STEP_SUMMARY
|
|
echo "Pull with: \`docker pull manticorum67/paper-dynasty-discordapp:latest\`" >> $GITHUB_STEP_SUMMARY
|
|
else
|
|
echo "_PR build - image not pushed to Docker Hub_" >> $GITHUB_STEP_SUMMARY
|
|
fi
|
|
|
|
- name: Discord Notification - Success
|
|
if: success() && github.ref == 'refs/heads/main'
|
|
run: |
|
|
curl -H "Content-Type: application/json" \
|
|
-d '{
|
|
"embeds": [{
|
|
"title": "Paper Dynasty Bot - Build Successful",
|
|
"description": "Docker image built and pushed to Docker Hub",
|
|
"color": 3066993,
|
|
"fields": [
|
|
{
|
|
"name": "Version",
|
|
"value": "`${{ steps.meta.outputs.version }}`",
|
|
"inline": true
|
|
},
|
|
{
|
|
"name": "Image Tag",
|
|
"value": "`${{ steps.meta.outputs.version_sha }}`",
|
|
"inline": true
|
|
},
|
|
{
|
|
"name": "Commit",
|
|
"value": "`${{ steps.meta.outputs.sha_short }}`",
|
|
"inline": true
|
|
},
|
|
{
|
|
"name": "Author",
|
|
"value": "${{ github.actor }}",
|
|
"inline": true
|
|
},
|
|
{
|
|
"name": "View Run",
|
|
"value": "[Click here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})",
|
|
"inline": false
|
|
}
|
|
],
|
|
"timestamp": "${{ steps.meta.outputs.timestamp }}"
|
|
}]
|
|
}' \
|
|
https://discord.com/api/webhooks/1468485116631453840/JALtLV8dO2IWso3tNcntHW8wDgQeMZuLgFKVUeoEY9ig_OPjjm4PmjvzwYebH5l7_Nxv
|
|
|
|
- name: Discord Notification - Failure
|
|
if: failure() && github.ref == 'refs/heads/main'
|
|
run: |
|
|
TIMESTAMP=$(date -u +%Y-%m-%dT%H:%M:%SZ)
|
|
curl -H "Content-Type: application/json" \
|
|
-d '{
|
|
"embeds": [{
|
|
"title": "Paper Dynasty Bot - Build Failed",
|
|
"description": "Docker build encountered an error.",
|
|
"color": 15158332,
|
|
"fields": [
|
|
{
|
|
"name": "Branch",
|
|
"value": "`${{ github.ref_name }}`",
|
|
"inline": true
|
|
},
|
|
{
|
|
"name": "Commit",
|
|
"value": "`${{ github.sha }}`",
|
|
"inline": true
|
|
},
|
|
{
|
|
"name": "Author",
|
|
"value": "${{ github.actor }}",
|
|
"inline": true
|
|
},
|
|
{
|
|
"name": "View Logs",
|
|
"value": "[Click here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})",
|
|
"inline": false
|
|
}
|
|
],
|
|
"timestamp": "'"$TIMESTAMP"'"
|
|
}]
|
|
}' \
|
|
https://discord.com/api/webhooks/1468485116631453840/JALtLV8dO2IWso3tNcntHW8wDgQeMZuLgFKVUeoEY9ig_OPjjm4PmjvzwYebH5l7_Nxv
|