github.com/kubeshop/testkube@v1.17.23/docs/docs/articles/github-actions.md (about) 1 # Testkube GitHub Action 2 3 The Testkube GitHub Action installs Testkube and enables running any [Testkube CLI](https://docs.testkube.io/cli/testkube) command in a GitHub workflow. It is available on Github Marketplace <https://github.com/marketplace/actions/testkube-action>. 4 The action provides a flexible way to work with your pipeline and can be used with Testkube Pro, Testkube Pro On-Prem and the open source Testkube platform. 5 6 ## Testkube Pro 7 8 ### How to configure Testkube CLI action for Testkube Pro and Run a Test 9 10 To use this GitHub Action for the [Testkube Pro](https://app.testkube.io/), you need to create an [API token](https://docs.testkube.io/testkube-pro/articles/organization-management/#api-tokens). 11 Then, pass the **organization** and **environment** IDs, along with the **token** and other parameters specific for your use case. 12 13 If a test is already created, you may directly run it using the command `testkube run test test-name -f` . However, if you need to create a test in this workflow, please add a creation command, e.g.: `testkube create test --name test-name --file path_to_file.json`. 14 15 ```yaml 16 steps: 17 - uses: kubeshop/setup-testkube@v1 18 with: 19 organization: tkcorg_0123456789abcdef 20 environment: tkcenv_fedcba9876543210 21 token: tkcapi_0123456789abcdef0123456789abcd 22 23 - run: | 24 testkube run test test-name -f 25 26 ``` 27 It is recommended that sensitive values should never be stored as plaintext in workflow files, but rather as [secrets](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions). Secrets can be configured at the organization, repository, or environment level, and allow you to store sensitive information in GitHub. 28 29 ```yaml 30 steps: 31 - uses: kubeshop/setup-testkube@v1 32 with: 33 organization: ${{ secrets.TkOrganization }} 34 environment: ${{ secrets.TkEnvironment }} 35 token: ${{ secrets.TkToken }} 36 37 - run: | 38 testkube run test test-name -f 39 40 ``` 41 ## Testkube OSS 42 43 ### How to Configure Testkube CLI Actions for Testkube OSS and Run a Test 44 45 To connect to the self-hosted instance, you need to have **kubectl** configured for accessing your Kubernetes cluster, and simply passing optional namespace, if Testkube is not deployed in the default **testkube** namespace. 46 47 If a test is already created, you may run it using the command `testkube run test test-name -f` . However, if you need to create a test in this workflow, please add a creation command, e.g.: `testkube create test --name test-name --file path_to_file.json`. 48 49 ```yaml 50 steps: 51 - uses: kubeshop/setup-testkube@v1 52 with: 53 namespace: custom-testkube 54 55 - run: | 56 testkube run test test-name -f 57 58 ``` 59 60 Steps to connect to your Kubernetes cluster differ for each provider. You should check the docs of your Cloud provider on how to connect to the Kubernetes cluster from GitHub Action, or check examples in this documentation for selected providers. 61 62 ### How to Configure Testkube CLI Actions for Testkube OSS and Run a Test 63 64 This workflow establishes a connection to EKS cluster and creates and runs a test using Testkube CLI. In this example, we also use GitHub secrets not to reveal sensitive data. Please make sure that the following points are satisfied: 65 - The **_AwsAccessKeyId_**, **_AwsSecretAccessKeyId_** secrets should contain your AWS IAM keys with proper permissions to connect to EKS cluster. 66 - The **_AwsRegion_** secret should contain an AWS region where EKS is. 67 - Tke **EksClusterName** secret points to the name of EKS cluster you want to connect. 68 69 ```yaml 70 steps: 71 - name: Checkout 72 uses: actions/checkout@v4 73 74 - uses: aws-actions/configure-aws-credentials@v4 75 with: 76 aws-access-key-id: ${{ secrets.aws-access-key }} 77 aws-secret-access-key: ${{ secrets.aws-secret-access-key }} 78 aws-region: ${{ secrets.aws-region }} 79 80 - run: | 81 aws eks update-kubeconfig --name ${{ secrets.eks-cluster-name }} --region ${{ secrets.aws-region }} 82 83 - uses: kubeshop/setup-testkube@v1 84 - 85 - run: | 86 testkube run test test-name -f 87 ``` 88 89 ### How to Connect to GKE (Google Kubernetes Engine) Cluster and Run a Test 90 91 This example connects to a k8s cluster in Google Cloud, creates and runs a test using Testkube GH Action. Please make sure that the following points are satisfied: 92 - The **_GKE Sevice Account_** should be created prior in Google Cloud and added to GH Secrets along with **_GKE Project_** value; 93 - The **_GKE Cluster Name_** and **_GKE Zone_** can be added as [environmental variables](https://docs.github.com/en/actions/learn-github-actions/variables) in the workflow. 94 95 ```yaml 96 steps: 97 - name: Checkout 98 uses: actions/checkout@v4 99 100 - uses: google-github-actions/setup-gcloud@1bee7de035d65ec5da40a31f8589e240eba8fde5 101 with: 102 service_account_key: ${{ secrets.GKE_SA_KEY }} 103 project_id: ${{ secrets.GKE_PROJECT }} 104 105 - run: |- 106 gcloud --quiet auth configure-docker 107 108 - uses: google-github-actions/get-gke-credentials@db150f2cc60d1716e61922b832eae71d2a45938f 109 with: 110 cluster_name: ${{ env.GKE_CLUSTER_NAME }} 111 location: ${{ env.GKE_ZONE }} 112 credentials: ${{ secrets.GKE_SA_KEY }} 113 114 - uses: kubeshop/setup-testkube@v1 115 - run: | 116 testkube run test test-name -f 117 ``` 118 Please consult the official documentation from GitHub on how to connect to GKE for more information [here](https://docs.github.com/en/actions/deployment/deploying-to-google-kubernetes-engine). 119 120 ### Complete Example of Working GitHub Actions Workflow and Testkube Tests Usage 121 To integrate Testkube Github Actions into your workflow, please take a look at the example that sets up connection to GKE and creates and runs a test: 122 123 ```yaml 124 name: Running Testkube Tests. 125 on: 126 push: 127 branches: 128 - main 129 env: 130 PROJECT_ID: ${{ secrets.GKE_PROJECT }} 131 GKE_CLUSTER: cluster-1 # Add your cluster name here. 132 GKE_ZONE: us-central1-c # Add your cluster zone here. 133 134 jobs: 135 setup-build-publish-deploy: 136 name: Connect to GKE 137 runs-on: ubuntu-latest 138 139 steps: 140 - name: Checkout 141 uses: actions/checkout@v4 142 143 - uses: google-github-actions/setup-gcloud@1bee7de035d65ec5da40a31f8589e240eba8fde5 144 with: 145 service_account_key: ${{ secrets.GKE_SA_KEY }} 146 project_id: ${{ secrets.GKE_PROJECT }} 147 148 - run: |- 149 gcloud --quiet auth configure-docker 150 151 - uses: google-github-actions/get-gke-credentials@db150f2cc60d1716e61922b832eae71d2a45938f 152 with: 153 cluster_name: ${{ env.GKE_CLUSTER }} 154 location: ${{ env.GKE_ZONE }} 155 credentials: ${{ secrets.GKE_SA_KEY }} 156 157 158 - uses: kubeshop/setup-testkube@v1 159 - run: | 160 testkube run test test-name -f 161 ``` 162