Skip to content

Issue 14566 str template begin #23

Issue 14566 str template begin

Issue 14566 str template begin #23

Workflow file for this run

#####################################################################################
# GitHub Action to generate Checkstyle report.
#
# Workflow starts when:
# 1) issue comment - created
#
# Requirements:
# 1) secrets.AWS_ACCESS_KEY_ID - access key for AWS S3 service user
# 2) secrets.AWS_SECRET_ACCESS_KEY - security access key for AWS S3 service user
#
# If you need to change bucket name or region, change AWS_REGION and AWS_BUCKET_NAME variables.
# For another bucket, you will need to change the secrets.
#####################################################################################
name: Diff-Report
env:
AWS_REGION: us-east-2
AWS_BUCKET_NAME: "checkstyle-diff-reports"
# yamllint disable-line rule:line-length
DEFAULT_PROJECTS_LINK: "https://raw.githubusercontent.com/checkstyle/contribution/master/checkstyle-tester/projects-to-test-on-for-github-action.properties"
USER_LOGIN: ${{ github.event.issue.user.login }}
on:
issue_comment:
types: [ created, edited ]
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 PR Body, search for links to .properties and .xml files
parse_body:
if: github.event.comment.body == 'GitHub, generate report'
runs-on: ubuntu-latest
outputs:
projects_link: ${{ steps.parse.outputs.projects_link }}
config_link: ${{ steps.parse.outputs.config_link }}
new_module_config_link: ${{ steps.parse.outputs.new_module_config_link }}
patch_config_link: ${{ steps.parse.outputs.patch_config_link }}
report_label: ${{ steps.parse.outputs.report_label }}
branch: ${{ steps.branch.outputs.ref }}
commit_sha: ${{ steps.branch.outputs.commit_sha }}
steps:
- uses: shanegenschaw/pull-request-comment-trigger@v2.1.0
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: Getting PR description
env:
ISSUE_BODY: ${{ github.event.issue.body }}
PULL_REQUEST_URL: ${{ github.event.issue.pull_request.url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mkdir -p .ci-temp
# convert windows line endings to unix in event text
echo "$ISSUE_BODY" > .ci-temp/windows.txt
tr -d '\15\32' < .ci-temp/windows.txt > .ci-temp/text
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
- name: Parsing content of PR description
id: parse
run: |
./.ci/diff-report.sh parse-pr-description-text
- name: Set branch
id: branch
run: |
./.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_body
if: needs.parse_body.outputs.config_link != ''
|| needs.parse_body.outputs.new_module_config_link != ''
outputs:
message: ${{ steps.out.outputs.message }}
steps:
- name: Download checkstyle
uses: actions/checkout@v4
- name: Download files
env:
NEW_MODULE_CONFIG_LINK: ${{ needs.parse_body.outputs.new_module_config_link }}
DIFF_CONFIG_LINK: ${{ needs.parse_body.outputs.config_link }}
PATCH_CONFIG_LINK: ${{ needs.parse_body.outputs.patch_config_link }}
LINK_FROM_PR: ${{ needs.parse_body.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_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
env:
LABEL: ${{ needs.parse_body.outputs.report_label }}
run: |
bash
TIME=$(date +%Y%H%M%S)
FOLDER="${{needs.parse_body.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_body, 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 }}