This repository was archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
152 lines (134 loc) · 7.27 KB
/
test-integration.yml
File metadata and controls
152 lines (134 loc) · 7.27 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
name: Integration Test
on:
pull_request:
types: [opened, labeled, unlabeled, synchronize]
branches:
- master
- next
paths:
- actions/integration-test/**
- .github/workflows/test-integration.yml
jobs:
checkLabel:
name: Please request integration test and review
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
steps:
- run: if [ ${{ contains( github.event.pull_request.labels.*.name, 'action/integration-test') }} == false ]; then exit 1; else exit 0; fi
test-integration:
name: Integration Test
needs: checkLabel
runs-on: ubuntu-latest
strategy:
matrix:
os: [ 'ubuntu-18.04', 'ubuntu-20.04' ] # , 'centos-8'
fail-fast: false
if: github.event.pull_request.draft == false
env:
DOMAIN_PREFIX: pr-${{ github.event.number }}-main-${{ matrix.os }}
DOMAIN: test.stackhead.io
steps:
- uses: actions/checkout@v2
- uses: webfactory/ssh-agent@v0.4.1
with:
ssh-private-key: "${{ secrets.SSH_PRIVATE_KEY }}"
- name: Setup Hetzner server
id: setup_server
uses: saitho/hetzner-cloud-action@v1.1.0
with:
action: create
server_name: "${{ env.DOMAIN_PREFIX }}"
server_image: "${{ matrix.os }}"
server_location: fsn1
server_ssh_key_name: gh-actions
wait_for_ssh: 1
env:
API_TOKEN: ${{ secrets.HETZNER_TOKEN }}
- name: Add DNS record
uses: kriasoft/create-dns-record@master
with:
type: "A"
name: "${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }}"
content: "${{ steps.setup_server.outputs.hcloud_server_created_ipv4 }}"
ttl: 1
proxied: 0
token: "${{ secrets.CLOUDFLARE_TOKEN }}"
zone: "${{ secrets.CLOUDFLARE_ZONE }}"
- name: Add DNS record for subdomain
uses: kriasoft/create-dns-record@master
with:
type: "A"
name: "sub.${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }}"
content: "${{ steps.setup_server.outputs.hcloud_server_created_ipv4 }}"
ttl: 1
proxied: 0
token: "${{ secrets.CLOUDFLARE_TOKEN }}"
zone: "${{ secrets.CLOUDFLARE_ZONE }}"
- name: Perform integration test
uses: ./actions/integration-test
with:
ipaddress: ${{ steps.setup_server.outputs.hcloud_server_created_ipv4 }}
domain: '${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }}'
domain2: 'sub.${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }}'
webserver: getstackhead.stackhead_webserver_nginx
selftest: 1
version: "${{ github.HEAD_REF }}"
- name: Debug GitHub action
uses: mxschmitt/action-tmate@v3
if: always() && contains( github.event.pull_request.labels.*.name, 'action/debug-tmate')
- name: PR comment if integration stage was left intact
uses: mshick/add-pr-comment@v1
if: always() && contains( github.event.pull_request.labels.*.name, 'action/keep-integration-stage')
with:
message: |
Because the `action/keep-integration-stage` label was set, the integration stage is left intact.
You may now continue debugging on it, if you had been granted SSH access.
IP-Address: ${{ steps.setup_server.outputs.hcloud_server_created_ipv4 }}
OS: ${{ matrix.os }}
## Quick command reference
### Build
```bash
INPUT_IPADDRESS=${{ steps.setup_server.outputs.hcloud_server_created_ipv4 }} INPUT_DOMAIN=${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }} INPUT_DOMAIN2=sub.${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }} INPUT_WEBSERVER=getstackhead.stackhead_webserver_nginx INPUT_CONTAINER=getstackhead.stackhead_container_docker INPUT_SELFTEST=1 GITHUB_ACTION_PATH=./actions/integration-test/ STACKHEAD_CLONE_LOCATION=. ./actions/integration-test/steps/build.sh
```
### Setup server
```bash
INPUT_IPADDRESS=${{ steps.setup_server.outputs.hcloud_server_created_ipv4 }} INPUT_DOMAIN=${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }} INPUT_DOMAIN2=sub.${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }} INPUT_WEBSERVER=getstackhead.stackhead_webserver_nginx INPUT_CONTAINER=getstackhead.stackhead_container_docker INPUT_SELFTEST=1 GITHUB_ACTION_PATH=./actions/integration-test/ STACKHEAD_CLONE_LOCATION=. ./actions/integration-test/steps/setup.sh
```
### Deploy application
```bash
INPUT_IPADDRESS=${{ steps.setup_server.outputs.hcloud_server_created_ipv4 }} INPUT_DOMAIN=${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }} INPUT_DOMAIN2=sub.${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }} INPUT_WEBSERVER=getstackhead.stackhead_webserver_nginx INPUT_CONTAINER=getstackhead.stackhead_container_docker INPUT_SELFTEST=1 GITHUB_ACTION_PATH=./actions/integration-test/ STACKHEAD_CLONE_LOCATION=. ./actions/integration-test/steps/deploy.sh
```
### Validate application
```bash
INPUT_IPADDRESS=${{ steps.setup_server.outputs.hcloud_server_created_ipv4 }} INPUT_DOMAIN=${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }} INPUT_DOMAIN2=sub.${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }} INPUT_WEBSERVER=getstackhead.stackhead_webserver_nginx INPUT_CONTAINER=getstackhead.stackhead_container_docker INPUT_SELFTEST=1 GITHUB_ACTION_PATH=./actions/integration-test/ STACKHEAD_CLONE_LOCATION=. ./actions/integration-test/steps/validate.sh
```
### Destroy application
```bash
INPUT_IPADDRESS=${{ steps.setup_server.outputs.hcloud_server_created_ipv4 }} INPUT_DOMAIN=${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }} INPUT_DOMAIN2=sub.${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }} INPUT_WEBSERVER=getstackhead.stackhead_webserver_nginx INPUT_CONTAINER=getstackhead.stackhead_container_docker INPUT_SELFTEST=1 GITHUB_ACTION_PATH=./actions/integration-test/ STACKHEAD_CLONE_LOCATION=. ./actions/integration-test/steps/destroy.sh
```
## Done debugging?
Destroy the stage by deleting the server in the Hetzner control panel and the DNS setting in the Cloudflare control panel.
repo-token: ${{ secrets.GH_TOKEN }}
allow-repeats: false
- name: Remove DNS record
uses: kriasoft/delete-dns-record@master
if: always() && !contains( github.event.pull_request.labels.*.name, 'action/keep-integration-stage')
with:
name: "${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }}"
token: "${{ secrets.CLOUDFLARE_TOKEN }}"
zone: "${{ secrets.CLOUDFLARE_ZONE }}"
- name: Remove DNS record for subdomain
uses: kriasoft/delete-dns-record@master
if: always() && !contains( github.event.pull_request.labels.*.name, 'action/keep-integration-stage')
with:
name: "sub.${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }}"
token: "${{ secrets.CLOUDFLARE_TOKEN }}"
zone: "${{ secrets.CLOUDFLARE_ZONE }}"
- name: Remove Hetzner server
uses: saitho/hetzner-cloud-action@v1.1.0
if: always() && !contains( github.event.pull_request.labels.*.name, 'action/keep-integration-stage')
with:
action: remove
server_id: "${{ steps.setup_server.outputs.hcloud_server_id }}"
env:
API_TOKEN: ${{ secrets.HETZNER_TOKEN }}