test 6 w nonce #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| name: Update Nonce on Issue Open | |
| 'on': | |
| issues: | |
| types: [opened] | |
| jobs: | |
| update-nonce: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| issues: read | |
| steps: | |
| - name: Check if issue body contains "nonce" | |
| id: check-nonce | |
| env: | |
| ISSUE_BODY: ${{ github.event.issue.body }} | |
| run: | | |
| if echo "$ISSUE_BODY" | grep -qi "nonce"; then | |
| echo "contains_nonce=true" >> $GITHUB_OUTPUT | |
| echo "Issue body contains 'nonce' - proceeding" | |
| else | |
| echo "contains_nonce=false" >> $GITHUB_OUTPUT | |
| echo "Issue body does not contain 'nonce' - stopping" | |
| fi | |
| - name: Checkout repository | |
| if: steps.check-nonce.outputs.contains_nonce == 'true' | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Update nonce in README | |
| if: steps.check-nonce.outputs.contains_nonce == 'true' | |
| run: | | |
| # Generate a random 6-digit number | |
| NEW_NONCE=$(printf "%06d" $((RANDOM % 1000000))) | |
| echo "Generated new nonce: $NEW_NONCE" | |
| # Find and replace nonce=NNNNNN pattern with new nonce | |
| # Only within the NONCE section markers | |
| NONCE_PATTERN='/<!-- NONCE -->/,/<!-- NONCE-END -->/' | |
| NONCE_REPLACEMENT='s/nonce=[0-9]\{6\}/nonce='"$NEW_NONCE"'/g' | |
| sed -i "${NONCE_PATTERN}${NONCE_REPLACEMENT}" README.md | |
| echo "Updated README.md with new nonce value" | |
| - name: Commit and push changes | |
| if: steps.check-nonce.outputs.contains_nonce == 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add README.md | |
| if git diff --staged --quiet; then | |
| echo "No changes to commit" | |
| else | |
| git commit -m "Update nonce value in README [skip ci]" | |
| git push | |
| fi |