Skip to content

Code Health Check

Code Health Check #333

Workflow file for this run

name: Code Health Check
on:
schedule:
- cron: "0 6 * * *"
defaults:
run:
shell: bash
jobs:
checks:
name: Code Health Checks
runs-on: ubuntu-latest
steps:
- name: Checkout Policy Framework
uses: actions/checkout@v4
with:
# `repository` is inferred as the "caller" repository
path: framework
# `ref` is inferred as the new commit
- name: CI Check
id: ci_check
working-directory: framework
continue-on-error: true
env:
GITHUB_USER: ${{ secrets.WORKFLOW_USER }}
GITHUB_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
SKIP_CLEANUP: "true"
run: |
EXIT_CODE=0
./build/periodic.sh || EXIT_CODE=$?
echo "CI_EXIT_CODE=${EXIT_CODE}" >> ${GITHUB_ENV}
exit ${EXIT_CODE}
- name: Codebase Check
id: codebase_check
working-directory: framework
continue-on-error: true
env:
SKIP_CLONING: "true"
run: |
EXIT_CODE=0
[[ -d "./stolostron/" ]] && ./build/codebase-check.sh || EXIT_CODE=$?
echo "CODEBASE_EXIT_CODE=${EXIT_CODE}" >> ${GITHUB_ENV}
exit ${EXIT_CODE}
- name: Post results to action summary
id: results
working-directory: framework
if: ${{ always() }}
run: |
SUCCESS_ICON="white_check_mark"
WARNING_ICON="warning"
FAILURE_ICON="no_entry"
echo "ACTION_RESULT=$([[ "${{ env.CI_EXIT_CODE }}" == 0 ]] && [[ "${{ env.CODEBASE_EXIT_CODE }}" == 0 ]] && echo 0 || echo 1)" >> ${GITHUB_ENV}
if [[ -f summary-ci-errors.log ]]; then
echo "CI_SUMMARY=\n\`\`\`\n$(awk '{printf "%s\\n", $0}' summary-ci-errors.log | sed 's/"/\\"/g')\`\`\`" >> ${GITHUB_ENV}
fi
if [[ -f summary-codebase-errors.log ]]; then
echo "CODEBASE_SUMMARY=\n\`\`\`\n$(awk '{printf "%s\\n", $0}' summary-codebase-errors.log | sed 's/"/\\"/g')\`\`\`" >> ${GITHUB_ENV}
fi
CI_ICON=${SUCCESS_ICON}
if [[ "${{ env.CI_EXIT_CODE }}" == 1 ]]; then
CI_ICON=${FAILURE_ICON}
fi
echo "CI_ICON=${CI_ICON}" >> ${GITHUB_ENV}
echo "## :${CI_ICON}: CI Check" >> ${GITHUB_STEP_SUMMARY}
echo "" >> ${GITHUB_STEP_SUMMARY}
if [[ -f ci-errors.log ]]; then
echo "<details><summary>See more</summary>" >> ${GITHUB_STEP_SUMMARY}
echo "" >> ${GITHUB_STEP_SUMMARY}
echo '```' >> ${GITHUB_STEP_SUMMARY}
cat ci-errors.log >> ${GITHUB_STEP_SUMMARY}
echo '```' >> ${GITHUB_STEP_SUMMARY}
echo "" >> ${GITHUB_STEP_SUMMARY}
echo "</details>" >> ${GITHUB_STEP_SUMMARY}
fi
echo "" >> ${GITHUB_STEP_SUMMARY}
CODEBASE_ICON=${SUCCESS_ICON}
if [[ "${{ env.CODEBASE_EXIT_CODE }}" == 1 ]]; then
CODEBASE_ICON=${WARNING_ICON}
elif [[ "${{ env.CODEBASE_EXIT_CODE }}" == 2 ]]; then
CODEBASE_ICON=${FAILURE_ICON}
fi
echo "CODEBASE_ICON=${CODEBASE_ICON}" >> ${GITHUB_ENV}
echo "## :${CODEBASE_ICON}: Codebase Check" >> ${GITHUB_STEP_SUMMARY}
echo "" >> ${GITHUB_STEP_SUMMARY}
if [[ -f codebase-errors.log ]]; then
echo "<details><summary>See more</summary>" >> ${GITHUB_STEP_SUMMARY}
echo "" >> ${GITHUB_STEP_SUMMARY}
echo '```' >> ${GITHUB_STEP_SUMMARY}
cat codebase-errors.log >> ${GITHUB_STEP_SUMMARY}
echo '```' >> ${GITHUB_STEP_SUMMARY}
echo "" >> ${GITHUB_STEP_SUMMARY}
echo "</details>" >> ${GITHUB_STEP_SUMMARY}
fi
- name: Send result to Slack
id: slack
uses: slackapi/[email protected]
if: ${{ always() }}
env:
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
SLACK_WEBHOOK_URL: ${{ secrets.CODE_HEALTH_SLACK_WEBHOOK }}
with:
payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Codebase health check ${{ env.ACTION_RESULT == 0 && 'succeeded' || 'failed' }}: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}#artifacts|View workflow run>\n:${{ env.CI_ICON }}: CI check${{ env.CI_SUMMARY }}\n:${{ env.CODEBASE_ICON }}: Codebase check${{ env.CODEBASE_SUMMARY }}"
}
}
]
}