I'm trying out github actions because I need to make the same changes to a lot of .mei files (xml-language) in my repository. Even after some (bad) attempts at fixing and looking through the documentation, I can't get it to work. The python script uses regex and walks on my own computer, so I think my problem lies within the .yml file.
I get the following error on git commit:
Run git config --global user.name "GitHub Actions"
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
Error: Process completed with exit code 1.
There are files that the regex would apply to which didn't change.
My Python file:
import re
import os
def main():
dir_path = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
for root, dirs, files in os.walk(dir_path):
for file in files:
if file.endswith(".mei"):
filechange(os.path.join(root, file))
def filechange(adress):
with open(adress) as f:
mei=f.read()
mei = re.sub(r"<score[^>]*>\s*(<scoreDef[^>]*)(mnum\.visible=\"\w\")?([^>]*>)",r'\1 mnum.visible="false"\3',mei)
mei = re.sub(r"<meterSig[^>]*>",r'',mei)
mei = re.sub(r"(<slur[^>]*)endid=\"#\d+\"([^>]*>)",r'\1tstamp2="0m+1"\2',mei)
with open(adress,"w") as f:
f.write(mei)
if __name__ == "__main__":
main()
My .yml file:
# This is a basic workflow to help you get started with Actions
name: Change MEI via Python
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
#push:
# branches: [ "main" ]
#pull_request:
#branches: [ "main" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r .github/workflows/requirements.txt
- name: Change files
run: python .github/workflows/meichange.py
- name: Commit changes
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
git add .
git commit -m "Update files"
git push
env:
GITHUB_TOKEN: ${{ secrets.SECRET_GITHUB_TOKEN }}
the requirements.txt file is empty, since os and re are in the standard distribution.
Any help is appreciated, thank you.
Because I'm still testing I commented out the on section. Is there a way to only run the action on certain commit messages (in this case: created mei)?