|
| 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