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.

You can get structured data about a project with plasmic info --json:

Copy
{
"id": "PROJECTID",
"name": "My Project Name",
"workspaceId": "wORKSPACEID",
"hostUrl": "https://mydomain.com",
"lastPublishedVersion": "0.0.2",
"publishedVersions": [
{
"version": "0.0.1",
"description": "First commit",
"createdAt": "2023-07-11T23:29:43.362Z",
"createdBy": "user@mydomain.com",
"tags": []
},
{
"version": "0.0.2",
"description": "First commit",
"createdAt": "2023-07-11T23:29:43.362Z",
"createdBy": "user@mydomain.com",
"tags": []
}
]
}

Here’s a script that accomplishes the PR syncing. This is just an example, and this could represent other similar automation built around checking versions.

Copy
/** @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 ID
const 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 titles
const 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?

Have feedback on this page? Let us know on our forum.