Files
codex-security/.github/workflows/node-release-labels.yml
Michael D'Angeloandmldangelo-oai 884b7b657a refactor!: consolidate scan, workbench and release rules (#2452)
* refactor(workbench): share schema repair and saved finding projections

* refactor(cli): resolve the command route once

* refactor(settings): share Deep Scan configuration and restore saved inputs

* refactor(imports): reuse scanner projections at the file boundary

* refactor(publish): share pending request and receipt handling

* refactor(telemetry): classify publication failures in the recorder

* refactor(package): share plugin inventory and archive checks

* refactor(release): reuse verified provenance and release decisions

* fix(ci): reconcile release labels with an empty array on Bash 3.2

* ci: report failed source checks after cancelled PR edits

---------

Co-authored-by: mldangelo-oai <269034524+mldangelo-oai@users.noreply.github.com>
2026-11-09 05:02:21 -08:00

159 lines
5.5 KiB
YAML

name: node-release-labels
on:
pull_request_target:
branches: [main]
types: [opened, edited, reopened]
permissions:
contents: read
concurrency:
group: node-release-labels-${{ github.event.pull_request.number }}
cancel-in-progress: false
jobs:
categorize:
if: github.repository == 'openai/codex-security'
name: categorize release notes
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
pull-requests: write
steps:
- name: Categorize pull request without checking out its code
shell: bash
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
set -euo pipefail
# The suffix preserves trailing newlines through shell command substitution.
current_title="$(gh api "repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER" --jq '.title + "."')"
current_title="${current_title%.}"
conventional_title='^([a-z][a-z0-9-]*)(\([a-z0-9][a-z0-9._/-]*\))?(!)?:[ ]([^[:space:]].*[^[:space:]]|[^[:space:]])$'
if [[ "$current_title" == *$'\n'* ||
"$current_title" == *$'\r'* ||
! "$current_title" =~ $conventional_title ]]; then
echo "Pull request title must follow <type>[optional scope][!]: <description>." >&2
exit 1
fi
label=""
if [[ "${BASH_REMATCH[3]}" == "!" ]]; then
label=breaking-change
else
case "${BASH_REMATCH[1]}" in
feat) label=enhancement ;;
fix) label=bug ;;
docs) label=documentation ;;
release | test) label=skip-release-notes ;;
chore)
if [[ "${BASH_REMATCH[2]}" == "(release)" ]]; then
label=skip-release-notes
fi
;;
esac
fi
current_labels="$(
gh api "repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/labels" \
--jq '.[].name'
)"
label_events=""
if [[ -n "$current_labels" ]]; then
label_events="$(
gh api \
"repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/timeline?per_page=100" \
--paginate \
--jq '.[] | select(.event == "labeled") | [.label.name, (.actor.login // "__unattributed__")] | @tsv'
)"
fi
label_already_present=false
manual_category_present=false
bot_labels=()
while IFS= read -r current_label; do
case "$current_label" in
breaking-change | enhancement | bug | documentation | skip-release-notes)
label_actor=""
while IFS=$'\t' read -r event_label event_actor; do
if [[ "$event_label" == "$current_label" ]]; then
label_actor="$event_actor"
fi
done <<< "$label_events"
if [[ "$label_actor" != "github-actions[bot]" ]]; then
echo "Preserving existing $current_label label."
if [[ "$current_label" != "skip-release-notes" || "$current_label" == "$label" ]]; then
label_already_present=true
fi
if [[ "$current_label" != "skip-release-notes" ]]; then
manual_category_present=true
fi
else
bot_labels+=("$current_label")
fi
;;
esac
done <<< "$current_labels"
# Bash 3.2 treats an empty array as unset under nounset.
if (( ${#bot_labels[@]} )); then
for current_label in "${bot_labels[@]}"; do
if [[ "$manual_category_present" == true || "$current_label" != "$label" ]]; then
gh api --method DELETE \
"repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/labels/$current_label" \
--silent
else
label_already_present=true
fi
done
fi
if [[ -z "$label" ]]; then
echo "No automatic release-note category applies."
exit 0
fi
if [[ "$label_already_present" == true ]]; then
echo "The current release-note category is already applied."
exit 0
fi
ensure_repository_label() {
local name="$1" color="$2" description="$3"
if ! gh api \
"repos/$GITHUB_REPOSITORY/labels/$name" \
--silent >/dev/null 2>&1; then
if ! gh api --method POST "repos/$GITHUB_REPOSITORY/labels" \
-f "name=$name" \
-f "color=$color" \
-f "description=$description" \
--silent >/dev/null 2>&1; then
gh api \
"repos/$GITHUB_REPOSITORY/labels/$name" \
--silent >/dev/null
fi
fi
}
case "$label" in
breaking-change)
ensure_repository_label \
breaking-change b60205 \
"Breaking change called out in generated release notes"
;;
skip-release-notes)
ensure_repository_label \
skip-release-notes ededed \
"Omit internal changes from generated release notes"
;;
esac
gh api --method POST \
"repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/labels" \
-f "labels[]=$label" \
--silent