Skip to content

Commit 5a4ac90

Browse files
authored
Add missing awaits (#379)
* auth-helper: properly await replacement of the token value in the config After writing the `.extraheader` config, we manually replace the token with the actual value. This is done in an `async` function, but we were not `await`ing the result. In our tests, this commit fixes a flakiness we observed where `remote.origin.url` sometimes (very rarely, actually) is not set for submodules. Our interpretation is that the configs are in the process of being rewritten with the correct token value _while_ another `git config` that wants to set the `insteadOf` value is reading the config, which is currently empty. A more idiomatic way to fix this in Typescript would use `Promise.all()`, like this: await Promise.all( configPaths.map(async configPath => { core.debug(`Replacing token placeholder in '${configPath}'`) await this.replaceTokenPlaceholder(configPath) }) ) However, during review of #379 it was decided to keep the `for` loop in the interest of simplicity. Reported by Ian Lynagh. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> * downloadRepository(): await the result of recursive deletions Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> * Ask ESLint to report floating Promises This rule is quite helpful in avoiding hard-to-debug missing `await`s. Note: there are two locations in `src/main.ts` that trigger warnings: the `run()` and the `cleanup()` function are called without `await` and without any `.catch()` clause. In the initial version of #379, this was addressed by adding `.catch()` clauses. However, it was determined that this is boilerplate code that will need to be fixed in a broader way. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> * Rebuild This trick was brought to you by `npm ci && npm run build`. Needed to get the PR build to pass. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent c952173 commit 5a4ac90

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

.eslintrc.json

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@typescript-eslint/no-empty-interface": "error",
2828
"@typescript-eslint/no-explicit-any": "error",
2929
"@typescript-eslint/no-extraneous-class": "error",
30+
"@typescript-eslint/no-floating-promises": "error",
3031
"@typescript-eslint/no-for-in-array": "error",
3132
"@typescript-eslint/no-inferrable-types": "error",
3233
"@typescript-eslint/no-misused-new": "error",

dist/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -5498,7 +5498,7 @@ class GitAuthHelper {
54985498
const configPaths = output.match(/(?<=(^|\n)file:)[^\t]+(?=\tremote\.origin\.url)/g) || [];
54995499
for (const configPath of configPaths) {
55005500
core.debug(`Replacing token placeholder in '${configPath}'`);
5501-
this.replaceTokenPlaceholder(configPath);
5501+
yield this.replaceTokenPlaceholder(configPath);
55025502
}
55035503
if (this.settings.sshKey) {
55045504
// Configure core.sshCommand
@@ -9594,7 +9594,7 @@ function downloadRepository(authToken, owner, repo, ref, commit, repositoryPath)
95949594
else {
95959595
yield toolCache.extractTar(archivePath, extractPath);
95969596
}
9597-
io.rmRF(archivePath);
9597+
yield io.rmRF(archivePath);
95989598
// Determine the path of the repository content. The archive contains
95999599
// a top-level folder and the repository content is inside.
96009600
const archiveFileNames = yield fs.promises.readdir(extractPath);
@@ -9613,7 +9613,7 @@ function downloadRepository(authToken, owner, repo, ref, commit, repositoryPath)
96139613
yield io.mv(sourcePath, targetPath);
96149614
}
96159615
}
9616-
io.rmRF(extractPath);
9616+
yield io.rmRF(extractPath);
96179617
});
96189618
}
96199619
exports.downloadRepository = downloadRepository;

src/git-auth-helper.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class GitAuthHelper {
148148
output.match(/(?<=(^|\n)file:)[^\t]+(?=\tremote\.origin\.url)/g) || []
149149
for (const configPath of configPaths) {
150150
core.debug(`Replacing token placeholder in '${configPath}'`)
151-
this.replaceTokenPlaceholder(configPath)
151+
await this.replaceTokenPlaceholder(configPath)
152152
}
153153

154154
if (this.settings.sshKey) {

src/github-api-helper.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export async function downloadRepository(
4747
} else {
4848
await toolCache.extractTar(archivePath, extractPath)
4949
}
50-
io.rmRF(archivePath)
50+
await io.rmRF(archivePath)
5151

5252
// Determine the path of the repository content. The archive contains
5353
// a top-level folder and the repository content is inside.
@@ -70,7 +70,7 @@ export async function downloadRepository(
7070
await io.mv(sourcePath, targetPath)
7171
}
7272
}
73-
io.rmRF(extractPath)
73+
await io.rmRF(extractPath)
7474
}
7575

7676
/**

0 commit comments

Comments
 (0)