|
1 | | -name: Bot change from input |
2 | | -on: |
3 | | - workflow_dispatch: |
4 | | - inputs: |
5 | | - change: |
6 | | - description: 'Short instruction for the bot' |
7 | | - required: true |
8 | | - |
9 | | -permissions: |
10 | | - contents: write |
11 | | - |
12 | | -jobs: |
13 | | - run-bot: |
14 | | - runs-on: ubuntu-latest |
15 | | - steps: |
16 | | - - uses: actions/checkout@v4 |
17 | | - with: |
18 | | - fetch-depth: 0 |
19 | | - |
20 | | - - name: Set up Python |
21 | | - uses: actions/setup-python@v4 |
22 | | - with: |
23 | | - python-version: '3.11' |
24 | | - |
25 | | - - name: Run bot script |
| 1 | + - name: Run copy-edit bot |
26 | 2 | env: |
27 | 3 | CHANGE_INSTRUCTION: ${{ github.event.inputs.change }} |
28 | 4 | run: | |
29 | 5 | mkdir -p scripts |
30 | | - echo 'import os, pathlib' > scripts/auto_edit.py |
31 | | - echo 'instr = os.environ.get("CHANGE_INSTRUCTION","(no instruction)")' >> scripts/auto_edit.py |
32 | | - echo 'p = pathlib.Path("BOT_CHANGES.md")' >> scripts/auto_edit.py |
33 | | - echo 'p.write_text(p.read_text() + f"- {instr}\n" if p.exists() else f"- {instr}\n")' >> scripts/auto_edit.py |
| 6 | + cat <<'PY' > scripts/auto_edit.py |
| 7 | +import pathlib |
| 8 | +search_text = "Add React to an Existing Project" |
| 9 | +replace_text = "Add React to your Existing Project" |
| 10 | + |
| 11 | +# loop through all .md files in the repo |
| 12 | +for md_file in pathlib.Path('.').rglob('*.md'): |
| 13 | + content = md_file.read_text() |
| 14 | + if search_text in content: |
| 15 | + md_file.write_text(content.replace(search_text, replace_text)) |
| 16 | + print(f"Updated {md_file}") |
| 17 | +PY |
34 | 18 | python3 scripts/auto_edit.py |
35 | 19 | git config user.name "github-actions" |
36 | 20 | git config user.email "[email protected]" |
37 | | - git add BOT_CHANGES.md |
38 | | - git commit -m "bot: apply change ${{ github.event.inputs.change }}" || echo "No changes to commit" |
| 21 | + git add . |
| 22 | + git commit -m "bot: apply copy edit" || echo "No changes to commit" |
39 | 23 | git push |
0 commit comments