Skip to content

Commit

Permalink
feat: Improve CI / CD
Browse files Browse the repository at this point in the history
  • Loading branch information
drorganvidez committed Jun 23, 2024
1 parent 03e72cd commit 9d1cd6d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 30 deletions.
48 changes: 22 additions & 26 deletions .github/workflows/deloyment_on_webhook.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
name: Deploy on Webhook

on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_run:
workflows:
- "Python Lint"
Expand All @@ -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 }}"
curl -X POST https://${{ secrets.WEBHOOK_DOMAIN }}/webhook/deploy -H "Authorization: Bearer ${{ secrets.WEBHOOK_TOKEN }}"
13 changes: 11 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ name: Python Lint
on: [push, pull_request]

jobs:
build:

lint:
runs-on: ubuntu-latest

steps:
Expand All @@ -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
14 changes: 12 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

0 comments on commit 9d1cd6d

Please sign in to comment.