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 | |
| parent | 8d4cc05be0c696db2aabca7e9995e59019a01469 (diff) | |
chore: label included issues for next release
| -rw-r--r-- | .github/workflows/label-next-release-issues.yml | 83 | ||||
| -rw-r--r-- | .github/workflows/release.yml | 21 |
2 files changed, 98 insertions, 6 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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 531ffe68..d479d4e3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -145,6 +145,7 @@ jobs: shell: bash env: GH_TOKEN: ${{ github.token }} + NEXT_RELEASE_LABEL: included-in-next-release run: | set -euo pipefail @@ -183,14 +184,22 @@ jobs: continue fi - if [ "$(jq -r '.state' <<<"$data")" != "open" ]; then - echo "Skipping #$issue because it is not open." - continue + HAS_NEXT_RELEASE_LABEL="$(jq -r --arg label "$NEXT_RELEASE_LABEL" 'any(.labels[].name; . == $label)' <<<"$data")" + + if [ "$(jq -r '.state' <<<"$data")" = "open" ]; then + if ! gh issue close "$issue" --repo "$GITHUB_REPOSITORY" --reason completed --comment "Released in [v${VERSION}](${RELEASE_URL})."; then + echo "::warning::Could not close issue #$issue." + continue + fi + else + echo "Skipping close for #$issue because it is not open." fi - if ! gh issue close "$issue" --repo "$GITHUB_REPOSITORY" --reason completed --comment "Released in [v${VERSION}](${RELEASE_URL})."; then - echo "::warning::Could not close issue #$issue." - continue + if [ "$HAS_NEXT_RELEASE_LABEL" = "true" ]; then + if ! gh issue edit "$issue" --repo "$GITHUB_REPOSITORY" --remove-label "$NEXT_RELEASE_LABEL"; then + echo "::warning::Could not remove $NEXT_RELEASE_LABEL from issue #$issue." + continue + fi fi done |
