diff --git a/.github/workflows/pr_script.yml b/.github/workflows/pr_script.yml index 560077e..78a3110 100644 --- a/.github/workflows/pr_script.yml +++ b/.github/workflows/pr_script.yml @@ -11,6 +11,9 @@ on: pre_commit: description: Whether to run the pre-commit script required: false + commit_message: + description: Optional commit message + required: false jobs: build: runs-on: ubuntu-latest @@ -35,5 +38,6 @@ jobs: TARGET: ${{ github.event.inputs.target }} SCRIPT: ${{ github.event.inputs.script }} PRE_COMMIT: ${{ github.event.inputs.pre_commit }} + COMMIT_MESSAGE: ${{ github.event.inputs.commit_message }} run: | python pr_script.py diff --git a/pr_script.py b/pr_script.py index 4b25014..961282b 100644 --- a/pr_script.py +++ b/pr_script.py @@ -33,7 +33,7 @@ def run(cmd, **kwargs): raise e -def run_script(target, script): +def run_script(target, script, commit_message=''): """Run a script on the target pull request URL""" # e.g. https://github.com/foo/bar/pull/81 owner, repo = target.replace("https://github.com/", "").split('/')[:2] @@ -62,7 +62,8 @@ def run_script(target, script): 'git config user.email "41898282+github-actions[bot]@users.noreply.github.com"' ) run('git config user.name "GitHub Action"') - run(f"git commit -a -m 'Run maintainer script' -m 'by {maintainer}' -m '{json.dumps(script)}'") + message = commit_message or "Run maintainer script" + run(f"git commit -a -m '{message}' -m 'by {maintainer}' -m '{json.dumps(script)}'") run(f"git push origin {branch}") @@ -70,6 +71,7 @@ def run_script(target, script): # https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#inputs target = os.environ.get('TARGET') maintainer = os.environ['MAINTAINER'] + commit_message = os.environ.get('COMMIT_MESSAGE', '') try: script = json.loads(os.environ.get('SCRIPT', '[]')) except Exception: @@ -80,4 +82,4 @@ def run_script(target, script): script += ['pre-commit run --all-files'] print(f'Running script on {target}:') print(f' {script}') - run_script(target, script) + run_script(target, script, commit_message)