thehanimo / pr-title-checker

An action to automatically check if pull request titles conform to Contribution Guidelines
MIT License
109 stars 36 forks source link

Getting the output of the pr title check to use in the next step #12

Closed lunaticmonk closed 2 years ago

lunaticmonk commented 2 years ago

Hi, here is what I am trying to do:

I want to check the regex in the PR title and when it matches, I want to check if a specific label is applied on the PR or not.

This is how my config json looks:

{
  "LABEL": {
    "name": ""
  },
  "CHECKS": {
    "prefixes": ["xyz: "],
    "regexpFlags": "i",
    "ignoreLabels" : ["dont-check-PRs-with-this-label", "meta"],
    "alwaysPassCI": true
  },
  "MESSAGES": {
    "success": "y",
    "failure": "n",
    "notice": ""
  }
}

And this is how the github action looks:

name: "PR Title Checker"
on:
  pull_request:
    types:
      - opened
      - edited
      - synchronize
      - labeled
      - unlabeled

jobs:
  titleCheck:
    runs-on: [ self-hosted ]
    steps:
      - id: title_check
        name: check pr title for keyword
        uses: thehanimo/pr-title-checker@v1.3.4
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          pass_on_octokit_error: false
          configuration_path: ".github/pr-title.json"
  labelCheck:
    runs-on: [ self-hosted ]
    needs: [ titleCheck ]
#    this check not working
    if: needs.steps.title_check.result == 'y'
    steps:
      - name: check label
        run: echo desired pr

Is there a way I can access the MESSAGES.success in the labelCheck job? Please help.

thehanimo commented 2 years ago

Hi @lunaticmonk! Currently, this action does not return any output. From GitHub Docs, if you want to know whether the previous step had passed/failed/cancelled/skipped, you could check for:

if: ${{ needs.steps.title_check.result == 'success' }} # One of success, failure, cancelled, or skipped

However, your workflow does this automatically and only runs the second action if the first one succeeds. If not, it will be skipped. So I'm not sure if you need this if condition at all.

Let me know if this helps. If you feel that there's a good reason for outputs to be returned by the action, I'd be happy to discuss!

thehanimo commented 2 years ago

Closing due to inactivity.