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

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?



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 smac89