Skip to content

Update Dockerfiles, tag and release #39

Update Dockerfiles, tag and release

Update Dockerfiles, tag and release #39

# Workflow to update all Dockerfiles when a new version of Caddy is available and create a new release and tag
name: Update Dockerfiles, tag and release
# Controls when the action will run
on:
workflow_dispatch: # allows to run the workflow manually from the Actions tab
push:
branches: main
paths:
- caddy-cloudflare/Dockerfile # file updated by Dependabot used as reference
# Environment variables available to all jobs and steps in this workflow
env:
CADDY_BUILDS: | # list of all Caddy Docker custom builds
caddy-cloudflare
caddy-cloudflare-crowdsec
# Jobs to run once the workflow is triggered
jobs:
# Job to parse the Caddy version from the reference Dockerfile
metadata:
name: Get updated Caddy version
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: main
- name: Parse Caddy version
id: version
run: echo "version=$(grep -Eo 'caddy:[0-9]+\.[0-9]+\.[0-9]+$' caddy-cloudflare/Dockerfile | cut -d ':' -f2)" | tee -a $GITHUB_OUTPUT
# Job to update the Caddy version in all Dockerfiles and create a tag
update:
name: Update Caddy and create tag
runs-on: ubuntu-latest
needs: metadata
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
token: ${{ secrets.PERSONAL_TOKEN }}
ref: main
- name: Replace Caddy version in all Dockerfiles
run: |
for caddy_build in $CADDY_BUILDS; do
sed -i "s/caddy:[0-9]\+\.[0-9]\+\.[0-9]\+/caddy:${{ needs.metadata.outputs.version }}/g" ./$caddy_build/Dockerfile
done
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v5
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
git_user_signingkey: true
git_commit_gpgsign: true
git_tag_gpgsign: true
- name: Commit and push changes
run: |
git add ./*/Dockerfile
if [ "$(git diff HEAD)" ]
then
git commit -Sm "Bump Caddy version to v${{ needs.metadata.outputs.version }} in all Dockerfiles"
git push
else
echo "No changes detected"
fi
- name: Create and push tag
run: |
git tag -fs v${{ needs.metadata.outputs.version }} -m "Docker images built with Caddy v${{ needs.metadata.outputs.version }}"
git push --tags -f
# Job to create a release
release:
name: Create release
runs-on: ubuntu-latest
needs: [metadata, update]
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: main
- name: Generate release text
run: |
echo "RELEASE_TEXT<<EOF" >> $GITHUB_ENV
for caddy_build in $CADDY_BUILDS; do
echo "- $caddy_build: [Source](https://github.com/serfriz/caddy-custom-builds/tree/main/$caddy_build) / \
[GitHub Package](https://ghcr.io/serfriz/$caddy_build) / [Docker Hub](https://hub.docker.com/r/serfriz/$caddy_build) / \
[Quay Package](https://quay.io/serfriz/$caddy_build)" >> $GITHUB_ENV
done
echo "EOF" >> $GITHUB_ENV
- name: Push release to github repository
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ needs.metadata.outputs.version }}
body: |
Caddy release notes: https://github.com/caddyserver/caddy/releases/tag/v${{ needs.metadata.outputs.version }}
Custom builds:
${{ env.RELEASE_TEXT }}