-
Notifications
You must be signed in to change notification settings - Fork 0
131 lines (107 loc) · 3.45 KB
/
ci.yaml
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
120
121
122
123
124
125
126
127
128
129
130
131
name: CI
on:
push:
branches: [master]
pull_request:
branches: [master]
defaults:
run:
shell: bash
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Install pre-commit
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade pre-commit
ansible-galaxy collection install --force ansible.posix
ansible-galaxy collection install --force community.postgresql
- name: Run pre-commit
run: |
python -m pre_commit run --all-files --show-diff-on-failure
python:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Install pytest / Ruff
run: |
python -m pip install pytest ruff
- name: Run Python linter
run: |
ruff format --check
ruff check
- name: Run Python tests
run: |
pushd roles/postgres/files
PATH=$PWD:$PATH pytest -v .
popd
ansible:
strategy:
matrix:
db_backup:
# Clean install
- ''
# Restore a database backup
- 'testdata/xsnippet-api_20241003-030004.pgc'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Ansible
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade ansible
ansible-galaxy collection install --force ansible.posix
ansible-galaxy collection install --force community.postgresql
- name: Remove pre-baked PostgreSQL
run:
# Existing pre-baked PostgreSQL installation may conflict with the
# PostgreSQL installed by our playbook. We better remove it for a
# greater good.
sudo apt purge 'postgresql-*'
- name: Create block storage device (volume)
run: |
VOLUME_DEVICE="$(losetup -f)"
VOLUME_IMAGE="${{ runner.temp }}/diskimage"
dd if=/dev/zero of=$VOLUME_IMAGE bs=1M count=1024
sudo losetup $VOLUME_DEVICE $VOLUME_IMAGE
echo "uri=$VOLUME_DEVICE" >> $GITHUB_OUTPUT
id: volume-device
- name: Add server names to /etc/hosts
run: |
echo "127.0.0.1 xsnippet.local" | sudo tee -a /etc/hosts
echo "127.0.0.1 api.xsnippet.local" | sudo tee -a /etc/hosts
- name: Run the playbook
run: |
read -r -d '' extra_vars << 'EOF' || true
{
"volume_device": "${{ steps.volume-device.outputs.uri }}",
"postgres_users": [
{
"database": "{{ xsnippet_api_user }}",
"username": "{{ xsnippet_api_user }}",
"backup_schedule": "*-*-* 3:00:00",
"backup_restore": "${{ matrix.db_backup }}"
}
]
}
EOF
ansible-playbook \
-vvv \
-e "${extra_vars}" \
--inventory inventories/ci \
site.yml
- name: Verify that the database backup has been restored correctly
if: matrix.db_backup != ''
run: |
# Expect at least one full page of results
test "$(curl http://127.0.0.1:8080/v1/snippets | jq length)" == "20"