Update run-sync-script.yaml #296
This file contains 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: Run Sync Script | |
on: | |
push: | |
branches: | |
- main | |
permissions: | |
contents: write | |
jobs: | |
run-sync-script: | |
if: github.repository == 'SalamLang/Salam' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.x' | |
- name: Install Python dependencies | |
run: | | |
cd config/yaml | |
if [ -f requirements.txt ]; then | |
cat requirements.txt | |
pip install -r requirements.txt | |
fi | |
- name: Run sync.py script | |
run: | | |
cd config/yaml | |
python3 sync.py | |
- name: Check for changes | |
id: check_changes | |
run: | | |
if [ -n "$(git status --porcelain)" ]; then | |
echo "Changes detected" | |
echo "changes=true" >> $GITHUB_ENV | |
else | |
echo "No changes detected" | |
echo "changes=false" >> $GITHUB_ENV | |
shell: bash | |
- name: Delete and recreate branch | |
if: env.changes == 'true' | |
run: | | |
git branch -D auto-sync-update || echo "Branch not found locally" | |
git push origin --delete auto-sync-update || echo "Branch not found remotely" | |
git checkout -b auto-sync-update | |
- name: Commit and create pull request | |
if: env.changes == 'true' | |
run: | | |
FIRST_NAME="Max" | |
DOMAIN="gmail.com" | |
EMAIL="${FIRST_NAME}BaseCode@${DOMAIN}" | |
git config --global user.email "$EMAIL" | |
git config --global user.name "Max Base (GitHub Actions)" | |
if [ -n "$(git status --porcelain)" ]; then | |
echo "Unstaged changes detected. Stashing changes." | |
git stash | |
fi | |
git fetch origin | |
git pull --rebase origin auto-sync-update | |
git add -A | |
git commit -m "Auto-sync: Update after running sync.py script" || echo "No changes to commit." | |
git push --force https://x-access-token:${{ secrets.GH_TOKEN }}@github.com/${{ github.repository }}.git auto-sync-update | |
gh pr create --title "Auto-sync: Update after running sync.py script" --body "This PR was automatically generated by the workflow." |