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

After creating releases wait for GitHub to propagate changes #32

Conversation

dgellow
Copy link
Member

@dgellow dgellow commented Sep 11, 2023

Ok, this one was a real pain to debug and find a reliable way to deal with, I approached it way too optimistic! But it is an important fix to make the release creation more reliable and avoid a whole set of issues that would (and currently does) impact end users.

In short, after creating github releases it takes a little bit of time for new/updated data to be available through GitHub's API. We need to wait a bit before assuming data returned by the API are up to date.

In more details, this pull request implements two mitigations for conditions that occur when chaining multiple release-please commands (in Stainless case, running createReleases() directly followed by createPullRequests()).

  1. We now wait a bit after creating a release to be sure it is returned by octokit.repos.listReleases()
  2. We also wait a bit after re-aligning next on top of main to be sure fetching the manifest returns the updated version
  3. We also need to be sure we aren't relying on objects with outdated state or data fetched from an old cache after changing git refs

Note that we did not face this problem before reading the manifest from next, I believe this change is what created conditions for this issue.

Something else to note is that this pull request in itself doesn't fix the whole issue, we also need changes to be sure we aren't using outdated data when re-using the same manifest object for multiple commands. I have a quick fix for this for the monorepo.

In case you're curious, that's the type of logs I get, from what I've seen it takes 1-3s before next content reflects the branch re-alignment:

✔ Align source branch 'next' to target branch 'main', commit '68f63fb0ca6b0f8603b02cdaa156b0403809a232'
❯ PATCH /repos/stainless-sdks/sink-go-public/git/refs/heads%2Fnext - 200 in 358ms
❯ Checking if file .release-please-manifest.json on branch next is up to date on GitHub (attempt 1)...
❯ Fetching '.release-please-manifest.json' from branch 'next'
❯ GET /repos/stainless-sdks/sink-go-public/git/trees/next?recursive=true - 200 in 183ms
❯ GET /repos/stainless-sdks/sink-go-public/git/blobs/4b8769fca013d363492496c81329eb8d71ba4b77 - 200 in 265ms
❯ Checking if file .release-please-manifest.json on branch next is up to date on GitHub (attempt 2)...
❯ Fetching '.release-please-manifest.json' from branch 'next'
❯ GET /repos/stainless-sdks/sink-go-public/git/trees/next?recursive=true - 200 in 232ms
❯ GET /repos/stainless-sdks/sink-go-public/git/blobs/1e4fc9c10cfc6cf53d8a476beb8c9c0b50951a1f - 200 in 208ms
❯ File .release-please-manifest.json on branch next seems up to date on GitHub

@dgellow dgellow changed the title fix: wait for github release to be fetchable after creating one After creating releases wait for GitHub to propagate changes Sep 11, 2023
src/github.ts Outdated
Comment on lines 2294 to 2296
private invalidateFileCache() {
this.fileCache = new RepositoryFileCache(this.octokit, this.repository);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

release-please github client uses RepositoryFileCache from git-file-utils, a simple read-through cache for a repository. But there is currently no way to invalidate entries or easily bypass the cache, so we need to recreate the whole object.

(I opened a feature request here)

src/github.ts Outdated
);
return;
}
await sleepInMs(100 * attempt);
Copy link
Member Author

@dgellow dgellow Sep 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naïve backoff just to avoid sending requests too quickly, I don't think we need anything more fancy here but I may be wrong.

src/github.ts Outdated Show resolved Hide resolved
src/manifest.ts Outdated Show resolved Hide resolved
src/github.ts Outdated Show resolved Hide resolved
Comment on lines +2296 to +2307
} catch (e: unknown) {
// other errors are already retried by octokit-plugin-retry
if (e instanceof FileNotFoundError) {
notFoundError = e;
this.logger.warn(
`Failed to fetch ${filePath} on branch ${branch}`,
notFoundError
);
} else {
throw e;
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcel-stainless I just thought about it, we already handle other errors via octokit/plugin-retry. The only one we need to handle here would be the file-not-found one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will merge the PR as it is, tell me if you want me to rollback or change the error handling here, I can follow-up with a small PR

@dgellow dgellow merged commit 96656d1 into main Sep 12, 2023
@dgellow dgellow deleted the sam/sta-2269-post-apitrigger-release-please-created-unwanted-release-pr branch September 12, 2023 09:54
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 this pull request may close these issues.

2 participants