On Update abort do not set empty path #316
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: Check Code and Sync main and dev | |
on: | |
push: | |
branches: | |
- main | |
- dev | |
pull_request: | |
branches: | |
- main | |
- dev | |
jobs: | |
lint-and-format: | |
runs-on: ubuntu-latest | |
outputs: | |
python_files_changed: ${{ env.PYTHON_FILES_CHANGED }} | |
black_outcome: ${{ steps.run_black.outcome }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Get changed files | |
id: changed_files | |
uses: jitterbit/get-changed-files@v1 | |
with: | |
format: space-delimited | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Check if Python files or wemod file changed | |
id: check_files | |
run: | | |
if echo "${{ steps.changed_files.outputs.added_modified }}" | grep -E '\.py$|wemod' > /dev/null; then | |
echo "PYTHON_FILES_CHANGED=true" >> $GITHUB_ENV | |
else | |
echo "PYTHON_FILES_CHANGED=false" >> $GITHUB_ENV | |
fi | |
- name: Set up Python | |
if: env.PYTHON_FILES_CHANGED == 'true' | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.12.3' | |
- name: Install dependencies | |
if: env.PYTHON_FILES_CHANGED == 'true' | |
run: | | |
pip install black | |
- name: Run Black | |
if: env.PYTHON_FILES_CHANGED == 'true' | |
id: run_black | |
run: | | |
black -l 78 -t py312 ./*.py ./wemod | |
- name: Increment version number | |
if: steps.run_black.outcome == 'success' && env.PYTHON_FILES_CHANGED == 'true' | |
run: | | |
awk '/script_version = "/ { | |
ver = $3; | |
ver = substr(ver, 2, length(ver) - 2); | |
new_ver = ver + 0.001; | |
printf(" script_version = \"%.3f\"\n", new_ver); | |
} | |
!/script_version = "/ { print $0 }' coreutils.py > coreutils.py.tmp && mv coreutils.py.tmp coreutils.py | |
current_ver=$(awk '/script_version = "/ {print $3}' coreutils.py | tr -d '"') | |
awk -v ver="$current_ver" '/The WeMod Launcher is currently on version / { | |
printf("**The WeMod Launcher is currently on version %.3f.**\n", ver); | |
} | |
!/The WeMod Launcher is currently on version / { print $0 }' readme.md > readme.tmp && mv readme.tmp readme.md | |
- name: Commit changes on dev | |
if: github.ref == 'refs/heads/dev' && steps.run_black.outcome == 'success' && env.PYTHON_FILES_CHANGED == 'true' | |
id: commit_changes_dev | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
git add . | |
git update-index --chmod=+x *.py wemod | |
git commit -m 'Github actions automatic code formatting on dev branch' -m 'This is an automatic task, run by a GitHub workflow, to automatically format the Python code in the repo, with the code formatter "black"' || echo "No changes to commit" | |
git push | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Commit changes on main | |
if: github.ref == 'refs/heads/main' && steps.run_black.outcome == 'success' && env.PYTHON_FILES_CHANGED == 'true' | |
id: commit_changes_main | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
git add . | |
git update-index --chmod=+x *.py wemod | |
git commit -m 'Github actions automatic code formatting on main branch' -m 'This is an automatic task, run by a GitHub workflow, to automatically format the Python code in the repo, with the code formatter "black"' || echo "No changes to commit" | |
git push | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
merge: | |
runs-on: ubuntu-latest | |
needs: lint-and-format | |
env: | |
PYTHON_FILES_CHANGED: ${{ needs.lint-and-format.outputs.python_files_changed }} | |
BLACK_OUTCOME: ${{ needs.lint-and-format.outputs.black_outcome }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Print PYTHON_FILES_CHANGED value | |
run: | | |
echo "PYTHON_FILES_CHANGED=${{ env.PYTHON_FILES_CHANGED }}" | |
echo "BLACK_OUTCOME=${{ env.BLACK_OUTCOME }}" | |
echo "On=${{ github.ref }}" | |
- name: Pull changes if main or dev | |
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev' | |
run: | | |
git pull | |
- name: Merge dev into main | |
if: github.ref == 'refs/heads/dev' && (env.PYTHON_FILES_CHANGED == 'false' || env.BLACK_OUTCOME == 'success') | |
uses: peter-evans/create-pull-request@v3 | |
id: create_pr_dev_to_main | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
commit-message: "Auto merge/sync branch 'dev' into 'main'" | |
branch: "main" | |
base: "dev" | |
title: "Auto merge/sync branch 'dev' into 'main'" | |
body: "This PR was created automatically to merge changes from dev into main." | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Merge main into dev | |
if: github.ref == 'refs/heads/main' && (env.PYTHON_FILES_CHANGED == 'false' || env.BLACK_OUTCOME == 'success') | |
uses: peter-evans/create-pull-request@v3 | |
id: create_pr_main_to_dev | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
commit-message: "Auto pull/sync back changes from 'main' into 'dev'" | |
branch: "dev" | |
base: "main" | |
title: "Auto pull/sync back changes from 'main' into 'dev'" | |
body: "This PR was created automatically to pull back changes from main into dev." | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |