From 1e495bfe234be713134b80e7470b4de7b1c1a124 Mon Sep 17 00:00:00 2001 From: Anmol Date: Sun, 30 Oct 2022 17:54:45 +0530 Subject: [PATCH] GH actions tests and action update (#1) * Change double quotes to single quotes, and use feature branch for testing UI to avoid too many commits in main * Fix installation of yq * Cat yaml file after creating from values * Add sudo for downloading yq * Use variables instead of env variables * Set strings for input values * Create kind cluster if kubeconfig is empty * Github path to scripts * Add debugging section in port forwarding * Add more test cases * Update testing for action * Add a temp kubeconfig file before kind setup * Fix port forward script, create temp kubeconfig file in pre step * Fix test yaml * Fix setting kubeconfig for kind cluster creation * Add extra log line for testing * Remove test branch from even branches * Reduce resources for each chain * Add deletion of helm chart after testing * Add name as input for users to provide release name, used to create seperate releases * Add name to tests action --- .github/workflows/test.yaml | 137 +++++++++++++++++++++++++++++++++--- action.yaml | 30 ++++---- port_forward.sh | 7 +- 3 files changed, 152 insertions(+), 22 deletions(-) mode change 100644 => 100755 port_forward.sh diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 00b24b5..9188c7d 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -12,10 +12,13 @@ jobs: test-with-values: runs-on: ubuntu-latest steps: + - uses: actions/checkout@v2 + - uses: ./ with: port-forward: true + name: test-with-values values: | chains: - name: osmosis-1 @@ -26,11 +29,11 @@ jobs: rpc: 26653 resources: limits: - cpu: "0.5" - memory: "1G" - requests: cpu: "0.2" - memory: "500M" + memory: "200M" + requests: + cpu: "0.1" + memory: "100M" - name: wasmd type: wasmd numValidators: 1 @@ -39,9 +42,127 @@ jobs: rest: 1319 resources: limits: - cpu: "0.5" - memory: "1G" + cpu: "0.2" + memory: "200M" + requests: + cpu: "0.1" + memory: "100M" + + - name: Check kubectl pods + run: | + for chain in wasmd osmosis-1; do + kubectl get pods $chain-genesis-0 + done + shell: bash + + - name: Check port forwarded status + run: | + for port in 26659 26653; do + status_code=$(curl --write-out %{http_code} --silent --output /dev/null http://localhost:$port/status) + if [[ "$status_code" -ne 200 ]]; then + echo "Expected status code: 200, got: $status_code, from http://localhost:$port/status" + exit 1 + else + echo "Successfully connected to: http://localhost:$port/status" + fi + done + shell: bash + + - name: Delete helm chart + run: | + helm delete test-with-values --debug + shell: bash + + test-with-remote-cluster: + runs-on: ubuntu-latest + steps: + + - uses: actions/checkout@v2 + + - run: echo -e "$TEMP_KUBECONFIG" > /tmp/kubeconfig + shell: bash + env: + TEMP_KUBECONFIG: | + apiVersion: v1 + kind: Config + preferences: {} + + - name: Setup kind cluster + if: ${{ inputs.kubeconfig == '' }} + uses: helm/kind-action@v1.4.0 + with: + cluster_name: kind-shuttle + env: + KUBECONFIG: /tmp/kubeconfig + + - name: Read kubeconfig + id: kubeconfig + uses: juliangruber/read-file-action@v1 + with: + path: /tmp/kubeconfig + + - uses: ./ + with: + port-forward: true + name: test-kubeconfig + kubeconfig: ${{ steps.kubeconfig.outputs.content }} + values: | + chains: + - name: osmosis-1 + type: osmosis + numValidators: 1 + ports: + rest: 1313 + rpc: 26653 + resources: + limits: + cpu: "0.2" + memory: "200M" requests: + cpu: "0.1" + memory: "100M" + + - name: Check kubectl pods + run: | + kubectl get pods osmosis-1-genesis-0 + shell: bash + + - name: Delete helm chart + run: | + helm delete test-kubeconfig --debug + shell: bash + + test-with-no-portforward: + runs-on: ubuntu-latest + steps: + + - uses: actions/checkout@v2 + + - uses: ./ + with: + port-forward: false + name: test-no-portforward + values: | + chains: + - name: osmosis-1 + type: osmosis + numValidators: 1 + resources: + limits: cpu: "0.2" - memory: "500M" - - run: kubectl get pods + memory: "200M" + requests: + cpu: "0.1" + memory: "100M" + + - name: Check kubectl pods + run: | + for chain in osmosis-1; do + kubectl get pods $chain-genesis-0 + done + shell: bash + + - name: Delete helm chart + run: | + helm delete test-no-portforward --debug + shell: bash diff --git a/action.yaml b/action.yaml index 6a9c1b2..e970f34 100644 --- a/action.yaml +++ b/action.yaml @@ -23,6 +23,10 @@ inputs: description: "Helm repo to fetch the chart from (default: https://anmol1696.github.io/shuttle)" required: false default: "https://anmol1696.github.io/shuttle" + name: + description: "Helm chart release name for installing helm chart (default: shuttle-devnet)" + required: false + default: "shuttle-devnet" runs: using: composite steps: @@ -30,7 +34,8 @@ runs: - name: Install dependencies run: | sudo apt-get install -y make sed wget tar - wget https://github.com/mikefarah/yq/releases/download/${VERSION}/${BINARY}.tar.gz -O - | tar xz && mv ${BINARY} /usr/bin/yq + sudo wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq + sudo chmod +x /usr/bin/yq shell: bash - name: Setup helm @@ -42,44 +47,45 @@ runs: uses: azure/setup-kubectl@v3 - name: Setup kind cluster + if: ${{ inputs.kubeconfig == '' }} uses: helm/kind-action@v1.4.0 - if: ${{ env.INPUT_KUBECONFIG != "" }} with: cluster_name: kind-shuttle - name: Create kubeconfig file - if: ${{ inputs.kubeconfig != "" }} + if: ${{ inputs.kubeconfig != '' }} run: | mkdir -p ~/.kube - echo -e "$INPUT_KUBECONFIG" > ~/.kube/config + echo -e "${{ inputs.kubeconfig }}" > ~/.kube/config shell: bash - name: Create values.yaml run: | - if [[ $INPUT_VALUES == *.yaml || $INPUT_VALUES == *.yml ]] + if [[ "${{ inputs.values }}" == *.yaml || "${{ inputs.values }}" == *.yml ]] then - cp $INPUT_VALUES custom-values.yaml + cp ${{ inputs.values }} ${{ inputs.name }}-values.yaml else - echo -e "$INPUT_VALUES" > custom-values.yaml + echo -e "${{ inputs.values }}" > ${{ inputs.name }}-values.yaml fi + cat ${{ inputs.name }}-values.yaml shell: bash - name: Setup shuttle helm repo run: | helm version - helm repo add shuttle $INPUT_REPO + helm repo add shuttle ${{ inputs.repo }} helm repo update helm search repo shuttle/devnet shell: bash - name: Helm install run: | - helm install -f custom-values.yaml shuttle-devnet shuttle/devnet --wait --debug --version $INPUT_VERSION + helm install -f ${{ inputs.name }}-values.yaml ${{ inputs.name }} shuttle/devnet --wait --debug --version ${{ inputs.version }} shell: bash - name: Port forward - if: ${{ inputs.port-forward == "true" }} - run: port_forward.sh + if: ${{ inputs.port-forward == 'true' }} + run: ${{ github.action_path }}/port_forward.sh shell: bash env: - VALUES_FILE: custom-values.yaml + VALUES_FILE: ${{ inputs.name }}-values.yaml diff --git a/port_forward.sh b/port_forward.sh old mode 100644 new mode 100755 index d56a77c..ef89d4b --- a/port_forward.sh +++ b/port_forward.sh @@ -9,18 +9,21 @@ echo "num_chains: $num_chains" echo "Port forwarding all chains genesis to localhost" for i in $(seq 0 $(( $num_chains - 1 ))); do - chain=$(yq -r ".chains[$i].namea" $VALUES_FILE) + chain=$(yq -r ".chains[$i].name" $VALUES_FILE) if [[ -z "$chain" || "$chain" == "null" ]]; then + echo "Chain not found for index: $i" continue fi - port_rpc=$(yq -r ".chains[$i].ports.rpce" $VALUES_FILE) + port_rpc=$(yq -r ".chains[$i].ports.rpc" $VALUES_FILE) echo "chain: $chain, port_rpc: $port_rpc" if [[ ! -z "$port_rpc" && "$port_rpc" != "null" ]]; then kubectl port-forward pods/$chain-genesis-0 $port_rpc:26657 & + echo "Port forwarded for pods/$chain-genesis-0 to $port_rpc:26657" fi port_rest=$(yq -r ".chains[$i].ports.rest" $VALUES_FILE) if [[ ! -z "$port_rest" && "$port_rest" != "null" ]]; then kubectl port-forward pods/$chain-genesis-0 $port_rest:1317 & + echo "Port forwarded for pods/$chain-genesis-0 to $port_rest:1317" fi echo "chain: $chain, port_rpc: $port_rpc, port_rest: $port_rest" done