Skip to content

Changeset checker #3554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 32 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
bf0b6a2
changeset script wip
hsubox76 Jul 28, 2020
2df7d5b
Add test changeset
hsubox76 Jul 28, 2020
fe12b67
Add test analytics change
hsubox76 Jul 28, 2020
4b0e6bd
Check for missing packages
hsubox76 Jul 28, 2020
3c7d4e1
Test step output
hsubox76 Aug 3, 2020
1106320
Restore yarn install and ts
hsubox76 Aug 3, 2020
78cd214
Add create comment action
hsubox76 Aug 3, 2020
99c84d0
Add correct PR number?
hsubox76 Aug 3, 2020
20ce0db
Try update and spaces
hsubox76 Aug 3, 2020
dce4cf3
Fix step names
hsubox76 Aug 3, 2020
08063b0
Fix formatting, try 2 packages
hsubox76 Aug 3, 2020
ff1fafb
Try newlines
hsubox76 Aug 3, 2020
9ac3230
Try outputs
hsubox76 Aug 3, 2020
f9b880b
quotes
hsubox76 Aug 3, 2020
690a8c2
Add paths for no missing packages
hsubox76 Aug 3, 2020
ab17ef2
Remove unneeded step ids
hsubox76 Aug 3, 2020
67db92c
Add a missing file
hsubox76 Aug 3, 2020
19cdbb8
Update text
hsubox76 Aug 3, 2020
8182002
Add all packages to changeset
hsubox76 Aug 3, 2020
0580ada
Omit 2 packages from changeset again
hsubox76 Aug 3, 2020
b112261
Address PR comments
hsubox76 Aug 4, 2020
acfb071
Test with a changeset file
hsubox76 Aug 4, 2020
4708530
Make a change to packages/app
hsubox76 Aug 4, 2020
9643efa
Make a change to packages/app
hsubox76 Aug 4, 2020
51baa38
Check that changeset file exists
hsubox76 Aug 4, 2020
aca4788
Add all packages to changeset
hsubox76 Aug 4, 2020
a8d18c1
Try rotation again: no changeset file
hsubox76 Aug 4, 2020
07f9589
New incomplete changelog file
hsubox76 Aug 4, 2020
97bce44
Complete changeset file
hsubox76 Aug 4, 2020
e584571
Delete changeset file
hsubox76 Aug 4, 2020
31180e1
Restore test changes
hsubox76 Aug 4, 2020
32cbd5c
Address PR comments
hsubox76 Aug 10, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/check-changeset.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Check Changeset

on: pull_request

jobs:
check_changeset:
name: Check changeset vs changed files
runs-on: ubuntu-latest

steps:
- name: Checkout Repo
uses: actions/checkout@master
with:
# This makes Actions fetch all Git history so check_changeset script can diff properly.
- name: Set up Node (10)
uses: actions/setup-node@v1
with:
node-version: 10.x
- name: Yarn install
run: yarn
- name: Run changeset script
run: yarn ts-node-script scripts/check_changeset.ts
id: check-changeset
- name: Read output
run: echo "${{steps.check-changeset.outputs.MISSING_PACKAGES}}"
- name: Find Comment
uses: peter-evans/find-comment@v1
id: fc
with:
issue-number: ${{github.event.number}}
body-includes: Changeset File Check
- name: Create comment (missing packages)
if: ${{!steps.fc.outputs.comment-id && steps.check-changeset.outputs.MISSING_PACKAGES}}
uses: peter-evans/create-or-update-comment@v1
with:
issue-number: ${{github.event.number}}
body: |
### Changeset File Check :warning:
Warning: This PR modifies files in the following packages but they have not been included in the changeset file:
${{steps.check-changeset.outputs.MISSING_PACKAGES}}

Make sure this was intentional.
- name: Update comment (missing packages)
if: ${{steps.fc.outputs.comment-id}}
uses: peter-evans/create-or-update-comment@v1
with:
comment-id: ${{steps.fc.outputs.comment-id}} && steps.check-changeset.outputs.MISSING_PACKAGES}}
edit-mode: replace
body: |
### Changeset File Check :warning:
Warning: This PR modifies files in the following packages but they have not been included in the changeset file:
${{steps.check-changeset.outputs.MISSING_PACKAGES}}

