-
Notifications
You must be signed in to change notification settings - Fork 13
feat: Implement automated testing with GHA #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
benjoe1126
wants to merge
19
commits into
master
Choose a base branch
from
automated-testing
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
12c9410
closes issue #8
benjoe1126 a9c30a3
changed url2 to url
benjoe1126 00ddd50
modofied so now it reads Get instead of Post
benjoe1126 3bece58
started working on pipelines and modified testutils to correct splitd…
benjoe1126 7d82f56
changed README and added .idea to .gitignore
benjoe1126 3427860
Merge branch 'master' of github.com:l7mp/learning-go into automated-t…
benjoe1126 994e8ee
Created report generation
benjoe1126 05ea39f
fixed bug with report, now the test cases are correctly mapped
benjoe1126 4948ab3
fixed makefile command issues and added back error checking for exerc…
benjoe1126 24fd2d5
minor improvement, now indexes won't overflow, may remove later
benjoe1126 aecab2b
updated go action script to not have code duplication and removed app…
benjoe1126 e945222
removed extra env var as it was not needed
benjoe1126 778b2d1
fixed small typo
benjoe1126 23a0d6d
clarifie kubernetes-tests options in test-labs.yaml
benjoe1126 5fc143f
clarified README
benjoe1126 6347fed
fixed go action main.sh to actually iterate through all tests
benjoe1126 901115a
changed cloud-provider-kind install from go install to downloading bi…
benjoe1126 503fa65
fixed typo service 'mash'
benjoe1126 517ce41
fixed 'mash' typo
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| name: Docker build | ||
| description: "Build the specified docker image and publishes it for the workflow" | ||
| inputs: | ||
| path: | ||
| description: "The path of the dockerfile to be built" | ||
| required: true | ||
| filepath: | ||
| description: "If the dockerfile is in a different directory then the context it needs to be specified here" | ||
| required: false | ||
| tags: | ||
| description: "The tag(s) for building the image" | ||
| required: true | ||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Build the container | ||
| id: img | ||
| shell: bash | ||
| env: | ||
| CONTEXT_PATH: ${{ inputs.path }} | ||
| FILE_PATH: ${{ inputs.filepath }} | ||
| TAGS: ${{ inputs.tags }} | ||
| run: | | ||
| bash $GITHUB_ACTION_PATH/build.sh | ||
| IMAGE_NAME=$(echo "${TAGS}" | cut -d : -f1) | ||
| echo ${IMAGE_NAME} | ||
| echo "name=${IMAGE_NAME}" >> $GITHUB_ENV | ||
|
|
||
| - name: Publish image | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: ${{ env.name }} | ||
| path: ${{ inputs.path }}/images | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| cd "${CONTEXT_PATH}" || exit 1 | ||
| if [[ -z "${FILE_PATH}" ]]; then | ||
| docker build -t "${TAGS}" . | ||
| else | ||
| docker build -f "${FILE_PATH}" -t "${TAGS}" . | ||
| fi | ||
| IMAGE_NAME=$(echo "${TAGS}" | cut -d : -f1) | ||
| mkdir images | ||
| docker image save -o "images/${IMAGE_NAME}" "${TAGS}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| name: Test go | ||
| description: "Tests the go files with the given arguments" | ||
| inputs: | ||
| tests: | ||
| description: "The project(s) that should be tested (kubernetes tests only), if you want to run multiple, provide their name separated with spaces" | ||
| required: true | ||
| default: 'all' | ||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Test go program | ||
levaitamas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| shell: bash | ||
| env: | ||
| PROJECT_PATH: ${{ github.workspace }} | ||
| TESTS: ${{ inputs.tests }} | ||
| run: bash ${{ github.action_path }}/main.sh | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| cd "${PROJECT_PATH}"/99-labs/code || exit 1 | ||
| if [ "${TESTS}" = "all" ]; then | ||
| TESTS=("helloworld" "splitdim" "kvstore") | ||
| fi | ||
|
|
||
| for TEST in ${TESTS[@]}; do | ||
| pushd . > /dev/null | ||
| cd ${TEST} || exit 1 | ||
| go mod download | ||
| go test ./... --tags=kubernetes --count 1 | ||
| ret=$? | ||
| if [[ $ret -ne 0 ]]; then | ||
| exit $ret | ||
| fi | ||
| popd > /dev/null | ||
| done | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| name: "Kind setup" | ||
| description: "Installs and sets up a running kind cluster, including the cloud-provider-kind and istio for service mesh" | ||
| inputs: | ||
| istio: | ||
| description: "A flag weather to start the istio service mesh" | ||
| default: 'false' | ||
| required: false | ||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Install kind and start cluster | ||
| uses: helm/kind-action@v1 | ||
| with: | ||
| cluster_name: test | ||
| kubectl_version: 'v1.30.4' | ||
|
|
||
| - name: Load images to node(s) | ||
| shell: bash | ||
| run: | | ||
| for i in $(docker images --format "{{.Repository}}:{{.Tag}}" | grep ':test'); do | ||
| kind load docker-image -n test ${i} | ||
| done | ||
|
|
||
| - name: Install cloud-provider-kind and start in background | ||
| shell: bash | ||
| env: | ||
| VERSION: 0.6.0 | ||
| run: | | ||
| curl -L https://github.com/kubernetes-sigs/cloud-provider-kind/releases/download/v${VERSION}/cloud-provider-kind_${VERSION}_linux_amd64.tar.gz \ | ||
| | tar -xz | ||
| sudo mv cloud-provider-kind /usr/local/bin/ | ||
| sudo chmod +x /usr/local/bin/cloud-provider-kind | ||
| cloud-provider-kind & | ||
|
|
||
| - name: Start istio service mesh | ||
| if: inputs.istio == 'true' | ||
| shell: bash | ||
| run: | | ||
| curl -L https://istio.io/downloadIstio | sh - | ||
| cd istio* | ||
| kubectl kustomize "github.com/kubernetes-sigs/gateway-api/config/crd?ref=v1.0.0" | kubectl apply -f - | ||
| bin/istioctl install --set profile=minimal -y | ||
| kubectl label namespace default istio-injection=enabled --overwrite | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| name: Load built images | ||
| description: "Loads the previously built images and deletes the artifacts after" | ||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Load images | ||
| shell: bash | ||
| run: | | ||
| for i in $(ls images); do | ||
| docker image load < "images/$i" | ||
| done | ||
| - name: Delete artifacts | ||
| uses: geekyeggo/delete-artifact@v5 | ||
| with: | ||
| useGlob: 'true' | ||
| name: '*' | ||
| failOnError: false | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| name: Minikube cluster setup | ||
| description: "Sets up a minikube cluster, starts the minikube tunnel and loads the necessery images" | ||
| inputs: | ||
| istio: | ||
| description: "Flag if istio should be installed" | ||
| default: 'false' | ||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Start minikube | ||
| uses: medyagh/setup-minikube@latest | ||
| with: | ||
| driver: docker | ||
| container-runtime: containerd | ||
| wait: all | ||
| cache: true | ||
|
|
||
| - name: Start minikube tunnel | ||
| shell: bash | ||
| run: minikube tunnel &> /dev/null & | ||
|
|
||
| - name: Load images | ||
| shell: bash | ||
| run: | | ||
| for i in $(docker images --format "{{.Repository}}:{{.Tag}}" | grep ':test'); do | ||
| minikube image load ${i} | ||
| done | ||
| - name: Start istio service mesh | ||
| if: inputs.istio == 'true' | ||
| shell: bash | ||
| run: | | ||
| curl -L https://istio.io/downloadIstio | sh - | ||
| cd istio* | ||
| kubectl kustomize "github.com/kubernetes-sigs/gateway-api/config/crd?ref=v1.0.0" | kubectl apply -f - | ||
| bin/istioctl install --set profile=minimal -y | ||
| kubectl label namespace default istio-injection=enabled --overwrite |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| name: Test istio | ||
| description: "Tests the istio service mesh" | ||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Test istio service mesh program | ||
| shell: bash | ||
| run: bash ${{ github.action_path }}/main.sh | ||
| env: | ||
| PROJECT_PATH: ${{ github.workspace }} | ||
| ACTION_PATH: ${{ github.action_path }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| cd ${PROJECT_PATH}/99-labs/code/splitdim/deploy || exit 1 | ||
| kubectl apply -f kubernetes-istio.yaml | ||
| bash ${ACTION_PATH}/wait.sh | ||
| export EXTERNAL_IP=$(kubectl get service splitdim-istio -o jsonpath='{.status.loadBalancer.ingress[0].ip}') | ||
| export EXTERNAL_PORT=80 | ||
| cd .. | ||
| go test ./... --tags=httphandler,api,localconstructor,reset,transfer,accounts,clear -v -count 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| SECONDS=0 | ||
| while true; do | ||
| kubectl get svc #for debug | ||
| IP=$(kubectl get service splitdim-istio -o jsonpath='{.status.loadBalancer.ingress[0].ip}') | ||
| if [[ ! -n "$IP" ]]; then | ||
| if (( SECONDS == 15));then | ||
| exit 1 | ||
| fi | ||
| SECONDS=$(( SECONDS + 1 )) | ||
| sleep 1 | ||
| else | ||
| exit 0 | ||
| fi | ||
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| name: Test Homeworks | ||
| on: | ||
| push: | ||
| branches: | ||
| - master | ||
| paths-ignore: | ||
| - 99-labs | ||
| - env | ||
| - internals | ||
| - .gitignore | ||
| workflow_dispatch: | ||
| inputs: | ||
| report: | ||
| type: boolean | ||
| description: If true then the pipeline creates a report json used for final evaluation and doesn't execute regular tests | ||
| default: false | ||
| jobs: | ||
| test-homeworks: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: '1' | ||
| - name: Setup go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: '^1.24.0' | ||
| - name: Test homeworks | ||
| if: ! inputs.report || github.event_name == 'push' | ||
| run: | | ||
| export STUDENT_ID="$(grep -v -e '^$' STUDENT_ID)" # set the student_id used for test generation | ||
| make generate # generate the tests | ||
| make test | ||
| - name: Generate report | ||
| if: inputs.report | ||
| run: | | ||
| export STUDENT_ID="$(grep -v -e '^$' STUDENT_ID)" # set the student_id used for test generation | ||
| make generate | ||
| make report | ||
| - name: Artifact report | ||
| if: inputs.report | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: 'report' | ||
| path: '*-report.json' | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| name: Test | ||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| kube-distro: | ||
| type: choice | ||
| description: "The type of kubernetes distribution to use, i.e minikube, kind" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool! Note: on the long run we will enable just one option to simplify debugging.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem is: we use |
||
| options: | ||
| - minikube | ||
| - kind | ||
| default: kind | ||
| required: false | ||
|
|
||
| istio-ready: | ||
| type: boolean | ||
| description: "Set to true if istio can be tested, leave false otherwise" | ||
| required: false | ||
|
|
||
| kubernetes-tests: | ||
| type: string | ||
| description: "Kubernetes tests to be run. Options: 'helloworld' 'splitdim', 'kvstore', 'all'. if you want to run multiple, provide them separated with spaces (e.g., 'kvstore splitdim'); 'all' means execute all tests" | ||
| default: 'all' | ||
| required: false | ||
|
|
||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| image-root: ['helloworld','kvstore', 'splitdim'] | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: ./.github/templates/docker | ||
| with: | ||
| path: ${{ github.workspace }}/99-labs/code/${{ matrix.image-root }} | ||
| filepath: ${{ github.workspace }}/99-labs/code/${{ matrix.image-root }}/deploy/Dockerfile | ||
| tags: ${{ matrix.image-root }}:test | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| needs: build | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: '1' | ||
| - uses: actions/download-artifact@v4 | ||
| with: | ||
| path: images | ||
| merge-multiple: 'true' | ||
| - name: Load all docker images | ||
| uses: ./.github/templates/load-images | ||
|
|
||
| - name: Setup go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: '^1.23.0' | ||
|
|
||
| - name: Start kind cluster | ||
| if: github.event.inputs.kube-distro == 'kind' | ||
| uses: ./.github/templates/kind-cluster-setup | ||
| with: | ||
| istio: 'true' | ||
|
|
||
| - name: Start minikube cluster | ||
| if: github.event.inputs.kube-distro == 'minikube' | ||
| uses: ./.github/templates/minikube-cluster-setup | ||
| with: | ||
| istio: 'true' | ||
|
|
||
|
|
||
| - name: Test istio | ||
| if: github.event.inputs.istio-ready == true | ||
| uses: ./.github/templates/test-istio | ||
|
|
||
| - name: Test go project | ||
| uses: ./.github/templates/go | ||
| with: | ||
| tests: ${{ github.event.inputs.kubernetes-tests }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,3 +14,5 @@ | |
| *.out | ||
|
|
||
| .vscode/* | ||
|
|
||
| .idea | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to stick to the env var, this line makes more sense to me:
BTW do we need this env var? This should work too:
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ended up removing the ACTION_PATH env var, can't quite remember why it was there to begin with, but it was not used anyway.
The GITHUB_ACTION_PATH has to stay tho, as ${{ github.action_path }} is a github context directive and can't be interpreted by the script executed on the runner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The shell script does not use the env var; using the context directive in this line is fine as the GHA runner reads it.