Skip to content

Commit

Permalink
fix: Fix token-sync utils (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
alanbsmith committed Oct 23, 2023
1 parent 68b38be commit f99b903
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 7 additions & 2 deletions scripts/tokens-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});

Expand Down
4 changes: 2 additions & 2 deletions scripts/utils/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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` */
Expand Down
14 changes: 11 additions & 3 deletions scripts/utils/file-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
}
Expand All @@ -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
);
}
}
6 changes: 3 additions & 3 deletions scripts/utils/pull-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ 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) {
console.error(`⛔️ Error: Failed to create a pull request.`, error.message);
}
}

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 🤖',
Expand Down

0 comments on commit f99b903

Please sign in to comment.