-
Notifications
You must be signed in to change notification settings - Fork 0
97 lines (94 loc) · 3.8 KB
/
main.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
name: Integration tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:12.3-alpine
ports:
- 5432:5432
env:
POSTGRES_PASSWORD: postgres
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-tests-${{ hashFiles('**/Cargo.lock') }}
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Run Migrations, Much quicker to use docker image with prebuilt binary atm.
run: docker run -e DATABASE_URL=$DATABASE_URL -v ${PWD}/migrations:/migrations --network=host ncrmro/rust:sqlx sqlx migrate run
env:
DATABASE_URL: 'postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres'
- name: Copy test database as we don't have SQLx cli locally (takes forever to build atm)
run: >
psql $DATABASE_URL -c "CREATE DATABASE postgres_test TEMPLATE postgres;"
env:
DATABASE_URL: 'postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres'
- name: Lint
run: cargo clippy -- -D warnings
env:
DATABASE_URL: 'postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres'
- name: Test
run: cargo test
env:
DATABASE_URL: 'postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres'
build:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:12.3-alpine
ports:
- 5432:5432
env:
POSTGRES_PASSWORD: postgres
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
if: github.ref == 'refs/heads/master'
needs: test
env:
HEROKU_APP: planetexpres
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
IMAGE_BASE: registry.heroku.com/planetexpres
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Run Migrations, Much quicker to use docker image with prebuilt binary atm.
run: docker run -e DATABASE_URL=$DATABASE_URL -v ${PWD}/migrations:/migrations --network=host ncrmro/rust:sqlx sqlx migrate run
env:
DATABASE_URL: 'postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres'
- name: Compile binary
run: cargo build --release
env:
DATABASE_URL: 'postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres'
- name: Compile manage binary
run: cargo build --release --bin manage
env:
DATABASE_URL: 'postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres'
- name: Build release image
run: docker build --tag web . && docker tag web $IMAGE_BASE/web
- name: Set up Heroku
run: sudo apt update && sudo apt install curl -y && sudo curl https://cli-assets.heroku.com/install.sh | sh
- name: Sign into heroku container registry
run: heroku container:login
- name: Push release image
run: docker push registry.heroku.com/planetexpres/web
- name: Release new image
run: heroku container:release web
- name: Run migrations
run: heroku run sqlx migrate run