From f99b90320e5be6830ab5e147c42271fdb018078b Mon Sep 17 00:00:00 2001 From: Alan B Smith Date: Mon, 23 Oct 2023 10:58:08 -0600 Subject: [PATCH] fix: Fix token-sync utils (#52) --- .github/workflows/merge.yml | 4 ++-- .github/workflows/pull-request.yml | 6 +++--- scripts/tokens-config.ts | 9 +++++++-- scripts/utils/api-client.ts | 4 ++-- scripts/utils/file-content.ts | 14 +++++++++++--- scripts/utils/pull-request.ts | 6 +++--- 6 files changed, 28 insertions(+), 15 deletions(-) diff --git a/.github/workflows/merge.yml b/.github/workflows/merge.yml index 72e8737..b7e6e9a 100644 --- a/.github/workflows/merge.yml +++ b/.github/workflows/merge.yml @@ -23,13 +23,13 @@ jobs: - name: Build Tokens shell: bash - run: yarn build:tokens + run: yarn build:tokens --no-cache # Build Storybook and extract component stories for Storybook aggregation. This will be used # for Chromatic rebaselining and publishing to GH Pages. - name: Build Storybook shell: bash - run: yarn build-storybook + run: yarn build-storybook --no-cache - name: Publish Storybook uses: JamesIves/github-pages-deploy-action@v4.4.1 diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 11a52d9..12d4713 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -25,10 +25,10 @@ jobs: node_version: 18.x - name: Build Tokens - run: yarn build:tokens + run: yarn build:tokens --no-cache - name: Build Storybook - run: yarn build-storybook --quiet + run: yarn build-storybook --no-cache - name: Cache Build id: build-cache @@ -54,7 +54,7 @@ jobs: run: yarn lint - name: Build Tokens - run: yarn build:tokens + run: yarn build:tokens --no-cache - name: Type Check shell: bash diff --git a/scripts/tokens-config.ts b/scripts/tokens-config.ts index fdc9898..83c36a4 100644 --- a/scripts/tokens-config.ts +++ b/scripts/tokens-config.ts @@ -45,13 +45,18 @@ program } }); +const baseBranchArg = new Argument('base', 'Specify the base branch for the sync pull request') + .default('main') + .argOptional(); + // Create a pull request to merge updates // yarn tokens-config create-pull program .command('create-pull') + .addArgument(baseBranchArg) .description('Create a pull request to merge the sync updates') - .action(async () => { - await createSyncPullRequest(); + .action(async base => { + await createSyncPullRequest(base); return; }); diff --git a/scripts/utils/api-client.ts b/scripts/utils/api-client.ts index 7524007..47de078 100644 --- a/scripts/utils/api-client.ts +++ b/scripts/utils/api-client.ts @@ -20,14 +20,14 @@ export const tokensStudioRepoParams = { /** `tokens/base.json` */ baseConfigPath: 'tokens/base.json', /** `tokens/brand/default.json` */ - brandConfigPath: 'tokens/brand/default.json', + brandConfigPath: 'tokens/sys/brand/default.json', /** `tokens/sys` */ sysConfigPath: 'tokens/sys', }; export const canvasTokensRepoParams = { /** `design` */ - owner: 'design', + owner: 'workday', /** `canvas-tokens` */ repo: 'canvas-tokens', /** `main` */ diff --git a/scripts/utils/file-content.ts b/scripts/utils/file-content.ts index 805f7b5..d5c0b79 100644 --- a/scripts/utils/file-content.ts +++ b/scripts/utils/file-content.ts @@ -21,10 +21,14 @@ export async function getFileContent( const response = await ghClient.repos.getContent(params); return response.data; } catch (error: any) { + const fullRepo = `${params.owner}/${params.repo}`; if (error.status === 404) { - console.log(`⚠️ Notice: ${params.path} does not exist.\n`); + console.log(`⚠️ Notice: ${params.path} does not exist in ${fullRepo}.\n`); } else { - console.error(`⛔️ Error: Failed to get file content from ${params.path}.`, error.message); + console.error( + `⛔️ Error: Failed to get file content from ${params.path} in ${fullRepo}.`, + error.message + ); } } } @@ -45,6 +49,10 @@ export async function updateFileContent( try { await ghClient.repos.createOrUpdateFileContents(params); } catch (error: any) { - console.error(`⛔️ Error: Failed to update.`, error.message); + const fullRepo = `${params.owner}/${params.repo}`; + console.error( + `⛔️ Error: Failed to update file content for ${params.path} in ${fullRepo}.`, + error.message + ); } } diff --git a/scripts/utils/pull-request.ts b/scripts/utils/pull-request.ts index 967e7f7..38e8566 100644 --- a/scripts/utils/pull-request.ts +++ b/scripts/utils/pull-request.ts @@ -15,7 +15,7 @@ export async function createPullRequest( ) { try { const fullRepo = `${params.owner}/${params.repo}`; - console.log(`Creating a PR to merge ${params.head} to ${params.base} for ${fullRepo}.\n`); + console.log(`Creating a PR to merge ${params.head} to ${params.base} in ${fullRepo}.\n`); await ghClient.pulls.create(params); console.log('✅ Success!\n'); } catch (error: any) { @@ -23,11 +23,11 @@ export async function createPullRequest( } } -export async function createSyncPullRequest() { +export async function createSyncPullRequest(baseBranch = canvasTokensRepoParams.defaultBranch) { await createPullRequest({ owner: canvasTokensRepoParams.owner, repo: canvasTokensRepoParams.repo, - base: canvasTokensRepoParams.defaultBranch, + base: baseBranch, head: canvasTokensRepoParams.syncBranch, maintainer_can_modify: true, title: 'chore: Sync Tokens Studio config 🤖',