-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5008872
commit d984634
Showing
3 changed files
with
72 additions
and
78 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* This script is used to build out the matrix that is the input | ||
* to the publish job. | ||
* */ | ||
import { appendFileSync } from "node:fs"; | ||
import { argv, env, exit } from "node:process"; | ||
import * as os from "node:os"; | ||
|
||
const { SITES, SITES_CHANGED } = env; | ||
|
||
try { | ||
const [_node, _script, ...userArgs] = argv; | ||
const doBuildAll = userArgs.some((arg) => arg === "--all"); | ||
if (!SITES) { | ||
throw new Error("Needs SITES set. Are you missing the sites.json file?"); | ||
} | ||
|
||
const allSites = JSON.parse(SITES); | ||
if (doBuildAll) { | ||
deploy(allSites); | ||
exit(0); | ||
} else { | ||
if (!SITES_CHANGED || SITES_CHANGED === "") { | ||
throw new Error("SITES_CHANGED is not set"); | ||
} | ||
|
||
deploy(reduceSites(allSites, SITES_CHANGED)); | ||
exit(0); | ||
} | ||
} catch (error) { | ||
console.error("Error building sites", error); | ||
exit(1); | ||
} | ||
|
||
function deploy(sites) { | ||
let matrix = { include: [] }; | ||
for (const [key, value] of Object.entries(sites)) { | ||
matrix.include.push({ package: key, project: value }); | ||
} | ||
appendFileSync( | ||
process.env.GITHUB_OUTPUT, | ||
`matrix=${JSON.stringify(matrix)}${os.EOL}` | ||
); | ||
} | ||
|
||
function reduceSites(allSites, sitesChanged) { | ||
return Object.entries(allSites).reduce((accum, [pkg, project]) => { | ||
if (sitesChanged.includes(pkg)) { | ||
accum["package"] = pkg; | ||
accum["project"] = project; | ||
} | ||
return accum; | ||
}, {}); | ||
} |
This file was deleted.
Oops, something went wrong.