mirror of https://github.com/hpcaitech/ColossalAI
[workflow] moved pre-commit to post-commit (#2895)
parent
8c8a39be95
commit
e33c043dec
|
@ -35,10 +35,9 @@ I will provide the details of each workflow below.
|
|||
|
||||
### Code Style Check
|
||||
|
||||
| Workflow Name | File name | Description |
|
||||
| --------------------------- | ------------------------------ | ---------------------------------------------------------------------------------------------------------- |
|
||||
| `Pre-commit` | `pre_commit.yml` | This workflow runs pre-commit checks for code style consistency for PRs. |
|
||||
| `Report pre-commit failure` | `report_precommit_failure.yml` | This PR will put up a comment in the PR to explain the precommit failure and remedy if `Pre-commit` fails. |
|
||||
| Workflow Name | File name | Description |
|
||||
| ------------- | ----------------- | -------------------------------------------------------------------------------------------------------------- |
|
||||
| `post-commit` | `post_commit.yml` | This workflow runs pre-commit checks for changed files to achieve code style consistency after a PR is merged. |
|
||||
|
||||
### Unit Test
|
||||
|
||||
|
@ -130,8 +129,7 @@ This file controls which CUDA versions will be checked against CUDA extenson bui
|
|||
## Progress Log
|
||||
|
||||
- [x] Code style check
|
||||
- [x] pre-commit check
|
||||
- [x] pre-commit failure report
|
||||
- [x] post-commit check
|
||||
- [x] unit testing
|
||||
- [x] test on PR
|
||||
- [x] report test coverage
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
name: pre-commit
|
||||
name: post-commit
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types:
|
||||
- closed
|
||||
|
||||
jobs:
|
||||
# this job will run after a PR is merged to run pre-commit on any changed file
|
||||
# so that the user does not need to learn pre-commit and pre-commit can still
|
||||
# be auto-executed by the workflow
|
||||
pre-commit:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event.pull_request.merged == true && github.repository == 'hpcaitech/ColossalAI'
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
|
@ -36,6 +42,11 @@ jobs:
|
|||
echo "$file was changed"
|
||||
done
|
||||
|
||||
# check out the main branch
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
ref: 'main'
|
||||
|
||||
- uses: actions/setup-python@v3
|
||||
|
||||
- name: Cache pre-commit hooks
|
||||
|
@ -49,23 +60,32 @@ jobs:
|
|||
pip install pre-commit
|
||||
pre-commit install
|
||||
|
||||
- name: Run pre-commit on Changed Files
|
||||
id: precommit
|
||||
# run pre-commit on changed files
|
||||
- name: Run Pre-commit
|
||||
run: |
|
||||
for file in ${{ steps.find-changed-files.outputs.all_changed_files }}; do
|
||||
echo "======= running pre-commit on ${file} ======="
|
||||
pre-commit run --files $file
|
||||
pre-commit run --files $file || true
|
||||
done
|
||||
|
||||
- name: Save PR number
|
||||
if: always()
|
||||
env:
|
||||
PR_NUMBER: ${{ github.event.number }}
|
||||
# create commit for pre-commit
|
||||
- name: Create commits
|
||||
run: |
|
||||
mkdir -p ./pr
|
||||
echo $PR_NUMBER > ./pr/pr_number
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: always()
|
||||
git config --global user.name 'github-actions'
|
||||
git config --global user.email 'github-actions@github.com'
|
||||
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
|
||||
git add -A
|
||||
git commit -am "[format] applied code formatting on changed files in pull request ${{ github.event.pull_request.number }}"
|
||||
|
||||
# create pull request
|
||||
- name: Create Pull Request
|
||||
id: cpr
|
||||
uses: peter-evans/create-pull-request@v4
|
||||
with:
|
||||
name: pr_number
|
||||
path: pr/
|
||||
branch: pre-commit-${{ github.event.pull_request.number }}
|
||||
title: "[format] applied code formatting on changed files in PR ${{ github.event.pull_request.number }}"
|
||||
|
||||
- name: Enable Auto-merge for the New PR
|
||||
uses: peter-evans/enable-pull-request-automerge@v2
|
||||
with:
|
||||
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
|
||||
merge-method: squash
|
|
@ -1,67 +0,0 @@
|
|||
name: Report Precommit Failure
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: [pre-commit]
|
||||
types:
|
||||
- completed
|
||||
|
||||
jobs:
|
||||
# comment with a message on how to do pre-commit
|
||||
# if the pre-commit check was not passed
|
||||
report-precommit-failure:
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
|
||||
steps:
|
||||
- name: 'Download artifact'
|
||||
uses: actions/github-script@v6
|
||||
with:
|
||||
script: |
|
||||
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
run_id: context.payload.workflow_run.id,
|
||||
});
|
||||
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
|
||||
return artifact.name == "pr_number"
|
||||
})[0];
|
||||
let download = await github.rest.actions.downloadArtifact({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
artifact_id: matchArtifact.id,
|
||||
archive_format: 'zip',
|
||||
});
|
||||
let fs = require('fs');
|
||||
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/pr_number.zip`, Buffer.from(download.data));
|
||||
|
||||
- name: 'Unzip artifact'
|
||||
run: unzip pr_number.zip
|
||||
|
||||
- name: 'Comment on PR'
|
||||
uses: actions/github-script@v6
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
let fs = require('fs');
|
||||
let issue_number = Number(fs.readFileSync('./pr_number'));
|
||||
let owner = context.repo.owner;
|
||||
let repo = context.repo.repo;
|
||||
let run_id = context.payload.workflow_run.id;
|
||||
let run_url = `https://github.com/${owner}/${repo}/actions/runs/${run_id}`
|
||||
let body = `
|
||||
Your pre-commit check failed, follow the steps to run pre-commit on your file for code style consistency.
|
||||
|
||||
1. install pre-commit via "pip install pre-commit"
|
||||
2. install pre-commit hooks via "pre-commit install"
|
||||
3. run pre-commit on file with format error via "pre-commit run --files path" by replacing "path" with the actual file path
|
||||
4. commit and push to your branch
|
||||
|
||||
View your job at ${run_url}.
|
||||
Read our "CONTRIBUTING.md" for more reference to the code style.
|
||||
`;
|
||||
await github.rest.issues.createComment({
|
||||
owner: owner,
|
||||
repo: repo,
|
||||
issue_number: issue_number,
|
||||
body: body
|
||||
});
|
Loading…
Reference in New Issue