Skip to content
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

github-action-required-labels doesn't detect label changes from previous steps #14

Closed
dil-dvinnai opened this issue Jan 5, 2022 · 2 comments · Fixed by #15
Closed

Comments

@dil-dvinnai
Copy link

dil-dvinnai commented Jan 5, 2022

When mheap/github-action-required-labels@v1 is used in a multi-step workflow, it won't detect label changes from previous steps, causing the condition of having at least 1 label fail.
Steps to replicate the issue:

  1. Setup files in the repo. release-drafter/release-drafter@v5.15.0 is capable of automatically labeling pull request based on certain criteria, e.g. taking it from the branch prefix, like feature/JIRA-123 -> because of feature prefix, labeling it as enhancement

.github/workflows/pr-label-enforcer.yaml:


on:
  pull_request:
    types: [opened, edited, labeled, unlabeled, synchronize]
jobs:
  pr-label-enforcer:
    runs-on: ubuntu-latest
    steps:
        # Only runs for PR 'opened' trigger. Because job steps run in a sequential order, 'check_label' will use the added label
      - name: Release Drafter - add label for opened PR
        if: github.event.action == 'opened'
        uses: release-drafter/release-drafter@v5.15.0
        with:
          disable-autolabeler: false
          disable-releaser: false
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: sleep 15
        if: github.event.action == 'opened'
        run: sleep 15
      - name: check_label
        uses: mheap/github-action-required-labels@v1
        with:
          mode: minimum
          count: 1
          labels: "feature, enhancement, fix, bugfix, bug, chore, skip-changelog"

.github/release-drafter.yml:

name-template: $NEXT_PATCH_VERSION
tag-template: $NEXT_PATCH_VERSION
categories:
  - title: 🚀 Features
    labels:
      - 'feature'
      - 'enhancement'
  - title: 🐛 Bug Fixes
    labels:
      - 'fix'
      - 'bugfix'
      - 'bug'
  - title: 🧰 Maintenance
    labels:
      - chore
autolabeler:
  - label: 'enhancement'
    branch:
      - '/feature\/.+/'
  - label: 'bug'
    branch:
      - '/^(bug|fix)+\/.+/'
exclude-labels:
  - 'skip-changelog'
change-template: "- $TITLE @$AUTHOR (#$NUMBER)"
template: |
  ## What’s Changed

  $CHANGES
  

  1. Submit a PR from e.g. feature/JIRA-123 branch. mheap/github-action-required-labels@v1 adds the label enhancement, the second step sleeps for 15 seconds, still, release-drafter/release-drafter@v5.15.0 fails with an error of not finding any labels.
    Unfortunately, this causes the workflow to fail on every PR open, because the label checker will fail, and then have to be triggered again manually to pass. The use case of this whole automation would be to enforce labels in all PRs, but also automatically tag PRs when possible.
@mheap
Copy link
Owner

mheap commented Jan 5, 2022

Thanks for the report! I've just release v1.2.0 with a fix for this. The issue is that the event.json file is static once the job starts. I've added a check to see if GITHUB_TOKEN is set, and if so it will query the API for live information rather than using the event.json file.

You can use it like so:

- uses: mheap/github-action-required-labels@v1
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  with:
    mode: exactly
    count: 1
    labels: "semver:patch, semver:minor, semver:major"

You can continue to use mheap/github-action-required-labels@v1 as the tag has been updated to point to v1.2.0 - all you need to do is provide the GITHUB_TOKEN to use

@dil-dvinnai
Copy link
Author

Thanks, Michael, it works as expected!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants