-
Notifications
You must be signed in to change notification settings - Fork 2
70 lines (59 loc) · 2.25 KB
/
cicd.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
name: "theko2fi.multipass collection CI/CD"
on:
push:
branches:
- '**'
tags-ignore:
- '**'
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Fetch the repo
uses: actions/checkout@v3
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_API_TOKEN }}
- name: Create digitalocean droplet
id: droplet-creator
run: |
DROPLET_IP=$(doctl compute droplet create --image ubuntu-22-04-x64 --size s-4vcpu-8gb --region nyc1 --user-data-file .github/files/user-data.yml --ssh-keys ${{ secrets.SSH_KEY_ID }} --wait --output json ansible-multipass-droplet | jq -r '.[].networks.v4[] | select(.type == "public") | .ip_address')
echo "DROPLET_IP=${DROPLET_IP}" >> "$GITHUB_ENV"
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install Ansible
run: pip3 install ansible
- name: Install the collection
run: ansible-galaxy collection install ${GITHUB_WORKSPACE}
- name: Install SSH key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_KEY }}
name: id_rsa
known_hosts: unnecessary
if_key_exists: fail
- name: ssh_known_hosts
uses: nick-fields/retry@v2
with:
timeout_minutes: 10
retry_wait_seconds: 30
max_attempts: 3
command: ssh-keyscan -4 -t rsa -p 22 -T 240 ${{ env.DROPLET_IP }} >> ~/.ssh/known_hosts
- name: check cloud-init status
uses: nick-fields/retry@v2
with:
timeout_minutes: 10
retry_wait_seconds: 60
max_attempts: 5
command: ssh ${{ secrets.SSH_USERNAME }}@${{ env.DROPLET_IP }} 'cloud-init status' | grep -q "done"
- name: Run ansible-test
run: |
cd ~/.ansible/collections/ansible_collections/theko2fi/multipass
ansible-test integration --target ssh:${{ secrets.SSH_USERNAME }}@${{ env.DROPLET_IP }},python=3.10 --exclude connection_multipass
- name: Delete droplet
if: ${{ always() }}
run: doctl compute droplet delete ansible-multipass-droplet --force