Repository navigation
Conversation
362e7d4 to
cd87ccd
Compare
cd87ccd to
133ffeb
Compare
| }, | ||
| ); | ||
|
|
||
| for (const [apiURL, repository] of uniqueDownloadSources) { |
There was a problem hiding this comment.
This is just a URL, not an API URL, i.e. it doesn't start with api.
There was a problem hiding this comment.
The name was just copied from setup-codeql.ts, but I have renamed this to instanceURL to address the feedback. While doing that I also noticed that apiURL /instanceURL isn't actually used at all beyond the short-circuit check and in log messages. That seems like it may have been an oversight in your PR when you added this, because without this we just end up checking for the repos on whatever instance getApiClient decides to use instead of the intended apiURL /instanceURL?
There was a problem hiding this comment.
without this we just end up checking for the repos on whatever instance
getApiClientdecides to use instead of the intendedapiURL/instanceURL?
Sorry, could you explain what you mean by this? The intent is to check the called Action repo on the same GH instance, the canonical github/codeql-action on the same GH instance, followed by github/codeql-action on Dotcom.
There was a problem hiding this comment.
Suppose that we are on GHE with GITHUB_SERVER_URL being something like https://my-org.ghe.com and that GITHUB_ACTION_REPOSITORY is test-org/my-codeql-action-fork, then we have the following (expected/intended) value for potentialDownloadSources:
[
["https://my-org.ghe.com", "test-org/my-codeql-action-fork"],
["https://my-org.ghe.com", "github/codeql-action"],
["http://github.com", "github/codeql-action"]
]
The for (const [instanceURL, repository] of uniqueDownloadSources) loop, however, never explicitly uses instanceURL for getReleaseByTag. The getApiClient call makes its own call to getApiDetails(env) which will always get it the GitHubApiDetails based on GITHUB_SERVER_URL and GITHUB_API_URL.
This happens to work as expected, because the only entry in potentialDownloadSources that would want different GitHubApiDetails is the last element of the array and we short-circuit the getReleaseByTag call there to exit the loop and return the result of getDefaultDotcomDownloadURL.
However, there are two problems with this:
- It is not immediately obvious that this happens to work out for any
potentialDownloadSourcesthat is currently possible. - If we ever make a change that allows an additional entry in
potentialDownloadSourceswhere the instance URL doesn't matchGITHUB_SERVER_URL, or the repository name is notGITHUB_ACTION_REPOSITORYif the instance URL isGITHUB_DOTCOM_URL, then this leads to a hard-to-troubleshoot issue where the short-circuit check doesn't apply and we instead callgetReleaseByTagwith the wrongGitHubApiDetails.
I'd suggest we either change this so that we configure the api client correctly in the loop for the instance given by instanceURL, to avoid shooting ourselves in the foot in the future. Alternatively, we should document this very explicitly and perhaps add a test to make sure we never end up with this scenario. I'll have a look.
| /** | ||
| * Asserts that `stub` must have been called once with at least the `expected` arguments. | ||
| */ | ||
| onceWith: <TArgs extends readonly any[]>( |
There was a problem hiding this comment.
Beyond your later fix in f9a9962, I think this should just be calledWith, since unlike calledOnce / calledOnceWithExactly / calledOnceWithMatch we don't validate that the stub was only called once.
There was a problem hiding this comment.
I am unsure if your comment here is a request to change anything, since f9a9962 has addressed this in the way I had intended.
There was a problem hiding this comment.
The matchers calledOnce, calledOnceWithExactly, and calledOnceWithMatch in sinon each require exactly one call in total, irrespective of the match, whereas this matcher permits the function to be called multiple times. So for consistency I think we should drop the once from the name of this matcher in favour of something like calledWith or calledAtLeastOnceWith.
There was a problem hiding this comment.
[..] whereas this matcher permits the function to be called multiple times.
It doesn't: the t.deepEqual(actual, [expected]) puts expected into a singleton array. It should only match if stub was called exactly once.
To test this as well, I made a local change to the "cleanup removes only old CodeQL TRAP caches" test which has an existing t.is(deleteStub.callCount, 2) assertion. Adding the following:
// Existing assertion
t.is(deleteStub.callCount, 2);
// Locally added new assertion
const st = addSinonAssertions(t);
st.onceWith(deleteStub, 4);Results in a test failure, as expected:
cleanup removes only old CodeQL TRAP caches
src/trap-caching.test.ts:281
280: const st = addSinonAssertions(t);
281: st.onceWith(deleteStub, 4);
282:
Difference (- actual, + expected):
[
[
4,
],
- [
- 3,
- ],
]
henrymercer
left a comment
There was a problem hiding this comment.
Couple of additional comments
The
start-proxyAction currently uses its owngetReleaseByVersionfunction to get hold of the release that we expect to find the proxy assets at. That function has hard-codedownerandrepovalues for the defaultgithub/codeql-actionrepository. This repository may not be available in all environments. In such environments,getReleaseByVersionfails and we fall-back to the hard-coded release obtained fromgetFallbackUrlinstead.Broadly, this PR does the following:
getCodeQLActionRepositoryandgetCodeQLBundleDownloadURLare refactored out ofsetup-codeqlinto a newsetup/repositorymodule.getCodeQLAssetDownloadURL(renamed fromgetCodeQLBundleDownloadURL) in thestart-proxyaction to apply the same logic for finding a suitable release as used bysetup-codeql.getCodeQLBundleDownloadURLis essentially equivalent, except that it uses the linked version rather than a hard-coded one. We have been shipping proxy artifacts successfully with releases for a good while now, so the fallback shouldn't be needed anymore.There are some drive-by improvements to logging and assertions for sinon stubs.
Risk assessment
For internal use only. Please select the risk level of this change:
Which use cases does this change impact?
Workflow types:
dynamicworkflows (Default Setup, Code Quality, ...).Products:
analysis-kinds: code-scanning.analysis-kinds: code-quality.Environments:
github.comand/or GitHub Enterprise Cloud with Data Residency.How did/will you validate this change?
.test.tsfiles).pr-checks).If something goes wrong after this change is released, what are the mitigation and rollback strategies?
How will you know if something goes wrong after this change is released?
Are there any special considerations for merging or releasing this change?
Merge / deployment checklist