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

Test all-in-one from bottom to top #17

Closed
wants to merge 13 commits into from
281 changes: 281 additions & 0 deletions .github/workflows/regression-report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,281 @@
name: Report-By-Comment
env:
AWS_REGION: ap-south-1
AWS_BUCKET_NAME: "chesktyler-reports"
USER_LOGIN: ${{ github.event.issue.user.login }}

on:
issue_comment:
types: [ created ]

permissions:
contents: read
pull-requests: write

concurrency:
# run_id is guaranteed to be unique and present
group: ${{ github.run_id }}
cancel-in-progress: false

jobs:
parse_comment:
if: |
github.event.issue.pull_request
&& (startsWith(github.event.comment.body, 'Github, generate report for ')
|| startsWith(github.event.comment.body, 'GitHub, generate report for '))
runs-on: ubuntu-latest
outputs:
config_bundle_path: ${{ steps.parse.outputs.config_bundle_path }}
config_link: ${{ steps.set_links.outputs.config_link }}
projects_link: ${{ steps.set_links.outputs.projects_link }}
branch: ${{ steps.set_branch.outputs.ref }}
commit_sha: ${{ steps.set_branch.outputs.commit_sha }}

steps:
- uses: shanegenschaw/[email protected]
name: React with rocket on run
with:
trigger: ','
reaction: rocket
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'

- run: 'echo We print it here for this action to work'
if: 'true'

- name: Checkout repository
uses: actions/checkout@v4

- name: Parse comment
id: parse
env:
COMMENT_BODY: ${{ github.event.comment.body }}
run: |
CONFIG_BUNDLE_PATH=$(echo "$COMMENT_BODY" | \
sed -E 's/.*(Github|GitHub), generate report for //g')
echo "CONFIG_BUNDLE_PATH=$CONFIG_BUNDLE_PATH"
./.ci/append-to-github-output.sh "config_bundle_path" "$CONFIG_BUNDLE_PATH"

- name: Set config and projects links
id: set_links
run: |
BASE_URL="https://raw.githubusercontent.com/checkstyle/test-configs/main"
CONFIG_BUNDLE_PATH="${{ steps.parse.outputs.config_bundle_path }}"
CONFIG_LINK="$BASE_URL/$CONFIG_BUNDLE_PATH/config.xml"
PROJECTS_LINK="$BASE_URL/$CONFIG_BUNDLE_PATH/list-of-projects.properties"
echo "CONFIG_LINK=$CONFIG_LINK"
echo "PROJECTS_LINK=$PROJECTS_LINK"
./.ci/append-to-github-output.sh "config_link" "$CONFIG_LINK"
./.ci/append-to-github-output.sh "projects_link" "$PROJECTS_LINK"

