Skip to content

Commit

Permalink
GH actions tests and action update (#1)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Anmol1696 authored Oct 30, 2022
1 parent 6a7c213 commit 1e495bf
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 22 deletions.
137 changes: 129 additions & 8 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
30 changes: 18 additions & 12 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@ 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:

- 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
Expand All @@ -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
7 changes: 5 additions & 2 deletions port_forward.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1e495bf

Please sign in to comment.