-
Notifications
You must be signed in to change notification settings - Fork 946
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
Changeset checker #3554
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
bf0b6a2
changeset script wip
hsubox76 2df7d5b
Add test changeset
hsubox76 fe12b67
Add test analytics change
hsubox76 4b0e6bd
Check for missing packages
hsubox76 3c7d4e1
Test step output
hsubox76 1106320
Restore yarn install and ts
hsubox76 78cd214
Add create comment action
hsubox76 99c84d0
Add correct PR number?
hsubox76 20ce0db
Try update and spaces
hsubox76 dce4cf3
Fix step names
hsubox76 08063b0
Fix formatting, try 2 packages
hsubox76 ff1fafb
Try newlines
hsubox76 9ac3230
Try outputs
hsubox76 f9b880b
quotes
hsubox76 690a8c2
Add paths for no missing packages
hsubox76 ab17ef2
Remove unneeded step ids
hsubox76 67db92c
Add a missing file
hsubox76 19cdbb8
Update text
hsubox76 8182002
Add all packages to changeset
hsubox76 0580ada
Omit 2 packages from changeset again
hsubox76 b112261
Address PR comments
hsubox76 acfb071
Test with a changeset file
hsubox76 4708530
Make a change to packages/app
hsubox76 9643efa
Make a change to packages/app
hsubox76 51baa38
Check that changeset file exists
hsubox76 aca4788
Add all packages to changeset
hsubox76 a8d18c1
Try rotation again: no changeset file
hsubox76 07f9589
New incomplete changelog file
hsubox76 97bce44
Complete changeset file
hsubox76 e584571
Delete changeset file
hsubox76 31180e1
Restore test changes
hsubox76 32cbd5c
Address PR comments
hsubox76 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
Feiyang1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.map(pkg => `- ${pkg}`) | ||
.join('%0A')}` | ||
); | ||
} | ||
process.exit(); | ||
} | ||
} catch (e) { | ||
console.error(chalk`{red ${e}}`); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
main(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.