Skip to content

Tests

Tests #2584

Workflow file for this run

---
# yamllint disable rule:line-length
name: Tests
on: # yamllint disable-line rule:truthy
push:
branches:
- master
- release*
tags:
- "*"
pull_request:
branches:
- master
- release*
workflow_dispatch:
env:
GO_VERSION: "1.18"
KIND_VERSION: "0.15.0"
GO111MODULE: "on"
IMAGE: "quay.io/backube/snapscheduler"
jobs:
lint:
name: Lint
runs-on: ubuntu-20.04
steps:
- name: Checkout source
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
- name: Install prereqs
run: |
echo 'APT::Acquire::Retries "5";' | sudo tee /etc/apt/apt.conf.d/80-retries
sudo apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y python3-pip ruby
sudo gem install bundler
cd ./.ci-scripts
sudo pip3 install -r requirements.txt
bundle install
bundle binstubs --all
echo "$(pwd)/bin" >> ${GITHUB_PATH}
- name: Run linters
run: ./.ci-scripts/pre-commit.sh --require-all
codescan:
name: CodeQL scan
runs-on: ubuntu-20.04
permissions:
security-events: write
steps:
- name: Checkout source
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
- name: Install Go
uses: actions/setup-go@268d8c0ca0432bb2cf416faae41297df9d262d7f
with:
go-version: ${{ env.GO_VERSION }}
- uses: actions/cache@56461b9eb0f8438fd15c7a9968e3c9ebb18ceff1
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Initialize CodeQL
uses: github/codeql-action/init@807578363a7869ca324a79039e6db9c843e0e100
- name: Download modules
run: go mod download
- name: Build operator
run: make build
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@807578363a7869ca324a79039e6db9c843e0e100
build:
name: Build
runs-on: ubuntu-20.04
steps:
- name: Checkout source
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
- name: Install Go
uses: actions/setup-go@268d8c0ca0432bb2cf416faae41297df9d262d7f
with:
go-version: ${{ env.GO_VERSION }}
- name: Build operator container
run: make docker-build IMAGE=${IMAGE}
- name: Export container image
run: docker save -o /tmp/image.tar ${IMAGE}
- name: Save container as artifact
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8
with:
name: container
path: /tmp/image.tar
test:
name: Unit test
runs-on: ubuntu-20.04
steps:
- name: Checkout source
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
- name: Install Go
uses: actions/setup-go@268d8c0ca0432bb2cf416faae41297df9d262d7f
with:
go-version: ${{ env.GO_VERSION }}
- uses: actions/cache@56461b9eb0f8438fd15c7a9968e3c9ebb18ceff1
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Ensure go module files are up-to-date
run: |
go mod tidy
diff=$(git diff --color -- go.mod go.sum)
if [ -n "$diff" ]; then
echo "$diff"
echo "***** go modules are out-of-date *****"
echo "***** run 'go mod tidy' *****"
exit 1
fi
- name: Run unit tests
run: make test
- name: Upload coverage
uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: cover.out
e2e:
name: End-to-end
needs: [build, test]
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
# There must be kindest/node images for these versions
# See: https://hub.docker.com/r/kindest/node/tags?page=1&ordering=name
KUBERNETES_VERSIONS:
- "1.20.15"
- "1.21.14"
- "1.22.13"
- "1.23.10"
- "1.24.4"
- "1.25.1"
env:
KUBECONFIG: /tmp/kubeconfig
KUBERNETES_VERSION: ${{ matrix.KUBERNETES_VERSIONS }}
steps:
# Bash as default shell is needed by the kuttl tests
- name: Set bash as default shell
run: |
echo 'APT::Acquire::Retries "5";' | sudo tee /etc/apt/apt.conf.d/80-retries
sudo apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y bash
sudo ln -s bash /bin/sh.bash
sudo mv /bin/sh.bash /bin/sh
- name: Checkout source
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
- name: Install Helm
run: make helm
- name: Install kubectl
run: |
curl -LO "https://storage.googleapis.com/kubernetes-release/release/v${KUBERNETES_VERSION}/bin/linux/amd64/kubectl"
sudo install ./kubectl /usr/local/bin/
kubectl version --short --client
kubectl version --short --client | grep -q ${KUBERNETES_VERSION}
- name: Install kind
run: |
curl -L -o kind https://github.com/kubernetes-sigs/kind/releases/download/v${KIND_VERSION}/kind-linux-amd64
sudo install ./kind /usr/local/bin && rm kind
kind version
kind version | grep -q ${KIND_VERSION}
- name: Create Kubernetes cluster
run: |
./hack/setup-kind-cluster.sh "${KUBERNETES_VERSION}"
- name: Load container artifact
uses: actions/download-artifact@fb598a63ae348fa914e94cd0ff38f362e927b741
with:
name: container
path: /tmp
- name: Import container image
run: |
docker load -i /tmp/image.tar
docker inspect ${IMAGE}
docker tag ${IMAGE} ${IMAGE}:ci-build
kind load docker-image "${IMAGE}:ci-build"
- name: Start operator
run: |
bin/helm install --create-namespace -n backube-snapscheduler \
--set image.tagOverride=ci-build \
--set metrics.disableAuth=true \
--wait --timeout=300s \
snapscheduler ./helm/snapscheduler
kubectl -n backube-snapscheduler get all
- name: Run e2e tests
run: make test-e2e
# This is a dummy job that can be used to determine success of CI:
# - by Mergify instead of having to list a bunch of other jobs
# - by the push jobs to ensure all pre-reqs pass before ANY containers are
# pushed.
# - by branch protection so it doesn't need to be updated each time the kube
# versions in the matrix change
e2e-success:
name: Successful e2e tests
needs: [build, e2e, lint]
runs-on: ubuntu-latest
steps:
- name: Success
run: echo "Previous steps were successful"
push:
name: Push container to registry
needs: [e2e-success]
if: >
(github.event_name == 'push' || github.event_name == 'workflow_dispatch') &&
(github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v'))
runs-on: ubuntu-latest
steps:
- name: Load container artifact
uses: actions/download-artifact@fb598a63ae348fa914e94cd0ff38f362e927b741
with:
name: container
path: /tmp
- name: Import container image
run: |
docker load -i /tmp/image.tar
docker inspect ${IMAGE}
- name: Login to registry
# If the registry server is specified in the image name, we use that.
# If the server isn't in the image name, default to docker.io
run: |
[[ "${IMAGE}" =~ ^([^/]+)/[^/]+/[^/]+ ]] && REGISTRY="${BASH_REMATCH[1]}" || REGISTRY="docker.io"
echo "Attempting docker login to: ${REGISTRY}"
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin ${REGISTRY}
- name: Push to registry (latest)
if: >
(github.event_name == 'push' || github.event_name == 'workflow_dispatch') &&
github.ref == 'refs/heads/master'
run: |
docker push "${IMAGE}"
- name: Push to registry (version tag)
if: >
(github.event_name == 'push' || github.event_name == 'workflow_dispatch') &&
startsWith(github.ref, 'refs/tags/v')
run: |
[[ "${{ github.ref }}" =~ ^refs/tags/v([0-9]+\..*) ]] || exit 0
TAG="${BASH_REMATCH[1]}"
echo "Pushing to $TAG"
docker tag "${IMAGE}" "${IMAGE}:${TAG}"
docker push "${IMAGE}:${TAG}"