Create my.py #13
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: Trigger on Pull Request Comment "/trigger" | |
on: | |
pull_request: | |
types: [opened, synchronize, reopened, closed] | |
jobs: | |
trigger_check: | |
name: Check for "/trigger" comment | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Check for trigger comment | |
id: check_comment | |
run: | | |
comments=$(curl -sSL "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.number }}/comments") | |
if [[ $comments == *"'/trigger'"* ]]; then | |
echo "Trigger comment found, proceeding with Pre-commit checks..." | |
exit 0 | |
else | |
echo "No trigger comment found, skipping workflow." | |
exit 1 | |
fi | |
- uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
github.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: 'Pre-commit checks will be triggered when a comment containing "/trigger" is added.' | |
}) | |
# Only run the following steps if the check_comment step succeeds (exit code 0) | |
if: success() | |
pre-commit_checks: | |
name: Pre-commit Checks | |
runs-on: ubuntu-latest | |
needs: trigger_check # This job depends on the trigger_check job | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: 3.x | |
- name: Install pre-commit | |
run: pip install pre-commit | |
- name: Run pre-commit | |
run: pre-commit run --all-files --show-diff-on-failure | |
- name: Run pre-commit-ci-lite | |
uses: pre-commit-ci/lite-action@v1.0.2 | |
if: always() |