ci: mark issues released on preview

This commit is contained in:
Ogulcan Celik 2026-06-07 19:20:12 +03:00
parent 0a3c9b97bc
commit 9c101b71d8
2 changed files with 114 additions and 5 deletions

View File

@ -252,6 +252,7 @@ jobs:
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
steps:
- uses: actions/checkout@v6
with:
@ -264,6 +265,17 @@ jobs:
with:
path: artifacts
- name: Record previous preview commit
id: previous-preview
shell: bash
run: |
set -euo pipefail
previous="$(python3 scripts/preview.py current-commit --manifest website/preview.json || true)"
if [ -z "$previous" ]; then
previous="$(git describe --tags --match 'v[0-9]*' --abbrev=0)"
fi
echo "commit=$previous" >> "$GITHUB_OUTPUT"
- name: Generate notes and checksums
shell: bash
run: |
@ -324,6 +336,94 @@ jobs:
git diff --cached --quiet || git commit -m "docs: update preview manifest"
git push "https://x-access-token:${KANGAL_GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" HEAD:master
- name: Mark preview-released issues
continue-on-error: true
shell: bash
env:
GH_TOKEN: ${{ secrets.KANGAL_GITHUB_TOKEN }}
PREVIEW_RELEASED_LABEL: preview-released
run: |
set -euo pipefail
echo "Using GitHub token for $(gh api user --jq .login)."
PREVIEW_COMMIT='${{ needs.preflight.outputs.commit }}'
PREVIEW_TAG='${{ needs.preflight.outputs.tag }}'
PREVIEW_BUILD_ID='${{ needs.preflight.outputs.build_id }}'
PREVIOUS_PREVIEW_COMMIT='${{ steps.previous-preview.outputs.commit }}'
echo "Scanning preview commits in $PREVIOUS_PREVIEW_COMMIT..$PREVIEW_COMMIT for refs #<issue> mentions."
mapfile -t ISSUES < <(
git log --format='%s%n%b' "$PREVIOUS_PREVIEW_COMMIT..$PREVIEW_COMMIT" \
| perl -ne 'print "$1\n" if /\brefs\s+#([0-9]+)\b/i' \
| sort -nu
)
if [ "${#ISSUES[@]}" -eq 0 ]; then
echo "No preview issue refs found."
exit 0
fi
if ! gh api "repos/${GITHUB_REPOSITORY}/labels/${PREVIEW_RELEASED_LABEL}" >/dev/null 2>&1; then
gh api -X POST "repos/${GITHUB_REPOSITORY}/labels" \
-f name="$PREVIEW_RELEASED_LABEL" \
-f color="1D76DB" \
-f description="Available on the preview channel, pending a stable release." \
>/dev/null \
|| gh api "repos/${GITHUB_REPOSITORY}/labels/${PREVIEW_RELEASED_LABEL}" >/dev/null
fi
PREVIEW_URL="https://github.com/${GITHUB_REPOSITORY}/releases/tag/${PREVIEW_TAG}"
PREVIEW_COMMENT_MARKER="<!-- herdr:preview-released:${PREVIEW_TAG} -->"
PREVIEW_COMMENT="${PREVIEW_COMMENT_MARKER}"$'\n'"Released on the preview channel in [${PREVIEW_BUILD_ID}](${PREVIEW_URL}). This is available to preview users, but is not in a stable Herdr release yet."
issue_has_comment_marker() {
local issue="$1"
local marker="$2"
local comments
if ! comments="$(gh api --paginate "repos/${GITHUB_REPOSITORY}/issues/${issue}/comments?per_page=100" --jq '.[].body')"; then
echo "::warning::Could not read comments for issue #$issue."
return 2
fi
grep -F -- "$marker" >/dev/null <<<"$comments"
}
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
HAS_PREVIEW_LABEL="$(jq -r --arg label "$PREVIEW_RELEASED_LABEL" 'any(.labels[].name; . == $label)' <<<"$data")"
if [ "$HAS_PREVIEW_LABEL" != "true" ]; then
if ! gh issue edit "$issue" --repo "$GITHUB_REPOSITORY" --add-label "$PREVIEW_RELEASED_LABEL"; then
echo "::warning::Could not label issue #$issue."
continue
fi
fi
MARKER_STATUS=0
issue_has_comment_marker "$issue" "$PREVIEW_COMMENT_MARKER" || MARKER_STATUS="$?"
if [ "$MARKER_STATUS" -eq 2 ]; then
continue
fi
if [ "$MARKER_STATUS" -eq 0 ]; then
echo "Skipping preview release comment for #$issue because it already exists."
continue
fi
if ! gh issue comment "$issue" --repo "$GITHUB_REPOSITORY" --body "$PREVIEW_COMMENT"; then
echo "::warning::Could not comment on issue #$issue."
continue
fi
done
- name: Prune old preview prereleases
env:
GH_TOKEN: ${{ github.token }}

