Skip to content

Commit

Permalink
Improve build preview message (#984)
Browse files Browse the repository at this point in the history
The build preview message now includes a link to the build preview
instructions, and a collapsible list of all published packages.

Co-authored-by: Maarten Zuidhoorn <[email protected]>
  • Loading branch information
Gudahtt and Mrtenz authored Dec 9, 2022
1 parent a5e5f21 commit 25b122b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .github/workflows/publish-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ jobs:
run: yarn publish-previews
env:
YARN_NPM_AUTH_TOKEN: ${{ secrets.PUBLISH_PREVIEW_NPM_TOKEN }}
- name: Generate preview build message
run: yarn ts-node scripts/generate-preview-build-message.ts
- name: Post build preview in comment
run: gh pr comment "${PR_NUMBER}" -b "Packages published as '[current-version]-preview.${COMMIT_SHA}'"
run: gh pr comment "${PR_NUMBER}" --body-file preview-build-message.txt
env:
COMMIT_SHA: ${{ steps.commit-sha.outputs.COMMIT_SHA }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ package-lock.json
.eslintcache

.DS_STORE

# Build preview message
preview-build-message.txt

packages/*/coverage
packages/*/dist
packages/*/docs
Expand Down
54 changes: 54 additions & 0 deletions scripts/generate-preview-build-message.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!yarn ts-node

import fs from 'fs';
import path from 'path';
import execa from 'execa';

/**
* Write a preview build message to the path "preview-build-message.txt".
*/
async function main() {
const packageMap: Record<string, string> = {};

const { stdout } = await execa('yarn', [
'workspaces',
'list',
'--no-private',
'--json',
]);
const packages = stdout.split('\n').map((line) => JSON.parse(line));
const packageManifestPaths = packages.map(({ location }) =>
path.join(location, 'package.json'),
);
for (const manifestPath of packageManifestPaths) {
const rawManifest = await fs.promises.readFile(manifestPath, {
encoding: 'utf8',
});
const { name, version } = JSON.parse(rawManifest);

packageMap[name] = version;
}

const previewBuildMessage = `
Preview builds have been published. [See these instructions](https://github.com/MetaMask/controllers/blob/main/docs/contributing.md#using-controllers-in-other-projects-during-developmenttesting) for more information about preview builds.
<details>
<summary>Expand for full list of packages and versions.</summary>
\`\`\`
${JSON.stringify(packageMap, null, 2)}
\`\`\`
</details>
`;

const messagePath = path.resolve(__dirname, '../preview-build-message.txt');
await fs.promises.writeFile(messagePath, previewBuildMessage);
}

main().catch((error) => {
console.error(error);
process.exitCode = 1;
});

0 comments on commit 25b122b

Please sign in to comment.