actions / toolkit

The GitHub ToolKit for developing GitHub Actions.
https://github.com/features/actions
MIT License
5k stars 1.44k forks source link

github.context.payload.pull_request.title always remains the same when rerunning action. #1204

Open mvashishtha opened 2 years ago

mvashishtha commented 2 years ago

Describe the bug

I am using a github action triggered by pull requests that is basically doing:

const github = require('@actions/github');
const pullRequestTitle = github.context.payload.pull_request.title;

The full code is here.

When I update the PR title after the action runs once, then rerun the action, the action reuses the old PR title! The result is that the action that is supposed to check my PR title can only be used once per commit. I have to push an empty commit to get the action to use the new PR title.

Sample runs: https://github.com/modin-project/modin/actions/runs/3231387461/jobs/5291018196

To Reproduce Steps to reproduce the behavior:

  1. Add this to .github/workflows/ci-required.yml in some github project:
    name: ci-required
    on: pull_request
    jobs:
    check-pr-title:
    runs-on: ubuntu-latest
    steps:
    - uses: Slashgear/action-check-pr-title@v3.0.0
      with:
        regexp: '^(?:FEAT|DOCS|FIX|REFACTOR|TEST|PERF)-#\d+:'
  2. Make a PR with valid title, e.g. TEST-#4982: Require format for PR descriptions instead of commit descriptions
  3. See the check-pr-title job pass, e.g. here
  4. change PR title so it's invalid, e.g. "TESTz-#4982: Require format for PR descriptions instead of commit descriptions"
  5. rerun check-pr-title job in github UI
  6. see check-pr-title job pass even though PR title is now invalid
  7. push empty commit to branch
  8. see check-pr-title job fail because it uses updated PR title

Expected behavior After I update PR title and re-run Github Action, action should use updated PR title.

caoxing9 commented 1 year ago

the same problem, did it work out?

mvashishtha commented 1 year ago

@MikeCxx I haven't found a solution yet.

ogreface commented 1 year ago

I don't think there's an answer, and I kinda think it's by design to keep a consistent view at a given commit. But there are a few loopholes.

I've put in documentation that if someone wants to get the updated PR text, they have to push an empty commit.

There's another option too. I don't think this should work, because it violates the consistency of the design, but if you close and re-open the PR, it will run the checks with the updated PR title.

rodricke commented 1 year ago

Have you tried?

on: pull_request: types: [opened, edited]

joshua-temple commented 1 year ago

Have you tried?

on: pull_request: types: [opened, edited]

This works for the problem at hand, but then any further commits added to the PR under this workflow do not kickoff the GHA again.

So instead, just add synchronized to the list as well, three in total - and this workaround is complete.

I've implemented this (title action) as a separate workflow for the same event type (in my case, pull requests to master) to avoid running the full gambit of CI/CD that traditionally is kicked off for PRs in my project.

So now the title action gets kicked off in tandem, but a commit is not necessary to update the github context.

j1myx commented 3 weeks ago

I have the same problem with github.context.payload.pull_request.requested_reviewers when i add or remove reviewers.