-
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there a way to run it only while opening PR? #9
Comments
@iamtodor First of all, sorry for the late response. It has been some crazy weeks. Thanks a lot for your interest in our GH action. First of all, it looks like the name: black-formation
on:
pull_request:
branches: [master]
jobs:
black-formation:
name: runner / black-formation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Check files using the black formatter
uses: rickstaa/action-black@v1
id: action_black
with:
black_args: ". --line-length 120"
- name: Create Pull Request
if: steps.action_black.outputs.is_formatted == 'true'
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: "Format Python code with psf/black push"
commit-message: ":art: Format Python code with psf/black"
body: |
There appear to be some python formatting errors in ${{ github.sha }}. This pull request
uses the [psf/black](https://github.com/psf/black) formatter to fix these issues.
base: ${{ github.head_ref }} # Creates pull request onto pull request or commit branch
branch: actions/black Further, you also do not need to use both the Running only when a pull request is merged is not yet possible; however, many workarounds can achieve this behaviour https://github.community/t/trigger-workflow-only-on-pull-request-merge/17359/2. Please comment below if you are still experiencing problems. |
Apparently, there still is some difference between the two actions I documented them in #10. |
Hello @rickstaa Sorry if my first description was unclear |
@iamtodor Ah I see that is supported. Please see the on:
pull_request:
types: [opened, reopened] |
@rickstaa got you, thanks! I find this way to set up run jobs only on PR's commit as it described here: https://stackoverflow.com/a/65096459/5151861 Here is my current config: name: linters
on:
pull_request:
jobs:
flake8-lint:
runs-on: ubuntu-latest
name: linters
steps:
- name: Check out source repository
uses: actions/checkout@v2
- name: Set up Python environment
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: flake8
uses: py-actions/flake8@v2
with:
max-line-length: 120
- name: black
uses: psf/black@stable
with:
src: .
options: --line-length 120
- name: run tests
run: |
pip install pytest pytest-cov
pytest --cov=./ --cov-report=xml
- name: Create Pull Request
if: steps.action_black.outputs.is_formatted == 'true'
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: "Format Python code with psf/black push"
commit-message: ":art: Format Python code with psf/black"
body: |
There appear to be some python formatting errors in ${{ github.sha }}. This pull request
uses the [psf/black](https://github.com/psf/black) formatter to fix these issues.
base: ${{ github.head_ref }} # Creates pull request onto pull request or commit branch
branch: actions/black But the issue is Was it because I used |
@iamtodor Sorry for the late reply. I have had some hectic weeks. From the output, you can see that the if: steps.action_black.outputs.is_formatted == 'true' This is caused by the fact that the |
@rickstaa Hi, thank you for your reply! Perhaps I am confused with all that things :D So I need to change it and everything should work fine? |
@iamtodor No problem. I recommended Lines 69 to 74 in 8908073
Since the official black action does not create this variable, the pull request step in your previous action recipe will always evaluate to |
@rickstaa could you please help me with how should I configure |
@iamtodor Sorry for the late reply. I have been very busy finishing my master Thesis. There are a lot of ways to check if black made changes. Something like this should work: name: linters
on:
pull_request:
jobs:
flake8-lint:
runs-on: ubuntu-latest
name: linters
steps:
- name: Check out source repository
uses: actions/checkout@v2
- name: Set up Python environment
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install black
- name: black
uses: psf/black@stable
with:
src: .
options: --line-length 120
- name: Check for changes
id: action_black
run: |
if [[ $(git status --porcelain | wc -l) -eq 0 ]]; then
echo "::set-output name=is_formatted::false"
else
echo "::set-output name=is_formatted::true"
fi
- name: Check if formatted
run: |
echo ${{needs.action_black.outputs.is_formatted}}
- name: Create Pull Request
if: steps.action_black.outputs.is_formatted == 'true'
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: "Format Python code with psf/black push"
commit-message: ":art: Format Python code with psf/black"
body: |
There appear to be some python formatting errors in ${{ github.sha }}. This pull request
uses the [psf/black](https://github.com/psf/black) formatter to fix these issues.
base: ${{ github.head_ref }} # Creates pull request onto pull request or commit branch
branch: actions/black You can see it in action here. If that is not what you had in mind, I think it is best to create an issue on psf/black or create a stackoverflow question. |
Hello,
The issue
I'm wondering whether there an option to run the black formater not just every single push but rather a PR.
The reason I'm asking is the following: while doing my task I can commit up to 20 commits. Once I think the job has been done I'd like to squash all the commits. After the squash, I'd like to make a PR and then this PR shall be formatted.
What I've tried so far
I've tried to have action-black as a separate workflow with the following config:
However in this case, for some reason, black does not find python files:
So the step
Create Pull Request
has not been run.If there any additional details and information has to be provided in order to investigate please let me know :)
The text was updated successfully, but these errors were encountered: