From 9d1cd6d3f82ef9f508513eebf7fb03d2522c571d Mon Sep 17 00:00:00 2001 From: drorganvidez Date: Sun, 23 Jun 2024 17:15:53 +0200 Subject: [PATCH] feat: Improve CI / CD --- .github/workflows/deloyment_on_webhook.yml | 48 ++++++++++------------ .github/workflows/lint.yml | 13 +++++- .github/workflows/tests.yml | 14 ++++++- 3 files changed, 45 insertions(+), 30 deletions(-) diff --git a/.github/workflows/deloyment_on_webhook.yml b/.github/workflows/deloyment_on_webhook.yml index 39bcbf010..c85e212ce 100644 --- a/.github/workflows/deloyment_on_webhook.yml +++ b/.github/workflows/deloyment_on_webhook.yml @@ -1,12 +1,6 @@ name: Deploy on Webhook on: - push: - branches: - - main - pull_request: - branches: - - main workflow_run: workflows: - "Python Lint" @@ -16,32 +10,34 @@ on: jobs: deploy: - if: >- - github.event.workflow_run.conclusion == 'success' && - (github.event.workflow_run.name == 'Python Lint' || github.event.workflow_run.name == 'Run tests') - runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v4 + - name: Download lint result + uses: actions/download-artifact@v2 + with: + name: lint-result + path: . + + - name: Download test result + uses: actions/download-artifact@v2 + with: + name: test-result + path: . + + - name: Check lint and test results + run: | + if [[ -f lint_result.txt && -f test_result.txt ]]; then + echo "Both lint and test succeeded." + else + echo "Skipping deployment as either lint or test did not pass." + exit 1 + fi - name: Trigger Deployment Webhook + if: success() env: WEBHOOK_DOMAIN: ${{ secrets.WEBHOOK_DOMAIN }} WEBHOOK_TOKEN: ${{ secrets.WEBHOOK_TOKEN }} run: | - # Check if both lint and test workflows succeeded - if [[ "${{ github.event.workflow_run.name }}" == "Python Lint" && "${{ github.event.workflow_run.conclusion }}" == "success" ]]; then - echo "Python Lint completed successfully." - echo "lint_success=1" >> $GITHUB_ENV - fi - if [[ "${{ github.event.workflow_run.name }}" == "Run tests" && "${{ github.event.workflow_run.conclusion }}" == "success" ]]; then - echo "Run tests completed successfully." - echo "test_success=1" >> $GITHUB_ENV - fi - - - name: Deploy if both succeeded - if: env.lint_success == '1' && env.test_success == '1' - run: | - curl -X POST https://${{ secrets.WEBHOOK_DOMAIN }}/webhook/deploy -H "Authorization: Bearer ${{ secrets.WEBHOOK_TOKEN }}" \ No newline at end of file + curl -X POST https://${{ secrets.WEBHOOK_DOMAIN }}/webhook/deploy -H "Authorization: Bearer ${{ secrets.WEBHOOK_TOKEN }}" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 1f95ab2a9..de7a54edf 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -3,8 +3,7 @@ name: Python Lint on: [push, pull_request] jobs: - build: - + lint: runs-on: ubuntu-latest steps: @@ -23,3 +22,13 @@ jobs: - name: Lint with flake8 run: | flake8 app + + - name: Upload lint result + if: success() + run: echo "lint_success=1" > lint_result.txt + continue-on-error: true + + - uses: actions/upload-artifact@v2 + with: + name: lint-result + path: lint_result.txt diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8f804ac10..862567bfb 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,9 +2,9 @@ name: Run tests on: push: - branches: [ main, develop ] + branches: [main, develop] pull_request: - branches: [ main, develop ] + branches: [main, develop] jobs: pytest: @@ -48,3 +48,13 @@ jobs: MARIADB_PASSWORD: uvlhub_password run: | pytest app/blueprints/ --ignore-glob='*selenium*' + + - name: Upload test result + if: success() + run: echo "test_success=1" > test_result.txt + continue-on-error: true + + - uses: actions/upload-artifact@v2 + with: + name: test-result + path: test_result.txt