Skip to content

Commit 68d3f32

Browse files
authored
Merge pull request #459 from Hritik14/actions
Improve actions time
2 parents fff7c7a + 7dec893 commit 68d3f32

1 file changed

Lines changed: 30 additions & 22 deletions

File tree

.github/workflows/main.yml

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,6 @@ jobs:
66
unit_tests:
77
runs-on: ubuntu-latest
88

9-
services:
10-
# Label used to access the service container
11-
postgres:
12-
image: postgres
13-
env:
14-
POSTGRES_PASSWORD: vulnerablecode
15-
POSTGRES_DB: vulnerablecode
16-
# Set health checks to wait until postgres has started
17-
options: >-
18-
--health-cmd pg_isready
19-
--health-interval 10s
20-
--health-timeout 5s
21-
--health-retries 5
22-
ports:
23-
# Maps tcp port 5432 on service container to the host
24-
- 5432:5432
259
steps:
2610
- name: Check out repository code
2711
uses: actions/checkout@v2
@@ -31,18 +15,42 @@ jobs:
3115
with:
3216
python-version: 3.8
3317

18+
- name: Restore cache
19+
uses: actions/cache@v2
20+
with:
21+
path: .venv
22+
key: ${{ runner.os }}-venv-${{ hashFiles('**/requirements.txt') }}
23+
restore-keys: |
24+
${{ runner.os }}-venv-
25+
3426
- name: Install dependencies
3527
run: |
36-
sudo apt install python3-dev postgresql libpq-dev build-essential libxml2-dev libxslt1-dev
28+
sudo apt install python3-dev postgresql libpq-dev build-essential libxml2-dev libxslt1-dev postgresql ncat
3729
python -m pip install --upgrade pip
38-
pip install -r requirements.txt
30+
31+
- uses: syphar/restore-virtualenv@v1
32+
id: cache-virtualenv
33+
with:
34+
requirement_files: requirements.txt # this is optional
35+
36+
- uses: syphar/restore-pip-download-cache@v1
37+
if: steps.cache-virtualenv.outputs.cache-hit != 'true'
38+
39+
- run: pip install -r requirements.txt
40+
if: steps.cache-virtualenv.outputs.cache-hit != 'true'
3941

42+
- name: Setup database
43+
env:
44+
PGPASSWORD: vulnerablecode
45+
run: |
46+
sudo systemctl start postgresql
47+
sudo -Eu postgres psql -c "CREATE ROLE vulnerablecode WITH PASSWORD '$PGPASSWORD' NOSUPERUSER CREATEDB NOCREATEROLE INHERIT LOGIN;"
48+
sudo systemctl status postgresql
49+
createdb --encoding=utf-8 --owner=vulnerablecode --user=vulnerablecode \
50+
--host=localhost --port=5432 vulnerablecode
51+
4052
- name: Run tests
4153
run: python -m pytest -v -m "not webtest"
4254
env:
43-
# The hostname, username used to communicate with the PostgreSQL service container
44-
POSTGRES_HOST: localhost
45-
VC_DB_USER: postgres
46-
POSTGRES_PORT: 5432
4755
DJANGO_DEV: 1
4856
GH_TOKEN: 1

0 commit comments

Comments
 (0)