1+ name : React on README.md Updates
2+
3+ on :
4+ push :
5+ branches :
6+ - main
7+ paths :
8+ - ' *.md'
9+ workflow_dispatch :
10+
11+ permissions :
12+ contents : write
13+ pull-requests : write
14+
15+ jobs :
16+ react-on-readme :
17+ runs-on : ubuntu-latest
18+ steps :
19+ - name : Checkout repository
20+ uses : actions/checkout@v4
21+ with :
22+ fetch-depth : 0
23+
24+ - name : Get all markdown files
25+ id : changed-markdown-files
26+ uses : tj-actions/changed-files@v45
27+ with :
28+ # Avoid using single or double quotes for multiline patterns
29+ files : |
30+ README.md
31+
32+ - name : Install python3
33+ if : steps.changed-markdown-files.outputs.any_changed == 'true'
34+ run : sudo apt-get update && sudo apt-get install -y python3
35+
36+ - name : Clone markdown-to-bbcode repository
37+ if : steps.changed-markdown-files.outputs.any_changed == 'true'
38+ run : |
39+ git clone https://github.com/chemodun/markdown-to-bbcode-simple.git
40+
41+ - name : Process *.md changes
42+ if : steps.changed-markdown-files.outputs.any_changed == 'true'
43+ env :
44+ CHANGED_FILES : ${{ steps.changed-markdown-files.outputs.all_changed_files }}
45+ DELETED_FILES : ${{ steps.changed-markdown-files.outputs.deleted_files }}
46+ run : |
47+ git config user.name "Chem O'Dun"
48+ git config user.email "[email protected] " 49+ for file_changed in ${CHANGED_FILES}; do
50+ for conversion_type in egosoft nexus; do
51+ echo "Converting $file_changed to $conversion_type"
52+ python3 markdown-to-bbcode-simple/markdown_to_bbcode.py -t $conversion_type -o "Docs" "$file_changed"
53+ if [[ $? -ne 0 ]]; then
54+ echo "Error converting $file_changed to $conversion_type" >&2
55+ else
56+ echo "Converted $file_changed to $conversion_type"
57+ file_converted="${file_changed%.md}.$conversion_type"
58+ git add "Docs/$file_converted"
59+ if [[ $? -ne 0 ]]; then
60+ echo "Error adding Docs/$file_converted to git" >&2
61+ else
62+ echo "Added Docs/$file_converted to git"
63+ fi
64+ fi
65+ done
66+ done
67+ for file_deleted in ${DELETED_FILES}; do
68+ for conversion_type in egosoft nexus; do
69+ file_to_delete="Docs/${file_deleted%.md}.$conversion_type"
70+ if [[ -f "$file_to_delete" ]]; then
71+ echo "Deleting $file_to_delete"
72+ git rm "$file_to_delete"
73+ if [[ $? -ne 0 ]]; then
74+ echo "Error deleting $file_to_delete" >&2
75+ else
76+ echo "Deleted $file_to_delete"
77+ fi
78+ fi
79+ done
80+ done
81+ rm -rf markdown-to-bbcode-simple
82+
83+ - name : Commit and push changes
84+ if : steps.changed-markdown-files.outputs.any_changed == 'true'
85+ run : |
86+ if [[ -n $(git status -uno --porcelain) ]]; then
87+ git commit -m "docs(bbcode): Update bbcode files"
88+ git push
89+ if [[ $? -ne 0 ]]; then
90+ echo "Error pushing changes" >&2
91+ else
92+ echo "Changes pushed successfully"
93+ fi
94+ else
95+ echo "No changes to commit"
96+ fi
97+ env :
98+ GITHUB_TOKEN : ${{ secrets.MY_RELEASE_PLEASE_TOKEN }}
0 commit comments