Code Health Check #325
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
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} | |
echo "<details><summary>See more</summary>" >> ${GITHUB_STEP_SUMMARY} | |
echo "" >> ${GITHUB_STEP_SUMMARY} | |
echo -e "${CI_SUMMARY}" >> ${GITHUB_STEP_SUMMARY} | |
echo "" >> ${GITHUB_STEP_SUMMARY} | |
echo "</details>" >> ${GITHUB_STEP_SUMMARY} | |
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} | |
echo "<details><summary>See more</summary>" >> ${GITHUB_STEP_SUMMARY} | |
echo "" >> ${GITHUB_STEP_SUMMARY} | |
echo -e "${CODEBASE_SUMMARY}" >> ${GITHUB_STEP_SUMMARY} | |
echo "" >> ${GITHUB_STEP_SUMMARY} | |
echo "</details>" >> ${GITHUB_STEP_SUMMARY} | |
- 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 }}" | |
} | |
} | |
] | |
} |