mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-11-02 11:39:12 +00:00
parent
293ae7626f
commit
51c1228b2a
66
.github/workflows/java-checkstyle-rw.yml
vendored
66
.github/workflows/java-checkstyle-rw.yml
vendored
@ -1,66 +0,0 @@
|
||||
# Copyright 2021 Collate
|
||||
# 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.
|
||||
|
||||
name: Comment on the pull request
|
||||
|
||||
# read-write repo token
|
||||
# access to secrets
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["Run the java checkstyle"]
|
||||
types:
|
||||
- completed
|
||||
|
||||
jobs:
|
||||
comment:
|
||||
runs-on: ubuntu-latest
|
||||
if: >
|
||||
${{ github.event.workflow_run.event == 'pull_request' &&
|
||||
github.event.workflow_run.conclusion == 'success' }}
|
||||
steps:
|
||||
- name: 'Download artifact'
|
||||
uses: actions/github-script@v3.1.0
|
||||
with:
|
||||
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));
|
||||
- run: unzip pr.zip
|
||||
|
||||
- name: 'Comment on PR'
|
||||
uses: actions/github-script@v3
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
var fs = require('fs');
|
||||
var issue_number = Number(fs.readFileSync('./NR'));
|
||||
var error = Number(fs.readFileSync('./checkstyle_exit_code')) > 0
|
||||
if (error) {
|
||||
await github.issues.createComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: issue_number,
|
||||
body: '**The Java checkstyle failed.**\n\nPlease run `mvn googleformatter:format@reformat-sources` in the root of your repository and commit the changes to this PR. You can also use [pre-commit](https://pre-commit.com/) to automate the Java code formatting.'
|
||||
});
|
||||
}
|
||||
@ -9,17 +9,17 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
name: Run the java checkstyle
|
||||
name: Java checkstyle
|
||||
|
||||
# read-only repo token
|
||||
# no access to secrets
|
||||
# read-write repo token
|
||||
# access to secrets
|
||||
on:
|
||||
pull_request_target:
|
||||
branches: [ main ]
|
||||
paths:
|
||||
- "catalog-rest-service/**"
|
||||
- "common/**"
|
||||
- "openmetadata-ui/**"
|
||||
- "openmetadata-ui/src/test/java/**"
|
||||
|
||||
jobs:
|
||||
check:
|
||||
@ -33,6 +33,8 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
ref: ${{ github.event.pull_request.head.sha }}
|
||||
|
||||
- name: Set up JDK 11
|
||||
uses: actions/setup-java@v1
|
||||
@ -42,26 +44,23 @@ jobs:
|
||||
- name: Run checkstyle
|
||||
run: mvn googleformatter:format@reformat-sources
|
||||
|
||||
- name: Save checkstyle outcome and PR number
|
||||
shell: bash {0}
|
||||
- name: Save checkstyle outcome
|
||||
id: git
|
||||
continue-on-error: true
|
||||
run: |
|
||||
mkdir -p ./pr
|
||||
git diff-files --quiet
|
||||
echo $? > ./pr/checkstyle_exit_code
|
||||
echo ${{ github.event.number }} > ./pr/NR
|
||||
|
||||
- name: Upload checkstyle outcome and PR number
|
||||
uses: actions/upload-artifact@v2
|
||||
- name: Create a comment in the PR with the instructions
|
||||
if: steps.git.outcome != 'success'
|
||||
uses: peter-evans/create-or-update-comment@v1
|
||||
with:
|
||||
name: pr
|
||||
path: pr/
|
||||
issue-number: ${{ github.event.pull_request.number }}
|
||||
body: |
|
||||
**The Java checkstyle failed.**
|
||||
|
||||
- name: Fail if Java checkstyle failed
|
||||
uses: actions/github-script@v3
|
||||
with:
|
||||
script: |
|
||||
var fs = require('fs');
|
||||
var error = Number(fs.readFileSync('./pr/checkstyle_exit_code')) > 0
|
||||
if (error) {
|
||||
process.exit(error)
|
||||
}
|
||||
Please run `mvn googleformatter:format@reformat-sources` in the root of your repository and commit the changes to this PR. You can also use [pre-commit](https://pre-commit.com/) to automate the Java code formatting.
|
||||
|
||||
- name: Java checkstyle failed, check the comment in the PR
|
||||
if: steps.git.outcome != 'success'
|
||||
run: |
|
||||
exit 1
|
||||
Loading…
x
Reference in New Issue
Block a user