Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 5 additions & 29 deletions .github/workflows/adr-number-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:
- 'scripts/suggest-next-adr.sh'
permissions:
contents: read
pull-requests: write
jobs:
suggest-adr-number:
runs-on: ubuntu-latest
Expand All @@ -18,35 +17,12 @@ jobs:
id: suggest
continue-on-error: true
run: bash scripts/suggest-next-adr.sh --ci-suggest "${{ github.base_ref }}"
- name: Comment on PR with suggestion
if: steps.suggest.outcome == 'failure' && steps.suggest.outputs.suggestion != ''
uses: actions/github-script@v7
- name: Fail if ADR numbering check failed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this step needed, as it now only displays the output of the previous step? You could simplify by removing the continue-on-error: true line on the previous step. This way, the workflow will simply fail if the suggest-next-adr.sh script fails.

if: steps.suggest.outcome == 'failure'
env:
ERROR_MSG: ${{ steps.suggest.outputs.error }}
SUGGESTION: ${{ steps.suggest.outputs.suggestion }}
with:
script: |
const body = [
'## ADR numbering check failed',
'',
process.env.ERROR_MSG,
'',
'**Suggested filename:**',
process.env.SUGGESTION,
'',
'Run locally from repo root:',
'```bash',
'./scripts/suggest-next-adr.sh',
'```'
].join('\n');
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body
})
- name: Fail if ADR numbering check failed
if: steps.suggest.outcome == 'failure'
run: |
echo "${{ steps.suggest.outputs.error }}"
exit 1
echo "$ERROR_MSG"
echo "$SUGGESTION"
exit 1
18 changes: 14 additions & 4 deletions scripts/suggest-next-adr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,23 @@ set_github_output() {
}

suggest_next_number() {
local ref=${1:-}
local existing=() num ex n maxNum=0 padded found=0 next=""

while IFS= read -r num; do
existing+=("$num")
done < <(
ls decisions/*.md 2>/dev/null \
| sed 's|.*/||; s/-.*//' \
if [ -n "$ref" ]; then
git ls-tree --name-only "${ref}:decisions/" \
| sed 's/-.*//' \
| grep -E '^[0-9]{3}$' \
| sort -n
else
ls decisions/*.md \
| sed 's|.*/||; s/-.*//' \
| grep -E '^[0-9]{3}$' \
| sort -n
fi
)

for ex in "${existing[@]}"; do
Expand Down Expand Up @@ -63,7 +71,7 @@ if [ "${1:-}" = "--ci-suggest" ]; then
suffix="${basename%.md}"
fi
suffix="${suffix%.md}"
next=$(bash "$0" --number-only)
next=$(bash "$0" --number-only --ref "origin/${base_ref}")

current="${basename:0:3}"
if [[ "$basename" =~ ^[0-9]{3}- ]] && [ "$current" != "$next" ]; then
Expand All @@ -82,7 +90,9 @@ if [ "${1:-}" = "--ci-suggest" ]; then
fi

if [ "${1:-}" = "--number-only" ]; then
suggest_next_number
ref=""
[ "${2:-}" = "--ref" ] && ref="${3:?missing ref}"
suggest_next_number "$ref"
exit 0
fi

Expand Down
Loading