View File

@ -191,6 +191,7 @@ jobs:
GH_TOKEN: ${{ secrets.KANGAL_GITHUB_TOKEN }}
NEXT_RELEASE_LABEL: pending-release
LEGACY_NEXT_RELEASE_LABEL: included-in-next-release
PREVIEW_RELEASED_LABEL: preview-released
run: |
set -euo pipefail
@ -246,9 +247,10 @@ jobs:
HAS_NEXT_RELEASE_LABEL="$(jq -r --arg label "$NEXT_RELEASE_LABEL" 'any(.labels[].name; . == $label)' <<<"$data")"
HAS_LEGACY_NEXT_RELEASE_LABEL="$(jq -r --arg label "$LEGACY_NEXT_RELEASE_LABEL" 'any(.labels[].name; . == $label)' <<<"$data")"
HAS_PENDING_RELEASE_LABEL="false"
if [ "$HAS_NEXT_RELEASE_LABEL" = "true" ] || [ "$HAS_LEGACY_NEXT_RELEASE_LABEL" = "true" ]; then
HAS_PENDING_RELEASE_LABEL="true"
HAS_PREVIEW_RELEASED_LABEL="$(jq -r --arg label "$PREVIEW_RELEASED_LABEL" 'any(.labels[].name; . == $label)' <<<"$data")"
HAS_RELEASE_TRACKING_LABEL="false"
if [ "$HAS_NEXT_RELEASE_LABEL" = "true" ] || [ "$HAS_LEGACY_NEXT_RELEASE_LABEL" = "true" ] || [ "$HAS_PREVIEW_RELEASED_LABEL" = "true" ]; then
HAS_RELEASE_TRACKING_LABEL="true"
fi
MARKER_STATUS=0
issue_has_comment_marker "$issue" "$RELEASE_COMMENT_MARKER" || MARKER_STATUS="$?"
@ -270,7 +272,7 @@ jobs:
echo "::warning::Could not close issue #$issue."
continue
fi
elif [ "$HAS_PENDING_RELEASE_LABEL" = "true" ]; then
elif [ "$HAS_RELEASE_TRACKING_LABEL" = "true" ]; then
if [ "$HAS_RELEASE_COMMENT" != "true" ]; then
if ! gh issue comment "$issue" --repo "$GITHUB_REPOSITORY" --body "$RELEASE_COMMENT"; then
echo "::warning::Could not comment on issue #$issue."
@ -280,7 +282,7 @@ jobs:
echo "Skipping release comment for #$issue because it already exists."
fi
else
echo "Skipping release comment for #$issue because it is closed and has no $NEXT_RELEASE_LABEL label."
echo "Skipping release comment for #$issue because it is closed and has no release tracking label."
fi
if [ "$HAS_NEXT_RELEASE_LABEL" = "true" ]; then
@ -296,6 +298,13 @@ jobs:
continue
fi
fi
if [ "$HAS_PREVIEW_RELEASED_LABEL" = "true" ]; then
if ! gh issue edit "$issue" --repo "$GITHUB_REPOSITORY" --remove-label "$PREVIEW_RELEASED_LABEL"; then
echo "::warning::Could not remove $PREVIEW_RELEASED_LABEL from issue #$issue."
continue
fi
fi
done
update-latest-json: