diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml index 4765a8f..e21a516 100644 --- a/.github/workflows/build-docker-image.yml +++ b/.github/workflows/build-docker-image.yml @@ -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: @@ -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 diff --git a/.github/workflows/check-caddy-release.yml b/.github/workflows/check-caddy-release.yml index 9d776f0..9e36ab7 100644 --- a/.github/workflows/check-caddy-release.yml +++ b/.github/workflows/check-caddy-release.yml @@ -1,4 +1,4 @@ -name: Check Caddy Releases and Build Docker Image +name: Check Caddy Releases on: schedule: @@ -15,7 +15,7 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - + - name: Set up Python uses: actions/setup-python@v2 with: @@ -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 "53650724+vkartk@users.noreply.github.com" 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 }}' + } + })