-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add types checking workflows (#3743)
- Loading branch information
Showing
2 changed files
with
66 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,46 +1,67 @@ | ||
name: Missing Types Checker | ||
name: Add comment for missing types | ||
|
||
on: | ||
pull_request: | ||
workflow_run: | ||
workflows: ["Check missing types"] | ||
types: | ||
- synchronize | ||
- completed | ||
|
||
jobs: | ||
detect-modified-files: | ||
add_comment: | ||
runs-on: ubuntu-latest | ||
if: > | ||
github.event.workflow_run.event == 'pull_request' && | ||
github.event.workflow_run.conclusion == 'success' | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
- name: 'Download artifact' | ||
uses: actions/[email protected] | ||
with: | ||
fetch-depth: 0 | ||
script: | | ||
var artifacts = await github.actions.listWorkflowRunArtifacts({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
run_id: ${{github.event.workflow_run.id }}, | ||
}); | ||
var matchArtifact = artifacts.data.artifacts.filter((artifact) => { | ||
return artifact.name == "pr" | ||
})[0]; | ||
var download = await github.actions.downloadArtifact({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
artifact_id: matchArtifact.id, | ||
archive_format: 'zip', | ||
}); | ||
var fs = require('fs'); | ||
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data)); | ||
- name: Get modified files | ||
- name: 'Read artifact' | ||
id: modified-files | ||
run: | | ||
echo $(git diff --name-only HEAD^ types/) | ||
echo $(git diff --name-only main types/) | ||
echo "::set-output name=modified::$(git diff --name-only HEAD^ types/)" | ||
unzip pr.zip | ||
cat files_changed | ||
echo "modified=$(cat files_changed)" >> "$GITHUB_OUTPUT" | ||
- name: Comment on PR | ||
if: steps.modified-files.outputs.modified == '' | ||
id: comment-on-pr | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
const fs = require('fs'); | ||
const issue_number = Number(fs.readFileSync('./NR')); | ||
const comment = ` | ||
## Status | ||
* ❌ No modified files found in the **types** directory. | ||
Please make sure to include types for any changes you have made. Thank you!.`; | ||
const pullRequest = await github.rest.pulls.get({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
pull_number: context.issue.number | ||
pull_number: issue_number | ||
}); | ||
const comments = await github.rest.issues.listComments({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: context.issue.number | ||
issue_number: issue_number | ||
}); | ||
const existingComment = comments.data.find(comment => comment.user.login === 'github-actions[bot]' && comment.body.includes('No modified files found in the **types** director')); | ||
if (existingComment) { | ||
|
@@ -49,22 +70,25 @@ jobs: | |
await github.rest.issues.createComment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: context.issue.number, | ||
issue_number: issue_number, | ||
body: comment | ||
}); | ||
} | ||
- name: Edit comment on PR | ||
if: steps.modified-files.outputs.modified != '' | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
const fs = require('fs'); | ||
const issue_number = Number(fs.readFileSync('./NR')); | ||
const comment = ` | ||
## Status | ||
* :white_check_mark: Type files updated!`; | ||
const comments = await github.rest.issues.listComments({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: context.issue.number | ||
issue_number: issue_number | ||
}); | ||
const existingComment = comments.data.find(comment => comment.user.login === 'github-actions[bot]' && comment.body.includes('No modified files found in the **types** director')); | ||
if (existingComment) { | ||
|
This file contains 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,25 @@ | ||
name: Check missing types | ||
|
||
on: pull_request | ||
|
||
jobs: | ||
detect-modified-files: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Get modified files | ||
id: modified-files | ||
run: | | ||
echo $(git diff --name-only origin/$GITHUB_BASE_REF $GITHUB_SHA types/ | tr '\n' ',') | ||
mkdir -p ./pr | ||
echo $(git diff --name-only origin/$GITHUB_BASE_REF $GITHUB_SHA types/ | tr '\n' ',') > ./pr/files_changed | ||
echo ${{ github.event.number }} > ./pr/NR | ||
- uses: actions/upload-artifact@v2 | ||
with: | ||
name: pr | ||
path: pr/ |