Compare commits

...

2 Commits

Author SHA1 Message Date
Reinier van der Leer
1b016cc0c2 fix up 2025-05-25 19:26:19 +01:00
Reinier van der Leer
013cc4e3a1 ci(repo): add format-on-command workflow 2025-05-25 20:08:17 +02:00

View File

@@ -0,0 +1,89 @@
name: Repo - Format PR on command
on:
issue_comment:
types: [created]
jobs:
run-formatters:
# Run if the PR author or a maintainer comments '!format'
if: >-
github.event.issue.pull_request &&
github.event.comment.body == '!format' &&
(
github.event.comment.user.login == github.event.issue.user.login ||
github.event.comment.author_association == 'OWNER' ||
github.event.comment.author_association == 'MEMBER' ||
github.event.comment.author_association == 'COLLABORATOR'
)
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: read
steps:
- name: Get PR details
id: pr
uses: actions/github-script@v7
with:
script: |
const { data: pullRequest } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
});
core.setOutput('head_repo', pullRequest.head.repo.full_name);
core.setOutput('head_ref', pullRequest.head.ref);
core.setOutput('head_sha', pullRequest.head.sha);
- name: Checkout PR source
uses: actions/checkout@v4
with:
repository: ${{ steps.pr.outputs.head_repo }}
ref: ${{ steps.pr.outputs.head_ref }}
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '21'
- name: Install frontend dependencies
working-directory: autogpt_platform/frontend
run: yarn install --frozen-lockfile
- name: Run frontend formatter
working-directory: autogpt_platform/frontend
run: yarn format
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Install backend dependencies
working-directory: autogpt_platform/backend
run: poetry install
- name: Run backend formatter
working-directory: autogpt_platform/backend
run: poetry run format
# ignore exit status, because format.py also runs pyight
continue-on-error: true
- name: Commit and push changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
if [[ -n $(git status --porcelain) ]]; then
git add .
git commit -m "`!format`"
git push
else
echo "No formatting changes needed"
fi