How to run a Github Action's step based on output condition?
Asked Answered
S

2

1

I would like to comment on a PR if there are more than 100 flake8 errors but it's not going to disable the merge button.

My approach is something like this:

name: Flake8 Check
on:  [pull_request]

jobs:
  flake8:
    name: Flake8 Check
    runs-on: ubuntu-latest

    steps:
      - name: Check out code
        uses: actions/checkout@v2

      - name: Install Python
        uses: actions/setup-python@v1
        with:
          python-version: 3.6

      - name: Install dependency
        run: pip install flake8

      - name: Flake8
        id: flake
        run: echo "::set-output name=number::$(flake8 --config=tools/dev/.flake8 --count -qq)"


      - name: comment PR
        uses: unsplash/comment-on-pr@master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          msg: "There are ${{ steps.flake.outputs.number }} Flake8 errors which is a lot :disappointed: \nThis will not block you to merge it but please try to fix them."
          check_for_duplicate_msg: true
        if: ${{ steps.flake.outputs.number }} > 100 

However, it is commenting even though there is less than 100 errors. I've check the documentation and it looks correct to me.

What is that I am missing?

Shammer answered 14/5, 2020 at 15:20 Comment(1)
Alternatively you may put the > 100 inside the double curly braces where you have full boolean evaluation with &&, || and parenthesisMavilia
O
6

On the github actions page for contexts, they recommend not using ${{ }} in the condition of the if context, although they also show an if condition that uses the ${{ }} syntax, but I guess it does not actually work as you have shown here.

So in your case, you need to change your if to:

if: steps.flake.outputs.number > 100
Orndorff answered 14/5, 2020 at 15:54 Comment(0)
C
1

if: ${{ steps.flake.outputs.number }} > 100

The documentation seems to show that using the ${{ }} turns the contents into a string, which won't be helping your comparison.

Cynde answered 23/8, 2023 at 19:46 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Devoted

© 2022 - 2024 — McMap. All rights reserved.