|
1 | | -name: Python CI (tests + docker) |
2 | | - |
3 | | -on: |
4 | | - push: |
5 | | - branches: [ "master", "lab03" ] |
6 | | - paths: |
7 | | - - "app_python/**" |
8 | | - - ".github/workflows/python-ci.yml" |
9 | | - pull_request: |
10 | | - branches: [ "master" ] |
11 | | - paths: |
12 | | - - "app_python/**" |
13 | | - - ".github/workflows/python-ci.yml" |
14 | | - |
15 | | -concurrency: |
16 | | - group: python-ci-${{ github.ref }} |
17 | | - cancel-in-progress: true |
18 | | - |
19 | | -permissions: |
20 | | - contents: read |
21 | | - |
22 | | -jobs: |
23 | | - test-and-lint: |
24 | | - runs-on: ubuntu-latest |
25 | | - |
26 | | - strategy: |
27 | | - fail-fast: true |
28 | | - matrix: |
29 | | - python-version: ["3.12", "3.13"] |
30 | | - |
31 | | - steps: |
32 | | - - name: Checkout |
33 | | - uses: actions/checkout@v4 |
34 | | - |
35 | | - - name: Set up Python ${{ matrix.python-version }} |
36 | | - uses: actions/setup-python@v5 |
37 | | - with: |
38 | | - python-version: ${{ matrix.python-version }} |
39 | | - cache: "pip" |
40 | | - cache-dependency-path: | |
41 | | - app_python/requirements.txt |
42 | | - app_python/requirements-dev.txt |
43 | | -
|
44 | | - - name: Install dependencies |
45 | | - working-directory: app_python |
46 | | - run: | |
47 | | - python -m pip install --upgrade pip |
48 | | - pip install -r requirements.txt |
49 | | - pip install -r requirements-dev.txt |
50 | | -
|
51 | | - - name: Lint (ruff) |
52 | | - working-directory: app_python |
53 | | - run: | |
54 | | - ruff check . |
55 | | -
|
56 | | - - name: Run tests (pytest) |
57 | | - working-directory: app_python |
58 | | - run: | |
59 | | - pytest -q |
60 | | - |
61 | | - - name: Install Snyk CLI |
62 | | - run: npm install -g snyk |
63 | | - |
64 | | - - name: Snyk scan (dependencies) |
65 | | - continue-on-error: true |
66 | | - env: |
67 | | - SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} |
68 | | - run: | |
69 | | - cd app_python |
70 | | - snyk test --severity-threshold=high --file=requirements.txt |
71 | | -
|
72 | | - docker-build-and-push: |
73 | | - runs-on: ubuntu-latest |
74 | | - needs: test-and-lint |
75 | | - |
76 | | - if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/lab03') |
77 | | - |
78 | | - permissions: |
79 | | - contents: read |
80 | | - |
81 | | - steps: |
82 | | - - name: Checkout |
83 | | - uses: actions/checkout@v4 |
84 | | - |
85 | | - - name: Set version (CalVer) |
86 | | - run: | |
87 | | - echo "VERSION=$(date -u +%Y.%m.%d)" >> $GITHUB_ENV |
88 | | -
|
89 | | - - name: Log in to Docker Hub |
90 | | - uses: docker/login-action@v3 |
91 | | - with: |
92 | | - username: ${{ secrets.DOCKERHUB_USERNAME }} |
93 | | - password: ${{ secrets.DOCKERHUB_TOKEN }} |
94 | | - |
95 | | - - name: Build and push |
96 | | - uses: docker/build-push-action@v6 |
97 | | - with: |
98 | | - context: ./app_python |
99 | | - file: ./app_python/Dockerfile |
100 | | - push: true |
101 | | - tags: | |
102 | | - ${{ secrets.DOCKERHUB_USERNAME }}/devops-info-service:${{ env.VERSION }} |
103 | | - ${{ secrets.DOCKERHUB_USERNAME }}/devops-info-service:latest |
| 1 | +name: Python CI (tests + docker) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ "master", "lab03" ] |
| 6 | + paths: |
| 7 | + - "app_python/**" |
| 8 | + - ".github/workflows/python-ci.yml" |
| 9 | + pull_request: |
| 10 | + branches: [ "master" ] |
| 11 | + paths: |
| 12 | + - "app_python/**" |
| 13 | + - ".github/workflows/python-ci.yml" |
| 14 | + |
| 15 | +concurrency: |
| 16 | + group: python-ci-${{ github.ref }} |
| 17 | + cancel-in-progress: true |
| 18 | + |
| 19 | +permissions: |
| 20 | + contents: read |
| 21 | + |
| 22 | +jobs: |
| 23 | + test-and-lint: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + |
| 26 | + strategy: |
| 27 | + fail-fast: true |
| 28 | + matrix: |
| 29 | + python-version: ["3.12", "3.13"] |
| 30 | + |
| 31 | + steps: |
| 32 | + - name: Checkout |
| 33 | + uses: actions/checkout@v4 |
| 34 | + |
| 35 | + - name: Set up Python ${{ matrix.python-version }} |
| 36 | + uses: actions/setup-python@v5 |
| 37 | + with: |
| 38 | + python-version: ${{ matrix.python-version }} |
| 39 | + cache: "pip" |
| 40 | + cache-dependency-path: | |
| 41 | + app_python/requirements.txt |
| 42 | + app_python/requirements-dev.txt |
| 43 | +
|
| 44 | + - name: Install dependencies |
| 45 | + working-directory: app_python |
| 46 | + run: | |
| 47 | + python -m pip install --upgrade pip |
| 48 | + pip install -r requirements.txt |
| 49 | + pip install -r requirements-dev.txt |
| 50 | +
|
| 51 | + - name: Lint (ruff) |
| 52 | + working-directory: app_python |
| 53 | + run: | |
| 54 | + ruff check . |
| 55 | +
|
| 56 | + - name: Run tests (pytest) |
| 57 | + working-directory: app_python |
| 58 | + run: | |
| 59 | + pytest -q |
| 60 | + |
| 61 | + - name: Install Snyk CLI |
| 62 | + run: npm install -g snyk |
| 63 | + |
| 64 | + - name: Snyk scan (dependencies) |
| 65 | + continue-on-error: true |
| 66 | + env: |
| 67 | + SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} |
| 68 | + run: | |
| 69 | + cd app_python |
| 70 | + snyk test --severity-threshold=high --file=requirements.txt |
| 71 | +
|
| 72 | + docker-build-and-push: |
| 73 | + runs-on: ubuntu-latest |
| 74 | + needs: test-and-lint |
| 75 | + |
| 76 | + if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/lab03') |
| 77 | + |
| 78 | + permissions: |
| 79 | + contents: read |
| 80 | + |
| 81 | + steps: |
| 82 | + - name: Checkout |
| 83 | + uses: actions/checkout@v4 |
| 84 | + |
| 85 | + - name: Set version (CalVer) |
| 86 | + run: | |
| 87 | + echo "VERSION=$(date -u +%Y.%m.%d)" >> $GITHUB_ENV |
| 88 | +
|
| 89 | + - name: Log in to Docker Hub |
| 90 | + uses: docker/login-action@v3 |
| 91 | + with: |
| 92 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 93 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 94 | + |
| 95 | + - name: Build and push |
| 96 | + uses: docker/build-push-action@v6 |
| 97 | + with: |
| 98 | + context: ./app_python |
| 99 | + file: ./app_python/Dockerfile |
| 100 | + push: true |
| 101 | + tags: | |
| 102 | + ${{ secrets.DOCKERHUB_USERNAME }}/devops-info-service:${{ env.VERSION }} |
| 103 | + ${{ secrets.DOCKERHUB_USERNAME }}/devops-info-service:latest |
0 commit comments