Skip to content
This repository has been archived by the owner on Dec 9, 2023. It is now read-only.

Qodana Publish

Qodana Publish #1460

---
# Receive dispatch events from LizardByte repositories that test with Qodana. This workflow will publish
# artifacts to the `gh-pages` branch.
name: Qodana Publish
on:
workflow_dispatch:
inputs:
repo:
description: 'Repository to publish'
required: true
ref:
description: 'Ref to publish'
required: true
run_id:
description: 'Run ID to publish'
required: true
repo_name:
description: 'Repository name'
required: true
destination:
description: 'Destination to publish'
required: true
status:
description: 'Status of the Qodana run'
required: true
reports_markdown:
description: 'Reports markdown'
required: true
concurrency:
# ensure only one workflow runs for a given repo and ref, cancel in progress to only run the latest
group: ${{ github.event.inputs.repo }}-${{ github.event.inputs.ref }}
cancel-in-progress: true
jobs:
qodana-upload:
runs-on: ubuntu-latest
name: Qodana Upload
steps:
- name: Queue
# we only want to run one add job at a time, so queue them
uses: ahmadnassri/action-workflow-queue@v1
- name: Checkout
uses: actions/checkout@v4
- name: Checkout qodana-reports/gh-pages branch
uses: actions/checkout@v4
with:
ref: gh-pages
path: gh-pages
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of the personal token
fetch-depth: 0 # otherwise, will fail to push refs to dest repo
- name: Download artifacts from triggering repo
uses: dawidd6/action-download-artifact@v2
with:
github_token: ${{ secrets.GH_BOT_TOKEN }}
repo: ${{ github.event.inputs.repo }}
run_id: ${{ github.event.inputs.run_id }}
path: ${{ runner.temp }}/artifacts
- name: Parse artifacts
run: |
# constants
repo_name=${{ github.event.inputs.repo_name }}
destination=${{ github.event.inputs.destination }}
# for each directory in artifacts directory, not recursive
for dir in ${{ runner.temp }}/artifacts/*; do
# get the language from the directory name, e.g. qodana-language
language=${dir##*-}
# check if language is accepted
languages=("default" "dotnet" "go" "java" "js" "php" "python")
if [[ ! " ${languages[@]} " =~ " ${language} " ]]
then
echo "Language ${language} is not supported"
exit 1
fi
# create the output directory
output_dir=./gh-pages/${repo_name}/${destination}/${language}
mkdir -p $output_dir
# empty contents
rm -f -r $output_dir/*
# copy qodana report
cp -f -r $dir/results/report/. $output_dir/
done
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
pip install -r ./requirements.txt
- name: Build site
env:
PAT_TOKEN: ${{ secrets.GH_BOT_TOKEN }}
run: |
# generate index.html
python -u ./build_index.py
# remove index_template.html
rm -f ./gh-pages-template/index_template.html
# copy rest of template, js/css/etc.
cp -f -r ./gh-pages-template/. ./gh-pages/
- name: Deploy to gh-pages
id: deploy
uses: actions-js/[email protected]
with:
github_token: ${{ secrets.GH_BOT_TOKEN }}
author_email: ${{ secrets.GH_BOT_EMAIL }}
author_name: ${{ secrets.GH_BOT_NAME }}
directory: gh-pages
branch: gh-pages
force: false
message: >-
update ${{ github.event.inputs.repo_name }}/${{ github.event.inputs.destination }}
- name: Setup final notification inputs
id: inputs
run: |
# check if destination is integer
if [[ ${{ github.event.inputs.destination }} =~ ^[0-9]+$ ]]; then
# destination is integer, so it's a PR
echo "dispatch=true" >> $GITHUB_OUTPUT
if [[ ${{ github.event.inputs.status }} == 'success' ]]; then
status=":white_check_mark: **Qodana success** :white_check_mark:"
else
status=":x: **Qodana failed** :x:"
fi
message=$(cat <<- EOF
${status}
Results: ${{ github.event.inputs.reports_markdown }}
EOF
)
# escape json control characters
message=$(jq -n --arg message "$message" '$message' | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g')
secondary_inputs=$(echo '{
"issue_message": "'"${message}"'",
"issue_message_id": "'"qodana"'",
"issue_number": "'"${{ github.event.inputs.destination }}"'",
"issue_repo_owner": "'"${{ github.repository_owner }}"'",
"issue_repo_name": "'"${{ github.event.inputs.repo_name }}"'"
}' | jq -r .)
#escape json control characters
secondary_inputs=$(jq -n --arg secondary_inputs "$secondary_inputs" '$secondary_inputs' \
| sed -e 's/\\/\\\\/g' -e 's/"/\\"/g')
echo $secondary_inputs
# secondary input as string, not JSON
# todo - change dispatch_ref to master instead of nightly
primary_inputs=$(echo '{
"dispatch_repository": "'"${{ github.repository_owner }}/.github"'",
"dispatch_workflow": "'"dispatch-issue-comment.yml"'",
"dispatch_ref": "'"nightly"'",
"dispatch_inputs": "'"${secondary_inputs}"'"
}' | jq -c .)
echo $primary_inputs
echo $primary_inputs | jq .
echo "primary_inputs=$primary_inputs" >> $GITHUB_OUTPUT
else
# destination is not integer, so it's a branch
echo "dispatch=false" >> $GITHUB_OUTPUT
fi
- name: Workflow Dispatch
if: ${{ steps.inputs.outputs.dispatch == 'true' }}
uses: benc-uk/[email protected]
with:
ref: ${{ github.base_ref || github.ref_name }} # base ref for PR and branch name for push
workflow: dispatcher.yml
inputs: ${{ steps.inputs.outputs.primary_inputs }}
token: ${{ github.token }}