tests: use github actions instead of circleci for test running

This commit is contained in:
Jose Diaz-Gonzalez
2021-01-09 16:49:18 -05:00
parent 3c5a3fdd7c
commit a7465f9d81
16 changed files with 438 additions and 297 deletions

15
.github/commands/ci-run vendored Executable file
View File

@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -eo pipefail
main() {
declare FILE_NAME="$1"
mkdir -p test-results/bats
pushd tests/unit >/dev/null
bats --report-formatter junit --output ../../test-results/bats "$FILE_NAME.bats"
popd >/dev/null
ls -lah test-results/bats
}
main "$@"

20
.github/commands/ci-setup vendored Executable file
View File

@@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -eo pipefail
echo "=====> resolve dokku.me"
sudo apt -qq -y --no-install-recommends install net-tools
# dokku.me now resolves to 10.0.0.2. add 10.0.0.2/24 to eth0
ifconfig
sudo ip addr add 10.0.0.2/24 broadcast 10.0.0.255 dev eth0
echo "=====> install ci-dependencies"
make ci-dependencies
echo "=====> setup tests"
./tests/ci/setup.sh
echo "=====> dokku cleanup:skip"
echo 'export DOKKU_SKIP_CLEANUP=true' | sudo tee /home/dokku/.dokkurc/dokku_skip_cleanup
echo "=====> dokku report"
dokku report

9
.github/commands/matrix vendored Executable file
View File

@@ -0,0 +1,9 @@
#!/usr/bin/env python
import json
import os
keys = ["index"]
values = [[s.replace(".bats", "") for s in os.listdir("tests/unit/") if s.endswith(".bats")]]
zi = zip(keys, values)
data = json.dumps(dict(zi))
print(data.replace(" ", ""))

157
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,157 @@
name: CI
on:
pull_request:
branches:
- '*'
push:
branches:
- 'master'
jobs:
build:
name: build
runs-on: ubuntu-16.04
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
strategy:
fail-fast: true
steps:
- uses: actions/checkout@v2
- name: build package
run: ./tests/ci/setup.sh build
- name: set matrix for build
id: set-matrix
run: |
json=$(python .github/commands/matrix)
echo $json
echo "::set-output name=matrix::$(echo "$json")"
- name: upload packages
uses: actions/upload-artifact@v2
with:
name: build
path: build
unit-tests:
name: unit.${{ matrix.index }}
needs: build
runs-on: ubuntu-16.04
strategy:
fail-fast: false
matrix: ${{fromJson(needs.build.outputs.matrix)}}
steps:
- uses: actions/checkout@v2
- name: download packages
uses: actions/download-artifact@v1
with:
name: build
- name: ci-setup
run: ./.github/commands/ci-setup
# - name: start ssh session
# uses: luchihoratiu/debug-via-ssh@main
# with:
# NGROK_AUTH_TOKEN: ${{ secrets.NGROK_AUTH_TOKEN }}
# SSH_PASS: ${{ secrets.SSH_PASS }}
- name: run ci
timeout-minutes: 30
run: sudo -E ./.github/commands/ci-run ${{ matrix.index }}
- uses: actions/upload-artifact@v2
with:
name: test-results-${{ matrix.index }}
path: test-results
docker-deploy-tests:
name: docker
needs: build
runs-on: ubuntu-16.04
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v2
- name: download packages
uses: actions/download-artifact@v1
with:
name: build
- name: ci-setup
run: ./.github/commands/ci-setup
- name: test docker deploys
shell: bash
timeout-minutes: 20
run: |
./tests/ci/setup.sh docker
DOKKU_SSH_PORT=3022 sudo -E make -e test-ci-docker
go-tests:
name: go.${{ matrix.index }}
needs: build
runs-on: ubuntu-16.04
strategy:
fail-fast: false
matrix:
index: [0, 1, 2, 3]
env:
GITHUB_NODE_INDEX: ${{ matrix.index }}
steps:
- uses: actions/checkout@v2
- name: download packages
uses: actions/download-artifact@v1
with:
name: build
- name: ci-setup
run: ./.github/commands/ci-setup
- name: run go tests
run: |
export CIRCLE_SHA1=$GITHUB_SHA
echo "CODACY_TOKEN=$CODACY_TOKEN"
if [ "$CODACY_TOKEN" != "" ]; then
echo "Detected value for CODACY_TOKEN"
fi
case $GITHUB_NODE_INDEX in
0) sudo -E make -e lint-ci go-tests ci-go-coverage ;;
1) sudo -E make -e deploy-test-checks-root deploy-test-config ;;
2) sudo -E make -e deploy-test-multi ;;
3) sudo -E make -e deploy-test-go-fail-predeploy deploy-test-go-fail-postdeploy ;;
esac
- uses: actions/upload-artifact@v2
with:
name: coverage.${{ matrix.index }}
path: test-results/coverage
publish-test-results:
name: publish-test-results
needs: unit-tests
runs-on: ubuntu-16.04
# the build-and-test job might be skipped, we don't need to run this job then
if: success() || failure()
steps:
- name: download test-results
uses: actions/download-artifact@v2
with:
path: test-results
- name: Publish Unit Test Results
uses: docker://ghcr.io/enricomi/publish-unit-test-result-action:v1.6
with:
check_name: Unit Test Results
github_token: ${{ secrets.GITHUB_TOKEN }}
files: test-results/**/*.xml
comment_on_pr: false