changesets / action

711 stars 255 forks source link

Does not update existing PR: A pull request already exists for #396

Open edouardr opened 3 months ago

edouardr commented 3 months ago

Since the latest version (v1.4.8) I get an error when a changesets PR already exists.

see the output log

 delete mode 100644 .changeset/wise-nails-wave.md
 create mode 100644 apps/new_file.md
 create mode 100644 apps/my-package/CHANGELOG.md
 create mode 100644 packages/another-package/CHANGELOG.md
/usr/bin/git push origin HEAD:changeset-release/main --force
To https://github.com/MyOrg/MyRepo
 + 4cd5cdb...8c05ff1 HEAD -> changeset-release/main (forced update)
[]
creating pull request
Error: HttpError: Validation Failed: {"resource":"PullRequest","code":"custom","message":"A pull request already exists for MyOrg:changeset-release/main."}
Error: Validation Failed: {"resource":"PullRequest","code":"custom","message":"A pull request already exists for MyOrg:changeset-release/main."}

If we pay attention we can see that we have creating pull request instead of updating found pull request #A_NUMBER.

It seems this would have been introduced by this commit https://github.com/changesets/action/commit/48ab0d2f2e77ae169182d022591ef5c18c931ff2, as we can see [] in the output just before.

This would come from:

/// src/run.ts l.381
 let existingPullRequests = await existingPullRequestsPromise;
  core.info(JSON.stringify(existingPullRequests.data, null, 2));
Andarist commented 3 months ago

Cc @s0

Andarist commented 3 months ago

Weirdly, I see pull requests to be updated just fine using the recent version, for example here.

If we take a close look we can see a lone [] a line above creating pull request. I believe this comes from this line: https://github.com/changesets/action/blob/50750fa876cc1e54c7cb972db5e2f7271fc53d99/src/run.ts#L382

So the response the action got to this request was, indeed, an empty array - indicating that there are no open PRs there. How many do u have? Could you try to programmatically query the same thing as here and report what result do u get back?

s0 commented 3 months ago

Is there any chance that there were multiple workflows being run concurrently that interfered? And what happens when you try to re-run the workflow run, is it consistently doing the same thing?

Shot in the dark, but my current thoughts are:

One potential solution could be to just:

Andarist commented 3 months ago

One potential solution could be to just

OTOH, if this is a race condition this might be a good thing that it fails. It lets the user to correct their concurrency setting.

edouardr commented 3 months ago

Hi guys!

Thanks for the answers. So to let you know, I reverted the action to this commit: aba318e9165b45b7948c60273e0b72fce0a64eb9

      - name: Create Release Pull Request or Publish to npm
        id: changesets
        uses: changesets/action@aba318e9165b45b7948c60273e0b72fce0a64eb9
        with:
          version: pnpm run ci:version
          commit: 'chore(twinops): update versions'
          title: 'chore(twinops): update versions'
          publish: pnpm run ci:publish
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.GPR_ACCESS_TOKEN }}

This successfully updated the existing PR

 {
  "total_count": 1,
  "incomplete_results": false,
  "items": [
    {
    /// ...

updating found pull request #66

Tonight, I'll run

 let existingPullRequests = await existingPullRequestsPromise;
  core.info(JSON.stringify(existingPullRequests.data, null, 2));

To see what the result is.

s0 commented 1 month ago

@edouardr what were the results of your findings?