Check Plugin Updates #11
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 Plugin Updates | |
| on: | |
| schedule: | |
| # Run weekly on Monday at 00:00 UTC | |
| - cron: '0 0 * * 1' | |
| workflow_dispatch: | |
| jobs: | |
| check-plugin-updates: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| issues: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Check caddy-webdav plugin | |
| id: check_webdav | |
| run: | | |
| echo "Checking mholt/caddy-webdav plugin..." | |
| # Get default branch first | |
| DEFAULT_BRANCH=$(curl -s https://api.github.com/repos/mholt/caddy-webdav | jq -r '.default_branch') | |
| # Fetch commit data once | |
| COMMIT_DATA=$(curl -s "https://api.github.com/repos/mholt/caddy-webdav/commits/$DEFAULT_BRANCH") | |
| LATEST_COMMIT=$(echo "$COMMIT_DATA" | jq -r '.sha[0:7]') | |
| LATEST_DATE=$(echo "$COMMIT_DATA" | jq -r '.commit.committer.date') | |
| echo "Latest commit: $LATEST_COMMIT" | |
| echo "Latest commit date: $LATEST_DATE" | |
| echo "commit=$LATEST_COMMIT" >> $GITHUB_OUTPUT | |
| echo "date=$LATEST_DATE" >> $GITHUB_OUTPUT | |
| - name: Check caddy-dns/cloudflare plugin | |
| id: check_cloudflare | |
| run: | | |
| echo "Checking caddy-dns/cloudflare plugin..." | |
| LATEST_TAG=$(curl -s https://api.github.com/repos/caddy-dns/cloudflare/releases/latest | jq -r '.tag_name') | |
| if [ "$LATEST_TAG" = "null" ] || [ -z "$LATEST_TAG" ]; then | |
| # Get default branch first | |
| DEFAULT_BRANCH=$(curl -s https://api.github.com/repos/caddy-dns/cloudflare | jq -r '.default_branch') | |
| LATEST_COMMIT=$(curl -s "https://api.github.com/repos/caddy-dns/cloudflare/commits/$DEFAULT_BRANCH" | jq -r '.sha[0:7]') | |
| echo "No releases found, using latest commit: $LATEST_COMMIT" | |
| echo "tag=commit-$LATEST_COMMIT" >> $GITHUB_OUTPUT | |
| else | |
| echo "Latest release: $LATEST_TAG" | |
| echo "tag=$LATEST_TAG" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Create plugin status issue | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const webdavCommit = '${{ steps.check_webdav.outputs.commit }}'; | |
| const webdavDate = '${{ steps.check_webdav.outputs.date }}'; | |
| const cloudflareTag = '${{ steps.check_cloudflare.outputs.tag }}'; | |
| const issueTitle = '📦 Plugin Status Check - ' + new Date().toISOString().split('T')[0]; | |
| const issueBody = `## Plugin Status Report | |
| This is an automated check of the Caddy plugins used in this Docker image. | |
| ### caddy-webdav (mholt/caddy-webdav) | |
| - Latest commit: \`${webdavCommit}\` | |
| - Commit date: ${webdavDate} | |
| - Repository: https://github.com/mholt/caddy-webdav | |
| ### caddy-dns/cloudflare | |
| - Latest version: \`${cloudflareTag}\` | |
| - Repository: https://github.com/caddy-dns/cloudflare | |
| ### Notes | |
| - Plugins are automatically updated when building with xcaddy | |
| - No action required unless there are breaking changes | |
| - Review plugin changelogs if you encounter issues | |
| --- | |
| *This report was automatically generated by the Check Plugin Updates workflow.*`; | |
| // Check if a similar issue exists from the last 7 days | |
| const existingIssues = await github.rest.issues.listForRepo({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| state: 'open', | |
| labels: 'plugin-status', | |
| per_page: 10 | |
| }); | |
| const oneWeekAgo = new Date(); | |
| oneWeekAgo.setDate(oneWeekAgo.getDate() - 7); | |
| const recentIssue = existingIssues.data.find(issue => | |
| new Date(issue.created_at) > oneWeekAgo | |
| ); | |
| if (recentIssue) { | |
| console.log('Recent plugin status issue exists, updating it...'); | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: recentIssue.number, | |
| body: issueBody | |
| }); | |
| } else { | |
| console.log('Creating new plugin status issue...'); | |
| await github.rest.issues.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title: issueTitle, | |
| body: issueBody, | |
| labels: ['plugin-status', 'automated'] | |
| }); | |
| } |