Make sure this was intentional.
- name: Update comment (no missing packages)
if: ${{steps.fc.outputs.comment-id && !steps.check-changeset.outputs.MISSING_PACKAGES}}
uses: peter-evans/create-or-update-comment@v1
with:
comment-id: ${{steps.fc.outputs.comment-id}}
edit-mode: replace
body: |
### Changeset File Check :white_check_mark:
No modified packages are missing from the changeset file.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,15 @@
"@types/child-process-promise": "2.2.1",
"@types/clone": "0.1.30",
"@types/inquirer": "7.3.0",
"@types/listr": "0.14.2",
"@types/long": "4.0.1",
"@types/mocha": "7.0.2",
"@types/mz": "2.7.1",
"@types/node": "12.12.53",
"@types/sinon": "9.0.4",
"@types/sinon-chai": "3.2.4",
"@types/tmp": "0.2.0",
"@types/yargs": "15.0.5",
"@types/listr": "0.14.2",
"@typescript-eslint/eslint-plugin": "2.34.0",
"@typescript-eslint/eslint-plugin-tslint": "2.34.0",
"@typescript-eslint/parser": "2.34.0",
Expand Down Expand Up @@ -111,11 +112,11 @@
"karma-coverage-istanbul-reporter": "2.1.1",
"karma-firefox-launcher": "1.3.0",
"karma-mocha": "2.0.1",
"karma-mocha-reporter": "2.2.5",
"karma-safari-launcher": "1.0.0",
"karma-sauce-launcher": "1.2.0",
"karma-sourcemap-loader": "0.3.7",
"karma-spec-reporter": "0.0.32",
"karma-mocha-reporter": "2.2.5",
"karma-summary-reporter": "1.8.0",
"karma-webpack": "4.0.2",
"lcov-result-merger": "3.1.0",
Expand Down
111 changes: 111 additions & 0 deletions scripts/check_changeset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { resolve } from 'path';
import chalk from 'chalk';
import simpleGit from 'simple-git/promise';
import fs from 'mz/fs';

const root = resolve(__dirname, '..');
const git = simpleGit(root);

/**
* Identify modified packages.
*/
async function getDiffData(): Promise<{
changedPackages: Set<string>;
changesetFile: string;
} | null> {
const diff = await git.diff(['--name-only', 'origin/master...HEAD']);
const changedFiles = diff.split('\n');
let changesetFile = '';
const changedPackages = new Set<string>();
for (const filename of changedFiles) {
// Check for an existing .changeset
const changesetMatch = filename.match(/^\.changeset\/[a-zA-Z-]+\.md/);
if (changesetMatch) {
changesetFile = changesetMatch[0];
}
// Check for changed files inside package dirs.
const pkgMatch = filename.match('^(packages(-exp)?/[a-zA-Z0-9-]+)/.*');
if (pkgMatch && pkgMatch[1]) {
const changedPackage = require(resolve(
root,
pkgMatch[1],
'package.json'
));
if (changedPackage) {
// Add the package itself.
changedPackages.add(changedPackage.name);
}
}
}
if (!changesetFile || changedPackages.size === 0) {
return null;
}
return { changedPackages, changesetFile };
}

async function parseChangesetFile(changesetFile: string) {
const fileExists = await fs.exists(changesetFile);
if (!fileExists) {
process.exit();
}
const fileText: string = await fs.readFile(changesetFile, 'utf8');
const fileParts = fileText.split('---\n');
const packageLines = fileParts[1].split('\n');
const changesetPackages = packageLines
.filter(line => line)
.map(line => {
const [packageName] = line.split(':');
return packageName.replace(/'/g, '');
});
return changesetPackages;
}

async function main() {
try {
const diffData = await getDiffData();
if (diffData == null) {
process.exit();
} else {
const { changedPackages, changesetFile } = diffData;
const changesetPackages = await parseChangesetFile(changesetFile);
const missingPackages = [...changedPackages].filter(
changedPkg => !changesetPackages.includes(changedPkg)
);
if (missingPackages.length > 0) {
/**
* Sets Github Actions output for a step. Pass missing package list to next
* step. See:
* https://github.com/actions/toolkit/blob/master/docs/commands.md#set-outputs
*/
console.log(
`::set-output name=MISSING_PACKAGES::${missingPackages
.map(pkg => `- ${pkg}`)
.join('%0A')}`
);
}
process.exit();
}
} catch (e) {
console.error(chalk`{red ${e}}`);
process.exit(1);
}
}

main();
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2503,6 +2503,13 @@
resolved "https://registry.npmjs.org/@types/mocha/-/mocha-7.0.2.tgz#b17f16cf933597e10d6d78eae3251e692ce8b0ce"
integrity sha512-ZvO2tAcjmMi8V/5Z3JsyofMe3hasRcaw88cto5etSVMwVQfeivGAlEYmaQgceUSVYFofVjT+ioHsATjdWcFt1w==

"@types/[email protected]":
version "2.7.1"
resolved "https://registry.npmjs.org/@types/mz/-/mz-2.7.1.tgz#1ac1d69b039c8b3cbe603972b5c12d3167a84f58"
integrity sha512-H86h7KmRDVs9UeSiQvtUeVhS+WYpJSYSsZrRvNYpGWGiytEqxwEtvgRnINESQtCgnojIH2wS2WgaMTJP0firBw==
dependencies:
"@types/node" "*"

"@types/[email protected]":
version "2.5.7"
resolved "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.5.7.tgz#20a2afffa882ab04d44ca786449a276f9f6bbf3c"
Expand Down