Skip to content

Commit 0db95d1

Browse files
authored
Add post deploy check (#85)
* Add check_deployment script
1 parent 24ff838 commit 0db95d1

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

.github/workflows/ci.yml

+33-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
push_to_registry:
6161
name: Push Docker image to HerokuApp (as production env)
6262
if: ${{ github.ref == 'refs/heads/main' }}
63-
needs: [verify-django, verify-js, verify-python, release]
63+
needs: [release]
6464
runs-on: ubuntu-latest
6565
environment:
6666
name: production
@@ -117,3 +117,35 @@ jobs:
117117
env:
118118
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
119119
run: heroku container:release web -a packet-helper-pr
120+
post_deploy_check_pr:
121+
name: Check status of env (as development env)
122+
if: ${{ github.ref != 'refs/heads/main' }}
123+
needs: [ push_to_registry_pr ]
124+
runs-on: ubuntu-latest
125+
steps:
126+
- name: Checkout repository
127+
uses: actions/checkout@v2
128+
with:
129+
fetch-depth: 0
130+
- name: Verify /api/info
131+
run: |
132+
pip install requests pydantic
133+
export GIT_VERSION_TAG=`git describe --tags --abbrev=0`
134+
export SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`
135+
python check_deployment.py https://packet-helper-pr.herokuapp.com $GIT_VERSION_TAG $SHORT_SHA
136+
post_deploy_check_prod:
137+
name: Check status of env (as production env)
138+
if: ${{ github.ref != 'refs/heads/main' }}
139+
needs: [ push_to_registry ]
140+
runs-on: ubuntu-latest
141+
steps:
142+
- name: Checkout repository
143+
uses: actions/checkout@v2
144+
with:
145+
fetch-depth: 0
146+
- name: Verify /api/info
147+
run: |
148+
pip install requests pydantic
149+
export GIT_VERSION_TAG=`git describe --tags --abbrev=0`
150+
export SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`
151+
python check_deployment.py https://www.packethelper.com $GIT_VERSION_TAG $SHORT_SHA

check_deployment.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from collections import namedtuple
2+
from sys import argv
3+
4+
from pydantic import BaseModel
5+
from requests import get
6+
7+
8+
class VersionResponse(BaseModel):
9+
version: str = "v0.0.0"
10+
revision: str = "0000000"
11+
12+
13+
def make_call(url: str, timeout: int = 9_000) -> VersionResponse:
14+
return VersionResponse.parse_obj(get(f"{url}/api/info", timeout=timeout, verify=False).json())
15+
16+
17+
if __name__ == "__main__":
18+
InputData = namedtuple("InputData", ["url", "version", "revision"])
19+
input_data = InputData(url=argv[1], version=argv[2], revision=argv[3])
20+
21+
version_response = make_call(input_data.url)
22+
23+
assert input_data.version == version_response.version, \
24+
f"Is {input_data.version} should be {version_response.version}"
25+
assert input_data.revision == version_response.revision, \
26+
f"Is {input_data.revision} should be {version_response.revision}"

0 commit comments

Comments
 (0)