Skip to content
This repository was archived by the owner on Sep 18, 2021. It is now read-only.

Commit 0ea6858

Browse files
committed
ci: restore CI configuration
1 parent fe267d9 commit 0ea6858

File tree

7 files changed

+362
-0
lines changed

7 files changed

+362
-0
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
* **Please check if the PR fulfills these requirements**
2+
- [ ] The commit message follows our guidelines
3+
- [ ] Tests for the changes have been added (for bug fixes / features)
4+
- [ ] Docs have been added / updated (for bug fixes / features)
5+
6+
7+
* **What kind of change does this PR introduce?** (Bug fix, feature, docs update, ...)
8+
9+
10+
11+
* **What is the current behavior?** (You can also link to an open issue here)
12+
13+
14+
15+
* **What is the new behavior (if this is a feature change)?**
16+
17+
18+
19+
* **Does this PR introduce a breaking change?** (What changes might users need to make in their application due to this PR?)
20+
21+
22+
23+
* **Other information**:

.github/linters/.isort.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[settings]
2+
3+
; https://pycqa.github.io/isort/#multi-line-output-modes
4+
multi_line_output = 3
5+
6+
; necessary because black expect the trailing comma.
7+
include_trailing_comma = true
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Cancel running jobs on PR update
2+
on: pull_request
3+
4+
jobs:
5+
build:
6+
name: auto-cancellation-running-action
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: fauguste/auto-cancellation-running-action@0.1.2
10+
with:
11+
githubToken: ${{ secrets.GH_TOKEN }}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches: [ master, next ]
6+
pull_request:
7+
# The branches below must be a subset of the branches above
8+
branches: [ master, next ]
9+
schedule:
10+
- cron: '36 23 * * 4'
11+
12+
jobs:
13+
analyze:
14+
name: Analyze
15+
runs-on: ubuntu-latest
16+
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
language: [ 'python' ] #'go',
21+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
22+
# Learn more:
23+
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
24+
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v2
28+
29+
# Initializes the CodeQL tools for scanning.
30+
- name: Initialize CodeQL
31+
uses: github/codeql-action/init@v1
32+
with:
33+
languages: ${{ matrix.language }}
34+
# If you wish to specify custom queries, you can do so here or in a config file.
35+
# By default, queries listed here will override any specified in a config file.
36+
# Prefix the list here with "+" to use these queries and those in the config file.
37+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
38+
39+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
40+
# If this step fails, then you should remove it and run the build manually (see below)
41+
- name: Autobuild
42+
uses: github/codeql-action/autobuild@v1
43+
44+
# ℹ️ Command-line programs to run using the OS shell.
45+
# 📚 https://git.io/JvXDl
46+
47+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
48+
# and modify them (or add more) to build your code if your project
49+
# uses a compiled language
50+
51+
#- run: |
52+
# make bootstrap
53+
# make release
54+
55+
- name: Perform CodeQL Analysis
56+
uses: github/codeql-action/analyze@v1

.github/workflows/linter.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
name: Lint Code Base
3+
4+
on:
5+
push:
6+
branches-ignore:
7+
- master
8+
- next
9+
10+
jobs:
11+
build:
12+
name: Lint Code Base
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout Code
17+
uses: actions/checkout@v2
18+
- name: Lint Code Base
19+
uses: docker://github/super-linter:v3
20+
env:
21+
VALIDATE_ALL_CODEBASE: false
22+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}

.github/workflows/test-cli.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Test CLI
2+
3+
on:
4+
pull_request:
5+
types: [opened, labeled, unlabeled, synchronize]
6+
branches:
7+
- master
8+
- next
9+
10+
jobs:
11+
12+
build:
13+
name: Build
14+
runs-on: ubuntu-latest
15+
steps:
16+
17+
- name: Set up Go 1.13
18+
uses: actions/setup-go@v1
19+
with:
20+
go-version: 1.13
21+
id: go
22+
23+
- name: Check out code into the Go module directory
24+
uses: actions/checkout@v2
25+
26+
- name: Build
27+
run: go build -v -o bin/stackhead-cli
28+
29+
- uses: actions/upload-artifact@v2
30+
with:
31+
name: stackhead-cli
32+
path: bin/stackhead-cli
33+
34+
test-unit:
35+
name: Unit Test
36+
needs: build
37+
runs-on: ubuntu-latest
38+
steps:
39+
- name: Set up Go 1.13
40+
uses: actions/setup-go@v1
41+
with:
42+
go-version: 1.13
43+
id: go
44+
45+
- name: Check out code into the Go module directory
46+
uses: actions/checkout@v2
47+
48+
- name: Test
49+
run: go test ./...
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
name: Integration Test
2+
3+
on:
4+
pull_request:
5+
types: [opened, labeled, unlabeled, synchronize]
6+
branches:
7+
- master
8+
- next
9+
10+
jobs:
11+
12+
build:
13+
name: Build
14+
runs-on: ubuntu-latest
15+
steps:
16+
17+
- name: Set up Go 1.13
18+
uses: actions/setup-go@v1
19+
with:
20+
go-version: 1.13
21+
id: go
22+
23+
- name: Check out code into the Go module directory
24+
uses: actions/checkout@v2
25+
26+
- name: Build
27+
run: go build -v -o bin/stackhead-cli
28+
29+
- uses: actions/upload-artifact@v2
30+
with:
31+
name: stackhead-cli
32+
path: bin/stackhead-cli
33+
34+
checkLabel:
35+
needs: build
36+
name: Please request integration test and review
37+
runs-on: ubuntu-latest
38+
if: github.event.pull_request.draft == false
39+
steps:
40+
- run: if [ ${{ contains( github.event.pull_request.labels.*.name, 'action/integration-test') }} == false ]; then exit 1; else exit 0; fi
41+
42+
test-integration:
43+
name: Integration Test
44+
needs: checkLabel
45+
runs-on: ubuntu-latest
46+
strategy:
47+
matrix:
48+
os: [ 'ubuntu-18.04', 'ubuntu-20.04', 'centos-8' ]
49+
fail-fast: false
50+
if: github.event.pull_request.draft == false
51+
env:
52+
DOMAIN_PREFIX: pr-${{ github.event.number }}-cli-${{ matrix.os }}
53+
DOMAIN: test.stackhead.io
54+
steps:
55+
- uses: actions/checkout@v2
56+
- name: Remove Python 2 and old Ansible 2.9 version
57+
run: sudo apt purge python ansible -y
58+
- name: Set up Python 3
59+
uses: actions/setup-python@v2
60+
with:
61+
python-version: '3.x'
62+
- name: Install Ansible v2.10.3 (GH actions currently uses 2.9)
63+
run: pip install ansible==2.10.3
64+
- name: Print Ansible and Python version
65+
run: ansible --version && python --version
66+
- uses: webfactory/ssh-agent@v0.4.1
67+
with:
68+
ssh-private-key: "${{ secrets.SSH_PRIVATE_KEY }}"
69+
- name: Setup Hetzner server
70+
id: setup_server
71+
uses: saitho/hetzner-cloud-action@v1.1.0
72+
with:
73+
action: create
74+
server_name: "${{ env.DOMAIN_PREFIX }}"
75+
server_image: ubuntu-18.04
76+
server_location: fsn1
77+
server_ssh_key_name: gh-actions
78+
wait_for_ssh: 1
79+
env:
80+
API_TOKEN: ${{ secrets.HETZNER_TOKEN }}
81+
- name: Add DNS record
82+
uses: saitho/create-dns-record@patch-1
83+
with:
84+
type: "A"
85+
name: "${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }}"
86+
content: "${{ steps.setup_server.outputs.hcloud_server_created_ipv4 }}"
87+
ttl: 1
88+
proxied: 0
89+
token: "${{ secrets.CLOUDFLARE_TOKEN }}"
90+
zone: "${{ secrets.CLOUDFLARE_ZONE }}"
91+
- name: Add DNS record for subdomain
92+
uses: saitho/create-dns-record@patch-1
93+
with:
94+
type: "A"
95+
name: "sub.${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }}"
96+
content: "${{ steps.setup_server.outputs.hcloud_server_created_ipv4 }}"
97+
ttl: 1
98+
proxied: 0
99+
token: "${{ secrets.CLOUDFLARE_TOKEN }}"
100+
zone: "${{ secrets.CLOUDFLARE_ZONE }}"
101+
- name: Download StackHead CLI artifact
102+
uses: actions/download-artifact@v2
103+
with:
104+
name: stackhead-cli
105+
path: /home/runner/bin
106+
- name: Set execution permission on binary
107+
run: chmod +x /home/runner/bin/stackhead-cli
108+
working-directory: /home/runner/bin
109+
- name: Perform validation tests
110+
run: |
111+
/home/runner/bin/stackhead-cli cli validate ./schemas/examples/cli-config/valid/cli.yml
112+
/home/runner/bin/stackhead-cli module validate ./schemas/examples/module-config/valid/container-module.yml
113+
/home/runner/bin/stackhead-cli project validate ./schemas/examples/project-definition/valid/docker_project.yml
114+
- name: Perform integration test
115+
uses: ./actions/integration-test
116+
with:
117+
ipaddress: ${{ steps.setup_server.outputs.hcloud_server_created_ipv4 }}
118+
domain: '${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }}'
119+
domain2: 'sub.${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }}'
120+
webserver: nginx # when using cli "getstackhead.stackhead_webserver_" prefix is added automatically
121+
selftest: 1
122+
cli: 1
123+
cli_bin_path: /home/runner/bin/stackhead-cli
124+
version: "${{ github.HEAD_REF }}"
125+
- name: PR comment if integration stage was left intact
126+
uses: mshick/add-pr-comment@v1
127+
if: always() && contains( github.event.pull_request.labels.*.name, 'action/keep-integration-stage')
128+
with:
129+
message: |
130+
Because the `action/keep-integration-stage` label was set, the integration stage is left intact.
131+
You may now continue debugging on it, if you had been granted SSH access.
132+
133+
IP-Address: ${{ steps.setup_server.outputs.hcloud_server_created_ipv4 }}
134+
OS: ${{ matrix.os }}
135+
136+
## Quick command reference
137+
138+
### Build
139+
140+
```bash
141+
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
142+
```
143+
144+
### Setup server
145+
146+
```bash
147+
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
148+
```
149+
150+
### Deploy application
151+
152+
```bash
153+
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
154+
```
155+
156+
### Validate application
157+
158+
```bash
159+
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
160+
```
161+
162+
### Destroy application
163+
164+
```bash
165+
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
166+
```
167+
168+
## Done debugging?
169+
170+
Destroy the stage by deleting the server in the Hetzner control panel and the DNS setting in the Cloudflare control panel.
171+
repo-token: ${{ secrets.GH_TOKEN }}
172+
allow-repeats: false
173+
- name: Remove DNS record
174+
uses: saitho/delete-dns-record@saitho-patch-1
175+
if: always() && !contains( github.event.pull_request.labels.*.name, 'action/keep-integration-stage')
176+
with:
177+
name: "${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }}"
178+
token: "${{ secrets.CLOUDFLARE_TOKEN }}"
179+
zone: "${{ secrets.CLOUDFLARE_ZONE }}"
180+
- name: Remove DNS record for subdomain
181+
uses: saitho/delete-dns-record@saitho-patch-1
182+
if: always() && !contains( github.event.pull_request.labels.*.name, 'action/keep-integration-stage')
183+
with:
184+
name: "sub.${{ env.DOMAIN_PREFIX }}.${{ env.DOMAIN }}"
185+
token: "${{ secrets.CLOUDFLARE_TOKEN }}"
186+
zone: "${{ secrets.CLOUDFLARE_ZONE }}"
187+
- name: Remove Hetzner server
188+
uses: saitho/hetzner-cloud-action@v1.1.0
189+
if: always() && !contains( github.event.pull_request.labels.*.name, 'action/keep-integration-stage')
190+
with:
191+
action: remove
192+
server_id: "${{ steps.setup_server.outputs.hcloud_server_id }}"
193+
env:
194+
API_TOKEN: ${{ secrets.HETZNER_TOKEN }}

0 commit comments

Comments
 (0)