Skip to content

Commit 7004c40

Browse files
Add GitHub Action to update nonce query parameter on issue trigger (#5)
* Initial plan * Add GitHub Action to update nonce on issue open Co-authored-by: hesreallyhim <172150522+hesreallyhim@users.noreply.github.com> * Fix security issue and improve sed command clarity Co-authored-by: hesreallyhim <172150522+hesreallyhim@users.noreply.github.com> * Add explicit GITHUB_TOKEN permissions to workflow Co-authored-by: hesreallyhim <172150522+hesreallyhim@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: hesreallyhim <172150522+hesreallyhim@users.noreply.github.com>
1 parent b9e43fa commit 7004c40

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

.github/workflows/update-nonce.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
name: Update Nonce on Issue Open
3+
4+
'on':
5+
issues:
6+
types: [opened]
7+
8+
jobs:
9+
update-nonce:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
issues: read
14+
15+
steps:
16+
- name: Check if issue body contains "nonce"
17+
id: check-nonce
18+
env:
19+
ISSUE_BODY: ${{ github.event.issue.body }}
20+
run: |
21+
if echo "$ISSUE_BODY" | grep -qi "nonce"; then
22+
echo "contains_nonce=true" >> $GITHUB_OUTPUT
23+
echo "Issue body contains 'nonce' - proceeding"
24+
else
25+
echo "contains_nonce=false" >> $GITHUB_OUTPUT
26+
echo "Issue body does not contain 'nonce' - stopping"
27+
fi
28+
29+
- name: Checkout repository
30+
if: steps.check-nonce.outputs.contains_nonce == 'true'
31+
uses: actions/checkout@v4
32+
with:
33+
token: ${{ secrets.GITHUB_TOKEN }}
34+
35+
- name: Update nonce in README
36+
if: steps.check-nonce.outputs.contains_nonce == 'true'
37+
run: |
38+
# Generate a random 6-digit number
39+
NEW_NONCE=$(printf "%06d" $((RANDOM % 1000000)))
40+
echo "Generated new nonce: $NEW_NONCE"
41+
42+
# Find and replace nonce=NNNNNN pattern with new nonce
43+
# Only within the NONCE section markers
44+
NONCE_PATTERN='/<!-- NONCE -->/,/<!-- NONCE-END -->/'
45+
NONCE_REPLACEMENT='s/nonce=[0-9]\{6\}/nonce='"$NEW_NONCE"'/g'
46+
sed -i "${NONCE_PATTERN}${NONCE_REPLACEMENT}" README.md
47+
48+
echo "Updated README.md with new nonce value"
49+
50+
- name: Commit and push changes
51+
if: steps.check-nonce.outputs.contains_nonce == 'true'
52+
run: |
53+
git config user.name "github-actions[bot]"
54+
git config user.email "github-actions[bot]@users.noreply.github.com"
55+
git add README.md
56+
if git diff --staged --quiet; then
57+
echo "No changes to commit"
58+
else
59+
git commit -m "Update nonce value in README [skip ci]"
60+
git push
61+
fi

0 commit comments

Comments
 (0)