2424 - name : Run extraction script
2525 run : node .github/scripts/extract-classnames.js
2626
27- - name : Check for changes
27+ - name : Check for changes in class-names.json
2828 id : check_changes
2929 run : |
3030 if git diff --quiet --exit-code class-names.json; then
@@ -33,14 +33,54 @@ jobs:
3333 echo "changed=true" >> $GITHUB_OUTPUT
3434 fi
3535
36- - name : Create or Update Pull Request
36+ - name : Configure Git to use bot token
3737 if : steps.check_changes.outputs.changed == 'true'
38- uses : peter-evans/create-pull-request@v6
39- with :
40- token : ${{ secrets.BOT_TOKEN }}
41- commit-message : " Update class-names.json"
42- branch : update-class-names
43- title : " Update class names"
44- body : " Automated update of class-names.json to keep track of ScratchTools class names across all features."
45- labels : automated
46- delete-branch : true
38+ env :
39+ BOT_TOKEN : ${{ secrets.BOT_TOKEN }}
40+ run : |
41+ git config user.name "your-bot-username"
42+ git config user.email "[email protected] " 43+ git remote set-url origin https://x-access-token:${BOT_TOKEN}@github.com/${{ github.repository }}
44+ git fetch origin main
45+ git checkout -B update-class-names origin/main
46+
47+ - name : Commit changes
48+ if : steps.check_changes.outputs.changed == 'true'
49+ run : |
50+ git add class-names.json
51+ git commit -m "Update class-names.json" || echo "No changes to commit"
52+
53+ - name : Push update-class-names branch
54+ if : steps.check_changes.outputs.changed == 'true'
55+ env :
56+ BOT_TOKEN : ${{ secrets.BOT_TOKEN }}
57+ run : |
58+ git push origin update-class-names --force
59+
60+ - name : Create or update pull request
61+ if : steps.check_changes.outputs.changed == 'true'
62+ env :
63+ BOT_TOKEN : ${{ secrets.BOT_TOKEN }}
64+ REPO : ${{ github.repository }}
65+ run : |
66+ PR_EXISTS=$(curl -s -H "Authorization: token ${BOT_TOKEN}" \
67+ -H "Accept: application/vnd.github.v3+json" \
68+ "https://api.github.com/repos/${REPO}/pulls?head=${{ github.repository_owner }}:update-class-names" | jq 'length')
69+
70+ if [ "$PR_EXISTS" -eq 0 ]; then
71+ # Create PR if none exists
72+ curl -s -X POST \
73+ -H "Authorization: token ${BOT_TOKEN}" \
74+ -H "Accept: application/vnd.github.v3+json" \
75+ "https://api.github.com/repos/${REPO}/pulls" \
76+ -d @- <<EOF
77+ {
78+ " title " : " Update class-names.json" ,
79+ " head " : " update-class-names" ,
80+ " base " : " main" ,
81+ " body " : " Automated update of class-names.json"
82+ }
83+ EOF
84+ else
85+ echo "PR already exists, no need to create."
86+ fi
0 commit comments