github.com/quay/claircore@v1.5.28/.github/workflows/changelog-label.yml (about)

     1  name: Check needs-changelog label freshness
     2  
     3  on:
     4    workflow_dispatch: {}
     5    schedule:
     6      - cron: '55 20 * * *'
     7  
     8  jobs:
     9    check_labels:
    10      name: Check Labels
    11      runs-on: ubuntu-latest
    12      steps:
    13        - name: Checkout
    14          uses: actions/checkout@v4
    15        - name: Switch to Changelog ref
    16          run: |
    17            git fetch origin +refs/notes/changelog:refs/notes/changelog
    18            git checkout refs/notes/changelog
    19        - name: Check for unresolved changelog labels
    20          # For all merged PRs with the `needs-changelog` label, check if a note exists on the merge commit.
    21          # If it does, remove the label.
    22          # If not, print a summary of all PRs that need a changelog entry.
    23          env:
    24            GH_TOKEN: ${{ github.token }}
    25          run: |
    26            summary=$(mktemp)
    27            remove=$(mktemp)
    28            trap 'rm -rf "$summary" "$remove"' EXIT
    29            gh api graphql -f query='
    30            {
    31              repository(owner: "quay", name: "claircore") {
    32                pullRequests(first: 100, labels: ["needs-changelog"], states: [MERGED]) {
    33                  nodes {
    34                    id
    35                    title
    36                    number
    37                    url
    38                    mergeCommit {
    39                      oid
    40                    }
    41                  }
    42                }
    43              }
    44            }
    45            ' -q '.data.repository.pullRequests.nodes[]' |
    46              jq --arg remove "$remove" --arg summary "$summary" \
    47                '@sh "if test -f \(.mergeCommit.oid); then echo \(.id) >> \($remove); else echo \(@text "- [#\(.number)](\(.url)): \(.title)") >> \($summary); fi"' |
    48              xargs -t -n1 -r sh -c
    49            if test -s "$remove"; then
    50              l=$(gh api graphql -f query='{repository(owner: "quay", name: "claircore") {label(name: "needs-changelog") {id}}}'|
    51                jq -r '.data.repository.label.id')
    52              cat "$remove" | while read id; do
    53                gh api graphql -F "id=${id}" -F "l=${l}" -f query='
    54                mutation rm($id: ID!, $l: ID!) {
    55                  removeLabelsFromLabelable(input: {
    56                    labelableId: $id,
    57                    labelIds: [$l],
    58                  }){clientMutationId}
    59                }
    60                '
    61              done
    62            fi
    63            test -s "$summary" || exit 0
    64            cat <<'.' >> "$GITHUB_STEP_SUMMARY"
    65            ### Changlog notes missing:
    66            
    67            .
    68            cat "$summary" >> "$GITHUB_STEP_SUMMARY"
    69            cat <<'.' >> "$GITHUB_STEP_SUMMARY"
    70            
    71            * * *
    72            If the changelog message is on another commit, the label needs to be removed manually. 🫥
    73            .