Skip to content

workflow: added Integration Tests #15

workflow: added Integration Tests

workflow: added Integration Tests #15

Workflow file for this run

# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Integration Tests
on:
push:
branches:
- 'main'
pull_request:
jobs:
collatz:
name: Build collatz binary
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
name: Checkout collatz example
with:
repository: ServiceWeaver/weaver
ref: 'v0.15.0'
- uses: actions/setup-go@v4
with:
go-version: '1.20'
cache: true
- name: Build collatz example
working-directory: ./examples/collatz
run: |
# Disable CGO to ensure the binary is statically linked
CGO_ENABLED=0 \
go build -o collatz
- uses: actions/upload-artifact@v3
with:
name: collatz-binary
path: ./examples/collatz/collatz
deploy:
name: Deploy and run tests
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: collatz
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.20'
cache: true
- uses: azure/setup-kubectl@v3
- uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Install weaver-kube
run: |
go install ./cmd/weaver-kube
- uses: actions/download-artifact@v3
with:
name: collatz-binary
path: ./examples/collatz
- uses: ASzc/change-string-case-action@v5
id: repository
with:
string: ${{ github.repository }}
- name: Generate weaver.toml
uses: DamianReeves/write-file-action@master
with:
path: ./examples/collatz/weaver.toml
write-mode: overwrite
contents: |
[serviceweaver]
binary = "./collatz"
[kube]
image = "ghcr.io/${{ steps.repository.outputs.lowercase }}/example-collatz"
listeners.collatz = {public = true}
- name: Build and generate kube manifests
working-directory: ./examples/collatz
run: |
# Ensure the binary is executable
chmod +x ./collatz
# Build the docker image and push
weaver-kube deploy weaver.toml
- uses: medyagh/setup-minikube@master
id: minikube
- name: Deploy the application
working-directory: ./examples/collatz
run: |
kubectl apply -f ./kube_*.yaml
- name: Wait for deployment to be ready
working-directory: ./examples/collatz
run: |
kubectl wait --for=condition=Available=True --timeout=90s Deployment -l serviceweaver/app_name=collatz
- name: Call the collatz API
run: |
# Get the load balancer name
LOAD_BALANCER_NAME=$(kubectl get service \
-l serviceweaver/app_name=collatz \
-o=go-template \
--template='{{- range .items -}}{{- if eq .spec.type "LoadBalancer" -}}{{ .metadata.name }}{{- end -}}{{- end -}}')
# Call the API and check the response
kubectl run -i --rm --restart=Never --image=busybox:latest test-api \
--command wget -- -q -O - http://$LOAD_BALANCER_NAME/\?x\=10
- name: Display deployment logs
if: failure()
working-directory: ./examples/collatz
run: |
kubectl get all && \
kubectl describe pod -l app_name=collatz && \
kubectl logs -l app_name=collatz
- uses: actions/upload-artifact@v3
if: always()
with:
name: collatz-kube-manifests
path: ./examples/collatz/kube_*.yaml