Skip to content

Commit

Permalink
Add types checking workflows (#3743)
Browse files Browse the repository at this point in the history
  • Loading branch information
garg3133 authored May 22, 2023
1 parent e8bd751 commit ac1a1ff
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 17 deletions.
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/github-script@v3.1.0
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) {
Expand All @@ -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) {
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/missing-types.yml
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/

0 comments on commit ac1a1ff

Please sign in to comment.