Skip to content

Commit 86555c4

Browse files
authored
refactor doc workflow (#4373)
refactor doc workflow (#4373)
1 parent 48792c6 commit 86555c4

File tree

1 file changed

+32
-17
lines changed

1 file changed

+32
-17
lines changed

.github/workflows/docs-ack.yml

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,29 @@ jobs:
1616
steps:
1717
- name: Read PR body
1818
id: body
19+
shell: bash
1920
run: |
20-
BODY=$(jq -r '.pull_request.body // ""' "$GITHUB_EVENT_PATH")
21-
echo "body<<EOF" >> $GITHUB_OUTPUT
22-
echo "$BODY" >> $GITHUB_OUTPUT
23-
echo "EOF" >> $GITHUB_OUTPUT
21+
set -euo pipefail
22+
BODY_B64=$(jq -r '.pull_request.body // "" | @base64' "$GITHUB_EVENT_PATH")
23+
{
24+
echo "body_b64=$BODY_B64"
25+
} >> "$GITHUB_OUTPUT"
2426
2527
- name: Validate checkbox selection
2628
id: validate
29+
shell: bash
30+
env:
31+
BODY_B64: ${{ steps.body.outputs.body_b64 }}
2732
run: |
28-
body='${{ steps.body.outputs.body }}'
33+
set -euo pipefail
34+
if ! body="$(printf '%s' "$BODY_B64" | base64 -d)"; then
35+
echo "::error::Failed to decode PR body from base64. Data may be corrupted or missing."
36+
exit 1
37+
fi
38+
39+
added_checked=$(printf '%s' "$body" | grep -Ei '^[[:space:]]*-\s*\[x\]\s*I added/updated documentation' | wc -l | tr -d '[:space:]' || true)
40+
noneed_checked=$(printf '%s' "$body" | grep -Ei '^[[:space:]]*-\s*\[x\]\s*Documentation is \*\*not needed\*\*' | wc -l | tr -d '[:space:]' || true)
2941
30-
added_checked=$(printf "%s" "$body" | grep -E '^- \[x\] I added/updated documentation' -i | wc -l | tr -d ' ')
31-
noneed_checked=$(printf "%s" "$body" | grep -E '^- \[x\] Documentation is \*\*not needed\*\*' -i | wc -l | tr -d ' ')
3242
3343
if [ "$added_checked" -eq 1 ] && [ "$noneed_checked" -eq 1 ]; then
3444
echo "::error::Choose exactly one: either 'docs added' OR 'not needed'."
@@ -41,30 +51,35 @@ jobs:
4151
fi
4252
4353
if [ "$added_checked" -eq 1 ]; then
44-
echo "mode=added" >> $GITHUB_OUTPUT
54+
echo "mode=added" >> "$GITHUB_OUTPUT"
4555
else
46-
echo "mode=noneed" >> $GITHUB_OUTPUT
56+
echo "mode=noneed" >> "$GITHUB_OUTPUT"
4757
fi
4858
4959
- name: Extract docs PR URL (when 'docs added')
5060
if: steps.validate.outputs.mode == 'added'
5161
id: extract
62+
shell: bash
63+
env:
64+
BODY_B64: ${{ steps.body.outputs.body_b64 }}
5265
run: |
53-
body='${{ steps.body.outputs.body }}'
66+
set -euo pipefail
67+
body="$(printf '%s' "$BODY_B64" | base64 -d)"
5468
5569
# Strictly require HTTPS and that it's a PR in netbirdio/docs
56-
# Examples accepted:
57-
# https://github.com/netbirdio/docs/pull/1234
58-
url=$(printf "%s" "$body" | grep -Eo 'https://github\.com/netbirdio/docs/pull/[0-9]+' | head -n1 || true)
70+
# e.g., https://github.com/netbirdio/docs/pull/1234
71+
url="$(printf '%s' "$body" | grep -Eo 'https://github\.com/netbirdio/docs/pull/[0-9]+' | head -n1 || true)"
5972
60-
if [ -z "$url" ]; then
73+
if [ -z "${url:-}" ]; then
6174
echo "::error::You checked 'docs added' but didn't include a valid HTTPS PR link to netbirdio/docs (e.g., https://github.com/netbirdio/docs/pull/1234)."
6275
exit 1
6376
fi
6477
65-
pr_number=$(echo "$url" | sed -E 's#.*/pull/([0-9]+)$#\1#')
66-
echo "url=$url" >> $GITHUB_OUTPUT
67-
echo "pr_number=$pr_number" >> $GITHUB_OUTPUT
78+
pr_number="$(printf '%s' "$url" | sed -E 's#.*/pull/([0-9]+)$#\1#')"
79+
{
80+
echo "url=$url"
81+
echo "pr_number=$pr_number"
82+
} >> "$GITHUB_OUTPUT"
6883
6984
- name: Verify docs PR exists (and is open or merged)
7085
if: steps.validate.outputs.mode == 'added'

0 commit comments

Comments
 (0)