forked from ansible/event-driven-ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
continuous_integration.yml
73 lines (73 loc) · 2.22 KB
/
continuous_integration.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
---
- hosts: localhost
gather_facts: False
tasks:
- name: checkout code
git:
repo: "{{event.repo}}"
dest: /tmp/deploy
version: "{{event.ref | split('/') | last}}"
update: true
force: true
- name: install code
pip:
virtualenv: /tmp/deploy/.venv
virtualenv_python: python3.8
chdir: /tmp/deploy
editable: true
name: .
- name: install test code
pip:
virtualenv: /tmp/deploy/.venv
chdir: /tmp/deploy
requirements: requirements_dev.txt
- name: run tests
shell:
cmd: /tmp/deploy/.venv/bin/pytest -v
chdir: /tmp/deploy
register: test_result
ignore_errors: yes
- set_fact:
cacheable: true
output: "{{test_result.stdout}}"
returncode: "{{test_result.rc}}"
- file:
path: /tmp/deploy
state: absent
- name: update commit status
uri:
url: "https://api.github.com/repos/{{event.repository_name}}/statuses/{{event.sha}}"
user: "{{gh_user}}"
password: "{{gh_token}}"
method: POST
headers:
Accept: application/vnd.github.v3+json
force_basic_auth: True
status_code: [200, 201]
body: '{"state": "success", "context": "pytest"}'
when: event.pr is defined and test_result.rc == 0
- name: update commit status
uri:
url: "https://api.github.com/repos/{{event.repository_name}}/statuses/{{event.sha}}"
user: "{{gh_user}}"
password: "{{gh_token}}"
method: POST
headers:
Accept: application/vnd.github.v3+json
force_basic_auth: True
status_code: [200, 201]
body: '{"state": "failure", "context": "pytest"}'
when: event.pr is defined and test_result.rc != 0
- name: merge PR
uri:
url: "https://api.github.com/repos/{{event.repository_name}}/pulls/{{event.pr}}/merge"
user: "{{gh_user}}"
password: "{{gh_token}}"
method: PUT
headers:
Accept: application/vnd.github.v3+json
force_basic_auth: True
status_code: [200, 201]
body: '{"merge_method": "rebase"}'
when: event.pr is defined and test_result.rc == 0
...