-
Notifications
You must be signed in to change notification settings - Fork 7
119 lines (112 loc) · 3.96 KB
/
ci.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
118
119
name: Build & Deploy Staging
env:
CI: true
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
services:
postgres:
image: postgres:9.6
env:
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Notify Push
uses: appleboy/[email protected]
with:
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
format: markdown
message: Building [this commit](https://github.com/${{github.repository}}/commit/${{github.sha}}) by [${{github.actor}}](https://github.com/${{github.actor}}).
- uses: actions/checkout@v2
- name: Setup Node
if: success()
uses: actions/setup-node@v2
with:
node-version: '14.x'
- name: Install Dependencies
if: success()
run: npm install
- name: Lint
if: success()
run: npm run lint
- name: Test & Coverage
if: success()
env:
POSTGRES_HOST: localhost
POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }}
run: npm run test -- --collect-coverage
- name: Archive code coverage results
uses: actions/upload-artifact@v1
with:
name: code-coverage-report
path: coverage/
- name: Codecov
uses: codecov/[email protected]
continue-on-error: true
timeout-minutes: 3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: coverage/coverage-final.json
fail_ci_if_error: false
- name: Publish to Docker Hub
uses: elgohr/Publish-Docker-Github-Action@master
if: ${{ github.ref == 'refs/heads/master' }}
with:
name: msociety/msocietybot
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
tags: latest
tag_names: true
tag_semver: true
- name: Notify Completed
uses: appleboy/[email protected]
if: success() || failure()
with:
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
format: markdown
message: Building completed with status ${{job.status}} for [this commit](https://github.com/${{github.repository}}/commit/${{github.sha}}) by [${{github.actor}}](https://github.com/${{github.actor}}).
deploy-staging:
needs: build
if: ${{ github.ref == 'refs/heads/master' }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: Notify Push
uses: appleboy/[email protected]
with:
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
format: markdown
message: Deploying to staging [this commit](https://github.com/${{github.repository}}/commit/${{github.sha}}) by [${{github.actor}}](https://github.com/${{github.actor}}).
- name: Deploy Staging
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USERNAME }}
key: ${{ secrets.DEPLOY_KEY }}
script: |
podman stop msocietybot-staging-new || true
podman rm msocietybot-staging-new || true
podman pull msociety/msocietybot
podman run -d --name msocietybot-staging-new --env-file $HOME/staging.env --pod msocietybot-pod msociety/msocietybot
yes | podman system prune
- name: Notify Completed
uses: appleboy/[email protected]
if: success() || failure()
with:
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
format: markdown
message: Deploying to staging completed with status ${{job.status}} for [this commit](https://github.com/${{github.repository}}/commit/${{github.sha}}) by [${{github.actor}}](https://github.com/${{github.actor}}).