Skip to content
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

Add types checking workflows #3743

Merged
merged 5 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
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) {
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
26 changes: 26 additions & 0 deletions .github/workflows/missing-types.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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/