Skip to content

Commit

Permalink
add pre-build-checks workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
imda-kwokwk committed Aug 29, 2024
1 parent b945141 commit 89d0901
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/pre-build-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,22 @@ jobs:
- name: Set Branch Variable (pull_request)
if: github.event_name == 'pull_request'
run: |
echo "BRANCH=${{ github.event.pull_request.head.ref }}" >> "$GITHUB_ENV"
echo "PR_NUM=#${{ github.event.pull_request.number }}" >> "$GITHUB_ENV"
- name: Set Branch Variable (workflow_dispatch)
if: github.event_name == 'workflow_dispatch'
run: |
echo "BRANCH=${{ inputs.branch_to_test }}" >> "$GITHUB_ENV"
echo "PR_NUM=#0" >> "$GITHUB_ENV"
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ env.BRANCH }}
submodules: recursive

- name: Setup python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
Expand All @@ -67,18 +72,66 @@ jobs:
# Unit Tests & Coverage
- name: Unit tests with coverage
id: unit_tests
if: ${{ ! cancelled() }}
timeout-minutes: 30
run: |
set +e
bash .ci/run-test.sh
source .ci/gen_pre_build_summ.sh test
test_status=$?
source .ci/gen_pre_build_summ.sh coverage
coverage_status=$?
echo "UNIT_TESTS_STATUS=$UNITTEST_SUMMARY" >> $GITHUB_ENV
echo "CODE_COVERAGE_STATUS=$COVERAGE_SUMMARY" >> $GITHUB_ENV
set -e
if [ $test_status -ne 0 ] || [ $coverage_status -ne 0 ]; then
exit 1
fi
# Code Quality analysis - flake8
- name: Code quality analysis (flake8)
id: code_quality
if: ${{ ! cancelled() }}
run: |
set +e
bash .ci/run-flake8.sh
source .ci/gen_pre_build_summ.sh lint
lint_status=$?
echo "CODE_QUALITY_STATUS=$LINT_SUMMARY" >> $GITHUB_ENV
set -e
exit $lint_status
# pip-audit
- name: Dependency analysis (vulnerabilities & licenses)
id: dependency_analysis
if: ${{ ! cancelled() }}
run: |
set +e
bash .ci/run-pip-audit.sh
source .ci/gen_pre_build_summ.sh dependency
dep_status=$?
source .ci/gen_pre_build_summ.sh license
lic_status=$?
echo "DEPENDENCY_STATUS=$DEPENDENCY_SUMMARY" >> $GITHUB_ENV
echo "LICENSE_STATUS=$LICENSE_SUMMARY" >> $GITHUB_ENV
set -e
if [ $dep_status -ne 0 ] || [ $lic_status -ne 0 ]; then
exit 1
fi
# Send slack notification
- name: Send slack notification
if: ${{ ! cancelled() }}
uses: slackapi/slack-github-action@v1.26.0
with:
payload: |
{
"workflow": "${{ github.repository }} | ${{ github.workflow }} | ${{ env.PR_NUM }}",
"status": "${{ job.status }}",
"details": "${{ env.UNIT_TESTS_STATUS }} | ${{ env.CODE_COVERAGE_STATUS }} | ${{ env.CODE_QUALITY_STATUS }} | ${{ env.DEPENDENCY_STATUS }} | ${{ env.LICENSE_STATUS }}",
"ref": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

0 comments on commit 89d0901

Please sign in to comment.