Read-only mirror — the public repositories of the Forgejo instance, refreshed every 10 minutes. The live instance (fg.dieschoenewolke.de) is reachable only over the VPN; clone here with https://git.dieschoenewolke.de/git/<owner>/<repo>.git.
summaryrefslogtreecommitdiff
path: root/src/github-api-helper.ts
diff options
context:
space:
mode:
authoreric sciple <ericsciple@users.noreply.github.com>2019-12-09 20:04:52 -0500
committereric sciple <ericsciple@users.noreply.github.com>2019-12-09 20:04:52 -0500
commit867df47ae6778022c3d84c4af43aeb7130e7cade (patch)
treeed99d7742fb93ce92598b3e7dbc38c7f443bf60e /src/github-api-helper.ts
parent3405b3243471fcdadc0b98dd5cd09008b8caf604 (diff)
.
Diffstat (limited to 'src/github-api-helper.ts')
-rw-r--r--src/github-api-helper.ts26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/github-api-helper.ts b/src/github-api-helper.ts
index 01e3bdd..7c08b00 100644
--- a/src/github-api-helper.ts
+++ b/src/github-api-helper.ts
@@ -41,14 +41,36 @@ export async function downloadRepository(
// }
const runnerTemp = process.env['RUNNER_TEMP'] as string
assert.ok(runnerTemp, 'RUNNER_TEMP not defined')
- const archiveFile = path.join(runnerTemp, 'checkout.tar.gz')
+ const archiveFile = path.join(runnerTemp, 'checkout-archive.tar.gz')
+ await io.rmRF(archiveFile)
await fs.promises.writeFile(archiveFile, new Buffer(response.data))
await exec.exec(`ls -la "${archiveFile}"`, [], {
cwd: repositoryPath
} as ExecOptions)
+
+ const extractPath = path.join(runnerTemp, 'checkout-archive')
+ await io.rmRF(extractPath)
+ await io.mkdirP(extractPath)
await exec.exec(`tar -xzf "${archiveFile}"`, [], {
- cwd: repositoryPath
+ cwd: extractPath
} as ExecOptions)
+
+ // Determine the real directory to copy (ignore extra dir at root of the archive)
+ const archiveFileNames = await fs.promises.readdir(extractPath)
+ assert.ok(
+ archiveFileNames.length == 1,
+ 'Expected exactly one directory inside archive'
+ )
+ const extraDirectoryName = archiveFileNames[0]
+ core.info(`Resolved ${extraDirectoryName}`) // contains the short SHA
+ const tempRepositoryPath = path.join(extractPath, extraDirectoryName)
+
+ for (const fileName of tempRepositoryPath) {
+ const sourcePath = path.join(tempRepositoryPath, fileName)
+ const targetPath = path.join(repositoryPath, fileName)
+ await io.mv(sourcePath, targetPath)
+ }
+
await exec.exec(`find .`, [], {
cwd: repositoryPath
} as ExecOptions)