- name: Set branch
env:
PULL_REQUEST_URL: ${{ github.event.issue.pull_request.url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
id: set_branch
run: |
mkdir -p .ci-temp
curl --fail-with-body -X GET "${PULL_REQUEST_URL}" \
-H "Accept: application/vnd.github+json" \
-H "Authorization: token $GITHUB_TOKEN" \
-o .ci-temp/info.json

jq --raw-output .head.ref .ci-temp/info.json > .ci-temp/branch
jq --raw-output .head.sha .ci-temp/info.json > .ci-temp/commit_sha

./.ci/append-to-github-output.sh "ref" "$(cat .ci-temp/branch)"
# shellcheck disable=SC2002
./.ci/append-to-github-output.sh "commit_sha" "$(cat .ci-temp/commit_sha | cut -c 1-7)"

echo "GITHUB_OUTPUT:"
# need to 'echo' to see output in Github CI
# shellcheck disable=SC2005
echo "$(cat "$GITHUB_OUTPUT")"

make_report:
runs-on: ubuntu-latest
needs: parse_comment
if: needs.parse_comment.outputs.config_link != ''
|| needs.parse_comment.outputs.projects_link != ''
outputs:
message: ${{ steps.out.outputs.message }}
steps:

- name: Download checkstyle
uses: actions/checkout@v4

- name: Download files
env:
DIFF_CONFIG_LINK: ${{ needs.parse_comment.outputs.config_link }}
DIFF_PROJECTS_LINK: ${{ needs.parse_comment.outputs.projects_link }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
./.ci/diff-report.sh download-files

# set main checkstyle repo as an upstream
# Diff report will be generated taking upstream's master branch as a base branch
- name: set upstream
run: |
bash
MAIN_REPO_GIT_URL="https://github.com/checkstyle/checkstyle.git"
git remote add upstream "$MAIN_REPO_GIT_URL"
git fetch upstream
FORK_REPO_GIT_URL="https://github.com/$USER_LOGIN/checkstyle.git"
git remote add forked "$FORK_REPO_GIT_URL"
git fetch forked

- name: Setup local maven cache
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: checkstyle-maven-cache-${{ hashFiles('**/pom.xml') }}

- name: Download contribution
uses: actions/checkout@v4
with:
repository: checkstyle/contribution
path: .ci-temp/contribution

- name: Prepare environment
run: |
mv .ci-temp/project.properties ./.ci-temp/contribution/checkstyle-tester/
mv .ci-temp/*.xml ./.ci-temp/contribution/checkstyle-tester/
sudo apt install groovy

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Generate report
env:
BRANCH: ${{ needs.parse_comment.outputs.branch }}
run: |
# Start from the repository root
cd $GITHUB_WORKSPACE

# Ensure we have the latest branches
git fetch --all --prune

# Set variables
REF="forked/$BRANCH"
REPO="$GITHUB_WORKSPACE"
BASE_BRANCH="upstream/master"

# Verify the branch exists
if ! git rev-parse --verify "$REF" >/dev/null 2>&1; then
echo "Error: Branch $REF does not exist!"
git branch -a # List all branches for debugging
exit 1
fi

# Change to the checkstyle-tester directory
cd .ci-temp/contribution/checkstyle-tester

# Set Maven options
export MAVEN_OPTS="-Xmx5g"

# Run the appropriate Groovy command
if [ -f new_module_config.xml ]; then
groovy diff.groovy -r "$REPO" -p "$REF" -pc new_module_config.xml -m single \
-l project.properties -xm "-Dcheckstyle.failsOnError=false" \
--allowExcludes
elif [ -f patch_config.xml ]; then
groovy diff.groovy -r "$REPO" -b "$BASE_BRANCH" -p "$REF" -bc diff_config.xml \
-pc patch_config.xml -l project.properties -xm "-Dcheckstyle.failsOnError=false" \
--allowExcludes
else
groovy diff.groovy -r "$REPO" -b "$BASE_BRANCH" -p "$REF" -c diff_config.xml \
-l project.properties -xm "-Dcheckstyle.failsOnError=false" \
--allowExcludes
fi

# - name: Generate report
# env:
# BRANCH: ${{ needs.parse_body.outputs.branch }}
# run: |
# cd .ci-temp/contribution/checkstyle-tester
# bash
# REF="forked/$BRANCH"
# REPO="../../../../checkstyle"
# BASE_BRANCH="upstream/master"
# export MAVEN_OPTS="-Xmx5g"
# if [ -f new_module_config.xml ]; then
# groovy diff.groovy -r "$REPO" -p "$REF" -pc new_module_config.xml -m single\
# -l project.properties -xm "-Dcheckstyle.failsOnError=false"\
# --allowExcludes
# elif [ -f patch_config.xml ]; then
# groovy diff.groovy -r "$REPO" -b "$BASE_BRANCH" -p "$REF" -bc diff_config.xml\
# -pc patch_config.xml -l project.properties -xm "-Dcheckstyle.failsOnError=false"\
# --allowExcludes
# else
# groovy diff.groovy -r "$REPO" -b "$BASE_BRANCH" -p "$REF" -c diff_config.xml\
# -l project.properties -xm "-Dcheckstyle.failsOnError=false"\
# --allowExcludes
# fi

- name: Copy Report to AWS S3 Bucket
run: |
bash
TIME=$(date +%Y%H%M%S)
FOLDER="${{needs.parse_comment.outputs.commit_sha}}_$TIME"
DIFF="./.ci-temp/contribution/checkstyle-tester/reports/diff"
LINK="https://${{env.AWS_BUCKET_NAME}}.s3.${{env.AWS_REGION}}.amazonaws.com"
aws s3 cp $DIFF "s3://${{env.AWS_BUCKET_NAME}}/$FOLDER/reports/diff/" --recursive
if [ -n "$LABEL" ]; then
echo "$LABEL: " > .ci-temp/message
fi
echo "$LINK/$FOLDER/reports/diff/index.html" >> .ci-temp/message

- name: Set output
id: out
run: |
./.ci/append-to-github-output.sh "message" "$(cat .ci-temp/message)"

# should be always last step
send_message:
runs-on: ubuntu-latest
needs: [ parse_comment, make_report ]
if: failure() || success()
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Get message
env:
MSG: ${{ needs.make_report.outputs.message }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mkdir -p .ci-temp
if [ -z "$MSG" ]; then
JOBS_LINK="https://github.com/checkstyle/checkstyle/actions/runs/${{github.run_id}}"
API_LINK="https://api.github.com/repos/checkstyle/checkstyle/actions/runs/"
API_LINK="${API_LINK}${{github.run_id}}/jobs"

curl --fail-with-body -X GET "${API_LINK}" \
-H "Accept: application/vnd.github+json" \
-H "Authorization: token $GITHUB_TOKEN" \
-o .ci-temp/info.json

jq '.jobs' .ci-temp/info.json > ".ci-temp/jobs"
jq '.[] | select(.conclusion == "failure") | .name' .ci-temp/jobs > .ci-temp/job_name
jq '.[] | select(.conclusion == "failure") | .steps' .ci-temp/jobs > .ci-temp/steps
jq '.[] | select(.conclusion == "failure") | .name' .ci-temp/steps > .ci-temp/step_name
echo "Report generation failed on phase $(cat .ci-temp/job_name)," > .ci-temp/message
echo "step $(cat .ci-temp/step_name).<br>Link: $JOBS_LINK" >> .ci-temp/message
else
echo "$MSG" > .ci-temp/message
fi

- name: Set message
id: out
run: |
./.ci/append-to-github-output.sh "message" "$(cat .ci-temp/message)"

- name: Comment PR
uses: checkstyle/contribution/comment-action@master
with:
message: ${{steps.out.outputs.message}}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ![](https://raw.githubusercontent.com/checkstyle/resources/master/img/checkstyle-logos/checkstyle-logo-260x99.png)

Checkstyle is a tool for checking Java source code for adherence to a Code Standard
Checkstyle is a tool for checking Java source code for adherence to a Code Standard
or set of validation rules (best practices).

[![][travis img]][travis]
Expand Down