forked from craws/OpenAtlas-Discovery
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt at making tests work on github actions
Also: more concise deubg messages for tests
- Loading branch information
Showing
4 changed files
with
57 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
import child_process from 'child_process'; | ||
import fs from 'fs-extra' | ||
import fs from 'fs-extra'; | ||
|
||
const clonedContentPath = 'temp'; | ||
|
||
const repo = process.env["CONTENT_REPO"] ?? 'Mocca101/oad-content-test'; | ||
const branch = process.env["CONTENT_BRANCH"] ?? 'main'; | ||
const repo = process.env.CONTENT_REPO ?? 'acdh-oeaw/OpenAtlas-Discovery-Content-Template'; | ||
const branch = process.env.CONTENT_BRANCH ?? 'main'; | ||
const configSourcePath = `${clonedContentPath}/discoveryConfig.json`; | ||
const configDestPath = `config/discoveryConfig.json`; | ||
const configDestPath = 'config/discoveryConfig.json'; | ||
|
||
const contentSourcePath = `${clonedContentPath}/content`; | ||
const contentDestPath = `content`; | ||
const contentDestPath = 'content'; | ||
|
||
const publicSourcePath = `${clonedContentPath}/public`; | ||
const publicDestPath = `public`; | ||
const publicDestPath = 'public'; | ||
|
||
cloneRepo(clonedContentPath, repo, branch); | ||
// Log the commit hash of the content repo | ||
console.log('Content repo commit hash: ', child_process.execSync(`git -C ${clonedContentPath} rev-parse HEAD`).toString().trim()); | ||
|
||
if(fs.existsSync(clonedContentPath)) { | ||
if (fs.existsSync(clonedContentPath)) { | ||
handleConfig(); | ||
handleContent(); | ||
handlePublic(); | ||
|
@@ -32,21 +32,20 @@ if(fs.existsSync(clonedContentPath)) { | |
* @param {string} repo following then format "user/repositoryName" | ||
* @param {string} branch | ||
*/ | ||
function cloneRepo(targetpath, repo, branch, useHttp = true) { | ||
function cloneRepo (targetpath, repo, branch, useHttp = true) { | ||
// From https://cheatcode.co/tutorials/how-to-clone-and-sync-a-github-repo-via-node-js | ||
// child_process.execSync(`git clone ${getBranch(branch)} https://${username}:${process.env.PERSONAL_ACCESS_TOKEN}@github.com/${username}/${repo}.git ${targetpath}`); | ||
|
||
if(fs.existsSync(targetpath)) { | ||
if (fs.existsSync(targetpath)) { | ||
fs.rmSync(clonedContentPath, { recursive: true, force: true }); | ||
} | ||
|
||
if(useHttp) { | ||
if (useHttp) { | ||
console.log(`Attempting to clone ${getBranch(branch)} on https://github.com/${repo}.git to ${targetpath}`); | ||
child_process.execSync(`git clone ${getBranch(branch)} https://github.com/${repo}.git ${targetpath}`); | ||
} else { | ||
console.log(`Attempting to clone ${getBranch(branch)} on [email protected]:${repo}.git to ${targetpath}`); | ||
child_process.execSync(`git clone ${getBranch(branch)} [email protected]:${repo}.git ${targetpath}`); | ||
|
||
} | ||
console.log('Clone successful'); | ||
} | ||
|
@@ -56,40 +55,40 @@ function cloneRepo(targetpath, repo, branch, useHttp = true) { | |
* @param {string} branch | ||
* @returns {string} | ||
*/ | ||
function getBranch(branch) { | ||
function getBranch (branch) { | ||
return branch ? `-b ${branch}` : ''; | ||
} | ||
|
||
function handleConfig() { | ||
if(fs.existsSync(configSourcePath)) { | ||
function handleConfig () { | ||
if (fs.existsSync(configSourcePath)) { | ||
try { | ||
fs.copyFile(configSourcePath, configDestPath); | ||
console.log('Successfully set config from content repo!'); | ||
} catch (err) { | ||
console.error(err) | ||
console.error(err); | ||
} | ||
} | ||
} | ||
|
||
function handleContent() { | ||
if(fs.existsSync(contentSourcePath)) { | ||
function handleContent () { | ||
if (fs.existsSync(contentSourcePath)) { | ||
try { | ||
fs.copySync(contentSourcePath, contentDestPath, { overwrite: true }) | ||
console.log('Successfully set content from content repo!') | ||
fs.copySync(contentSourcePath, contentDestPath, { overwrite: true }); | ||
console.log('Successfully set content from content repo!'); | ||
} catch (err) { | ||
console.error(err) | ||
console.error(err); | ||
} | ||
} | ||
} | ||
|
||
function handlePublic() { | ||
if(fs.existsSync(publicSourcePath)) { | ||
function handlePublic () { | ||
if (fs.existsSync(publicSourcePath)) { | ||
try { | ||
fs.copySync(publicSourcePath, publicDestPath, { overwrite: true }) | ||
console.log('Successfully set public folder from content repo!') | ||
console.log('Public folder contents: ', fs.readdirSync(publicDestPath)) | ||
fs.copySync(publicSourcePath, publicDestPath, { overwrite: true }); | ||
console.log('Successfully set public folder from content repo!'); | ||
console.log('Public folder contents: ', fs.readdirSync(publicDestPath)); | ||
} catch (err) { | ||
console.error(err) | ||
console.error(err); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters