Skip to content

Synchronize backport labels with maintenance versions #9

Synchronize backport labels with maintenance versions

Synchronize backport labels with maintenance versions #9

name: Synchronize backport labels with maintenance versions
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *' # midnight, daily
permissions:
issues: write
contents: read
jobs:
sync-labels:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- id: get-maintenance-versions
uses: hazelcast/hazelcast/.github/actions/get-supported-maintenance-versions@master
- run: |
set -euo pipefail ${RUNNER_DEBUG:+-x}
# Compute desired labels based off maintenance versions:
# - "backport to 5.3" (e.g.)
# - "backport to all versions""
desired_labels=$(jq -r '. + ["all versions"] | .[] | "backport to \(. )"' <<< '${{ steps.get-maintenance-versions.outputs.versions }}')
# Get existing repository "backport to" labels
existing_labels=$(gh label list \
--limit 1000 \
--json name \
--jq '[.[].name] | map(select(startswith("backport to "))) | .[]')
# Add any that are missing
while IFS= read -r label; do
if ! echo "${existing_labels}" | grep --quiet "${label}"; then
echo "::notice::Creating new label - ${label}"
gh label create "${label}"
fi
done <<< "${desired_labels}"
# Remove those that are no longer required
while IFS= read -r label; do
if ! echo "${desired_labels}" | grep --quiet "${label}"; then
echo "::notice::Deleting deprecated label - ${label}"
gh label delete "${label}" --yes
fi
done <<< "${existing_labels}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}