Skip to content

Commit

Permalink
ci: Update workflows to use repository_dispatch for triggering builds
Browse files Browse the repository at this point in the history
- Check Caddy Releases workflow updated to trigger Build and Push Docker Image workflow using repository_dispatch event.
- Build and Push Docker Image workflow now listens to repository_dispatch event for building and pushing Docker images.
- Added payload to repository_dispatch for passing the latest version information.
  • Loading branch information
vkartk committed May 26, 2024
1 parent 9cd5a9b commit 77e6517
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
19 changes: 15 additions & 4 deletions .github/workflows/build-docker-image.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Build and Push Docker Image

on:
release:
types: [published]
repository_dispatch:
types: [caddy-release]
workflow_dispatch: # Allows manual triggering

permissions:
Expand Down Expand Up @@ -37,10 +37,21 @@ jobs:
push: true
platforms: linux/amd64,linux/arm64,linux/arm/v7
tags: |
ghcr.io/${{ github.repository_owner }}/caddy-cloudflare-docker:${{ github.event.release.tag_name }}
ghcr.io/${{ github.repository_owner }}/caddy-cloudflare-docker:${{ github.event.client_payload.latest_version }}
ghcr.io/${{ github.repository_owner }}/caddy-cloudflare-docker:latest
- name: Clean up Docker images
run: |
docker rmi ghcr.io/${{ github.repository_owner }}/caddy-cloudflare-docker:${{ github.event.release.tag_name }} || true
docker rmi ghcr.io/${{ github.repository_owner }}/caddy-cloudflare-docker:${{ github.event.client_payload.latest_version }} || true
docker builder prune --force
- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.event.client_payload.latest_version }}
release_name: "Caddy Release ${{ github.event.client_payload.latest_version }}"
body: "New Caddy release detected. See the full release notes [here](https://github.com/caddyserver/caddy/releases/tag/${{ github.event.client_payload.latest_version }})."
draft: false
prerelease: false
31 changes: 17 additions & 14 deletions .github/workflows/check-caddy-release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Check Caddy Releases and Build Docker Image
name: Check Caddy Releases

on:
schedule:
Expand All @@ -15,7 +15,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v2
with:
Expand All @@ -27,25 +27,28 @@ jobs:
- name: Check and compare Caddy release
id: check_release
run: python scripts/check_caddy_release.py

- name: Update version file
if: env.IS_NEW_RELEASE == 'true'
run: |
echo "{\"version\": \"${LATEST_VERSION}\"}" > version.json
echo "{\"version\": \"${{ env.LATEST_VERSION }}\"}" > version.json
git config --global user.name "vkartk"
git config --global user.email "[email protected]"
git add version.json
git commit -m "Update version to ${LATEST_VERSION}"
git commit -m "Update version to ${{ env.LATEST_VERSION }}"
git push
- name: Create GitHub Release
- name: Trigger Build Workflow
if: env.IS_NEW_RELEASE == 'true'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: actions/github-script@v7
with:
tag_name: ${{ env.LATEST_VERSION }}
release_name: "Caddy Release ${{ env.LATEST_VERSION }}"
body: "New Caddy release detected. See the full release notes [here](https://github.com/caddyserver/caddy/releases/tag/${{ env.LATEST_VERSION }})."
draft: false
prerelease: false
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.repos.createDispatchEvent({
owner: context.repo.owner,
repo: context.repo.repo,
event_type: 'caddy-release',
client_payload: {
latest_version: '${{ env.LATEST_VERSION }}'
}
})

0 comments on commit 77e6517

Please sign in to comment.