CI/CD script examples
Sync Plasmic to GitHub from a script
Say you use codegen and want to generate PRs from Plasmic published versions. Perhaps you’re running this from a Jenkins cron job.
Here’s a script that accomplishes this. This is just an example, and this could represent other similar automation built around checking versions.
/** @format */// Read this bottom half of this file to know what to customize!function extractAndCompareVersions(inputString, regex) {const versions = [];let match;while ((match = regex.exec(inputString)) !== null) {versions.push(match[1]);}return versions.length > 0? versions.sort((a, b) => a.localeCompare(b, undefined, { numeric: true, sensitivity: 'base' })).pop(): undefined;}const githubTitles = '' + execSync('gh pr list --json title');// Point to your project IDconst plasmicVersions = '' + execSync('npx plasmic info --json -p PROJECTID');const latestPlasmic = extractAndCompareVersions(githubTitles, /"version": "(\S+)"/g);// Customize this regex to use your version tagging scheme in commit titlesconst latestGithub = extractAndCompareVersions(plasmicVersions, /Plasmic v(\S+)/g);if (latestPlasmic && latestGithub !== latestPlasmic) {const [{ description, author, tags }] = JSON.parse(plasmicVersions).publishedVersions.slice(-1);execSync('npx plasmic sync');// Use the author, description, tags as you want here.// Remember to use the same format for identifying versions as what your regex above uses.execSync('git checkout --branch NEWBRANCH ...');execSync('git add . && git commit -m ...');execSync(`gh pr create ...`);}
Was this page helpful?