1
0
mirror of https://github.com/pavel-odintsov/fastnetmon synced 2026-07-24 15:15:00 +02:00
Files
fastnetmon-rewritten/.github/workflows/check-fmt-release.yml

84 lines
3.1 KiB
YAML

name: Check for new fmt release
on:
schedule:
# Run daily at 06:00 UTC
- cron: '0 6 * * *'
workflow_dispatch:
permissions:
contents: read
issues: write
jobs:
check-fmt:
runs-on: ubuntu-latest
steps:
- name: Get latest fmt release
id: latest
env:
GH_TOKEN: ${{ github.token }}
run: |
latest=$(curl -fsSL \
-H "Authorization: Bearer ${GH_TOKEN}" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/fmtlib/fmt/releases/latest | jq -r .tag_name)
if [ -z "$latest" ] || [ "$latest" = "null" ]; then
echo "::error::Failed to fetch latest fmt release tag"
exit 1
fi
echo "latest=$latest" >> "$GITHUB_OUTPUT"
echo "Latest fmt release: $latest"
- name: Check for existing issue
id: existing
env:
GH_TOKEN: ${{ github.token }}
LATEST: ${{ steps.latest.outputs.latest }}
REPO: ${{ github.repository }}
run: |
title="New fmt release available: ${LATEST}"
# Search both open and closed issues so we do not reopen / duplicate
# an already-acknowledged release notification.
query=$(jq -rn --arg repo "$REPO" --arg title "$title" \
'"repo:\($repo) is:issue in:title \"\($title)\""')
count=$(curl -fsSL -G \
-H "Authorization: Bearer ${GH_TOKEN}" \
-H "Accept: application/vnd.github+json" \
--data-urlencode "q=${query}" \
https://api.github.com/search/issues | jq -r '.total_count')
echo "Matching issues found: $count"
echo "count=$count" >> "$GITHUB_OUTPUT"
echo "title=$title" >> "$GITHUB_OUTPUT"
- name: Create issue for new fmt release
if: steps.existing.outputs.count == '0'
env:
GH_TOKEN: ${{ github.token }}
LATEST: ${{ steps.latest.outputs.latest }}
REPO: ${{ github.repository }}
TITLE: ${{ steps.existing.outputs.title }}
run: |
body=$(cat <<EOF
A new release of [fmtlib/fmt](https://github.com/fmtlib/fmt) has been published.
- Latest version: \`${LATEST}\`
- Release notes: https://github.com/fmtlib/fmt/releases/tag/${LATEST}
Please consider updating the bundled fmt version in this repository.
_This issue was created automatically by the \`check-fmt-release\` workflow. Close it once the update has been handled (or acknowledged) — it will not be reopened for the same version._
EOF
)
curl -fsSL -X POST \
-H "Authorization: Bearer ${GH_TOKEN}" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/${REPO}/issues" \
-d "$(jq -n --arg title "$TITLE" --arg body "$body" \
'{title:$title, body:$body, labels:["dependencies"]}')"
echo "Opened issue: $TITLE"
- name: No action needed
if: steps.existing.outputs.count != '0'
run: echo "An issue for fmt ${{ steps.latest.outputs.latest }} already exists; nothing to do."