-
Notifications
You must be signed in to change notification settings - Fork 0
118 lines (111 loc) · 3.57 KB
/
book-api.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: Django Book API
on:
push:
branches: [ master ]
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# install python dependencies
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
# format code with autopep8
- name: autopep8
uses: peter-evans/autopep8@v1
with:
args: --recursive --in-place --aggressive --aggressive .
# create a pull request if autopep8 made changes
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
with:
commit-message: autopep8 action fixes
title: Fixes by autopep8 action
body: This is an auto-generated PR with fixes by autopep8.
labels: autopep8, automated pr
reviewers: abu271
branch: autopep8-patches
# lint code with flake8
- name: Lint with flake8
run: cd app && flake8
# upload artifacts
- name: Upload math result for job 1
uses: actions/upload-artifact@v3
with:
name: bookapi-artifact
path: |
app/
Dockerfile
docker-compose.yml
requirements.txt
version.txt
retention-days: 1
test:
name: Unit Tests
runs-on: ubuntu-latest
needs: build
# create docker postgres container for testing
services:
postgres:
image: postgres:12.3-alpine
env:
POSTGRES_DB: github-workflow
POSTGRES_USER: postgres
POSTGRES_PASSWORD: superpassword
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
# download artifacts
- name: Download artifact from Build
uses: actions/download-artifact@v3
with:
name: bookapi-artifact
# install python dependencies
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
# run python tests
- name: Run test
run: cd app && python manage.py test
env:
SYSTEM_ENV: GITHUB_WORKFLOW
push_docker:
name: Push to Docker Hub
runs-on: ubuntu-latest
needs: [test, build]
steps:
# download artifacts
- name: Download artifact from Build
uses: actions/download-artifact@v3
with:
name: bookapi-artifact
# build & upload docker image
- name: Docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract version and set it to TAG env var
run: |
echo "TAG=$(cat version.txt)" >> $GITHUB_ENV
- name: Build Docker image
run: |
docker build -t bookapi_v${{ env.TAG }} .
docker tag bookapi_v${{ env.TAG }} ${{ secrets.DOCKER_USER }}/octo:bookapi_v${{ env.TAG }}
- name: Upload Docker image to Docker Hub
run: docker push ${{ secrets.DOCKER_USER }}/octo:bookapi_v${{ env.TAG }}