diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-05-17 00:23:04 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-05-17 00:23:04 +0300 |
| commit | d2aa8865911ded97a67054fb2392a1c12fae018c (patch) | |
| tree | 585f8665dbf0868c8e6cf6fa7a1406b6c09391b2 /.github/workflows/label-next-release-issues.yml | |
| parent | 8d4cc05be0c696db2aabca7e9995e59019a01469 (diff) | |
chore: label included issues for next release
Diffstat (limited to '.github/workflows/label-next-release-issues.yml')
| -rw-r--r-- | .github/workflows/label-next-release-issues.yml | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/.github/workflows/label-next-release-issues.yml b/.github/workflows/label-next-release-issues.yml new file mode 100644 index 00000000..5e98b1f5 --- /dev/null +++ b/.github/workflows/label-next-release-issues.yml @@ -0,0 +1,83 @@ +name: Label next-release issues + +on: + push: + branches: [master] + +permissions: + contents: read + issues: write + +env: + NEXT_RELEASE_LABEL: included-in-next-release + +jobs: + label: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Label issues referenced by pushed commits + shell: bash + env: + GH_TOKEN: ${{ github.token }} + run: | + set -euo pipefail + + BEFORE="${{ github.event.before }}" + AFTER="${{ github.sha }}" + ZERO_SHA="0000000000000000000000000000000000000000" + + if [ "$BEFORE" = "$ZERO_SHA" ]; then + RANGE_ARGS=(-1 "$AFTER") + echo "Scanning latest commit $AFTER for refs #<issue> lines." + else + RANGE_ARGS=("$BEFORE..$AFTER") + echo "Scanning pushed commits in $BEFORE..$AFTER for refs #<issue> lines." + fi + + mapfile -t ISSUES < <( + git log --format=%b "${RANGE_ARGS[@]}" \ + | perl -ne 'print "$1\n" if /^\s*refs\s+#([0-9]+)\s*$/i' \ + | sort -nu + ) + + if [ "${#ISSUES[@]}" -eq 0 ]; then + echo "No issue refs found." + exit 0 + fi + + if ! gh api "repos/${GITHUB_REPOSITORY}/labels/${NEXT_RELEASE_LABEL}" >/dev/null 2>&1; then + gh api -X POST "repos/${GITHUB_REPOSITORY}/labels" \ + -f name="$NEXT_RELEASE_LABEL" \ + -f color="5319E7" \ + -f description="Landed on master and planned for the next release." \ + >/dev/null \ + || gh api "repos/${GITHUB_REPOSITORY}/labels/${NEXT_RELEASE_LABEL}" >/dev/null + fi + + for issue in "${ISSUES[@]}"; do + echo "Checking #$issue" + if ! data="$(gh api "repos/${GITHUB_REPOSITORY}/issues/${issue}")"; then + echo "::warning::Could not read issue #$issue; skipping." + continue + fi + + if jq -e 'has("pull_request")' <<<"$data" >/dev/null; then + echo "Skipping #$issue because it is a pull request." + continue + fi + + if [ "$(jq -r '.state' <<<"$data")" != "open" ]; then + echo "Skipping #$issue because it is not open." + continue + fi + + if ! gh issue edit "$issue" --repo "$GITHUB_REPOSITORY" --add-label "$NEXT_RELEASE_LABEL"; then + echo "::warning::Could not label issue #$issue." + continue + fi + done |
