Check Caddy Releases and Trigger Build #2309
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Check Caddy Releases and Trigger Build | |
on: | |
schedule: | |
- cron: '0 0 * * *' | |
workflow_dispatch: # Allows manual triggering | |
concurrency: | |
group: ${{ github.workflow }} | |
cancel-in-progress: true | |
jobs: | |
check_and_trigger: | |
name: Check Caddy Release and Trigger Build if Needed | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Python 3.x | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.x' | |
- name: Install Python dependencies | |
run: pip install requests | |
- name: Set DOCKERHUB_REPOSITORY_NAME with fallback | |
run: | | |
echo "DOCKERHUB_REPOSITORY_NAME=${DOCKERHUB_REPOSITORY_NAME:-caddybuilds/caddy-cloudflare}" >> $GITHUB_ENV | |
env: | |
DOCKERHUB_REPOSITORY_NAME: ${{ vars.DOCKERHUB_REPOSITORY_NAME || secrets.DOCKERHUB_REPOSITORY_NAME }} | |
- name: Check Caddy release status (GitHub & Docker Hub) | |
id: check_script | |
env: | |
DOCKERHUB_REPOSITORY_NAME: ${{ env.DOCKERHUB_REPOSITORY_NAME }} | |
run: python scripts/check_caddy_status.py | |
- name: Trigger Build Workflow if Needed | |
# Run this step ONLY if the script output NEEDS_BUILD is 'true' | |
if: steps.check_script.outputs.NEEDS_BUILD == 'true' | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const version = '${{ steps.check_script.outputs.LATEST_VERSION }}'; | |
console.log(`Build required for Caddy version: ${version}. Dispatching event...`); | |
try { | |
await github.rest.repos.createDispatchEvent({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
event_type: 'caddy-release', | |
client_payload: { | |
caddy_version: version // Pass the tag (e.g., "v2.9.1") | |
} | |
}); | |
console.log(`Successfully dispatched event for ${version}.`); | |
} catch (error) { | |
core.setFailed(`Failed to dispatch event: ${error.message}`); | |
} |