minor: investigation #87
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##################################################################################### | |
# GitHub Action to generate Checkstyle site. | |
# | |
# Workflow starts when: | |
# 1) issue comment - created, edited | |
# | |
# 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: "Site" | |
env: | |
AWS_REGION: "us-east-2" | |
AWS_BUCKET_NAME: "checkstyle-diff-reports" | |
on: | |
issue_comment: | |
types: [ created, edited ] | |
permissions: | |
contents: read | |
pull-requests: write | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.issue.number || github.ref }} | |
cancel-in-progress: false | |
jobs: | |
parse_pr_info: | |
if: github.event.comment.body == 'GitHub, generate web site' | |
|| github.event.comment.body == 'GitHub, generate website' | |
|| github.event.comment.body == 'GitHub, generate site' | |
runs-on: ubuntu-latest | |
outputs: | |
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: Getting PR description | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
mkdir -p .ci-temp | |
curl --fail-with-body -X GET "${{github.event.issue.pull_request.url}}" \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "Authorization: token $GITHUB_TOKEN" \ | |
-o .ci-temp/info.json | |
jq .head.ref .ci-temp/info.json > .ci-temp/branch | |
jq .head.sha .ci-temp/info.json > .ci-temp/commit_sha | |
- name: Set branch | |
id: branch | |
run: | | |
echo "ref=$(xargs < .ci-temp/branch)" >> "$GITHUB_OUTPUT" | |
echo "commit_sha=$(xargs < .ci-temp/commit_sha | cut -c 1-7)" >> "$GITHUB_OUTPUT" | |
generate_site: | |
needs: parse_pr_info | |
runs-on: ubuntu-latest | |
outputs: | |
message: ${{ steps.out.outputs.message}} | |
steps: | |
- name: Checkout repository from origin | |
uses: actions/checkout@v4 | |
# fetch-depth - number of commits to fetch. | |
# 0 indicates all history for all branches and tags. | |
# 0, because we need access to all branches to create a report. | |
# ref - branch to checkout. | |
- name: Download checkstyle for PR | |
uses: actions/checkout@v4 | |
env: | |
USER_LOGIN: ${{ github.event.issue.user.login }} | |
with: | |
repository: ${{ env.USER_LOGIN }}/checkstyle | |
ref: ${{needs.parse_pr_info.outputs.branch}} | |
path: .ci-temp/checkstyle | |
fetch-depth: 0 | |
- 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: Setup local maven cache | |
uses: actions/cache@v4 | |
with: | |
path: ~/.m2/repository | |
key: checkstyle-maven-cache-${{ hashFiles('**/pom.xml') }} | |
- name: Generate site | |
run: | | |
bash | |
cd .ci-temp/checkstyle | |
mvn -e --no-transfer-progress clean site -Pno-validations -Dmaven.javadoc.skip=false | |
- name: Copy site to AWS S3 Bucket | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
REPOSITORY_OWNER: ${{ github.repository_owner }} | |
run: | | |
bash | |
TIME=$(date +%Y%H%M%S) | |
FOLDER="${{needs.parse_pr_info.outputs.commit_sha}}_$TIME" | |
SITE=".ci-temp/checkstyle/target/site" | |
LINK="https://${{env.AWS_BUCKET_NAME}}.s3.${{env.AWS_REGION}}.amazonaws.com" | |
aws s3 cp "$SITE" "s3://${{env.AWS_BUCKET_NAME}}/$FOLDER/" --recursive | |
echo "$LINK/$FOLDER/index.html" > .ci-temp/message | |
./.ci/generate-extra-site-links.sh ${{ github.event.issue.number }} "$LINK/$FOLDER" | |
- 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: [ generate_site ] | |
if: failure() || success() | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Get message | |
env: | |
MSG: ${{needs.generate_site.outputs.message}} | |
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" | |
echo "API_LINK=${API_LINK}" | |
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 "Site generation job 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 }} |