|
| 1 | +name: Continuous Integration |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + branches: [main] |
| 8 | + |
| 9 | +jobs: |
| 10 | + lint: |
| 11 | + name: Lint |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - name: Install shellcheck |
| 18 | + run: sudo apt-get update && sudo apt-get install -y shellcheck |
| 19 | + |
| 20 | + - name: Run shellcheck |
| 21 | + run: shellcheck kubectl-beam |
| 22 | + |
| 23 | + - name: Verify POSIX compliance |
| 24 | + run: shellcheck -s sh kubectl-beam |
| 25 | + |
| 26 | + unit-test: |
| 27 | + name: Unit Tests |
| 28 | + runs-on: ubuntu-latest |
| 29 | + |
| 30 | + steps: |
| 31 | + - uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Install bats |
| 34 | + run: | |
| 35 | + git clone --depth 1 https://github.com/bats-core/bats-core.git /tmp/bats |
| 36 | + sudo /tmp/bats/install.sh /usr/local |
| 37 | +
|
| 38 | + - name: Run unit tests |
| 39 | + run: bats test/kubectl-beam.bats |
| 40 | + |
| 41 | + integration-test: |
| 42 | + name: Integration Tests |
| 43 | + runs-on: ubuntu-latest |
| 44 | + needs: [lint, unit-test] |
| 45 | + |
| 46 | + steps: |
| 47 | + - uses: actions/checkout@v4 |
| 48 | + |
| 49 | + - name: Read versions from .tool-versions |
| 50 | + id: versions |
| 51 | + run: | |
| 52 | + OTP_VERSION=$(grep erlang .tool-versions | awk '{print $2}') |
| 53 | + ELIXIR_VERSION=$(grep elixir .tool-versions | awk '{print $2}' | cut -d'-' -f1) |
| 54 | + echo "otp=$OTP_VERSION" >> $GITHUB_OUTPUT |
| 55 | + echo "elixir=$ELIXIR_VERSION" >> $GITHUB_OUTPUT |
| 56 | + echo "OTP Version: $OTP_VERSION" |
| 57 | + echo "Elixir Version: $ELIXIR_VERSION" |
| 58 | +
|
| 59 | + - name: Setup BEAM |
| 60 | + uses: erlef/setup-beam@v1 |
| 61 | + with: |
| 62 | + otp-version: ${{ steps.versions.outputs.otp }} |
| 63 | + elixir-version: ${{ steps.versions.outputs.elixir }} |
| 64 | + |
| 65 | + - name: Verify BEAM installation |
| 66 | + run: | |
| 67 | + erl -version |
| 68 | + elixir --version |
| 69 | +
|
| 70 | + - name: Install bats |
| 71 | + run: | |
| 72 | + git clone --depth 1 https://github.com/bats-core/bats-core.git /tmp/bats |
| 73 | + sudo /tmp/bats/install.sh /usr/local |
| 74 | +
|
| 75 | + - name: Create kind cluster |
| 76 | + uses: helm/kind-action@v1 |
| 77 | + with: |
| 78 | + cluster_name: kubectl-beam-test |
| 79 | + wait: 60s |
| 80 | + |
| 81 | + - name: Verify cluster |
| 82 | + run: | |
| 83 | + kubectl cluster-info |
| 84 | + kubectl get nodes |
| 85 | +
|
| 86 | + - name: Build Erlang app Docker image |
| 87 | + run: | |
| 88 | + cd examples/erlang-app |
| 89 | + docker build \ |
| 90 | + --build-arg OTP_VERSION=${{ steps.versions.outputs.otp }} \ |
| 91 | + --build-arg ALPINE_VERSION=3.20.3 \ |
| 92 | + -t erlang-app:test . |
| 93 | +
|
| 94 | + - name: Build Elixir app Docker image |
| 95 | + run: | |
| 96 | + cd examples/elixir-app |
| 97 | + docker build \ |
| 98 | + --build-arg ELIXIR_VERSION=${{ steps.versions.outputs.elixir }} \ |
| 99 | + --build-arg OTP_VERSION=${{ steps.versions.outputs.otp }} \ |
| 100 | + --build-arg ALPINE_VERSION=3.20.3 \ |
| 101 | + -t elixir-app:test . |
| 102 | +
|
| 103 | + - name: Load images to kind |
| 104 | + run: | |
| 105 | + kind load docker-image erlang-app:test --name kubectl-beam-test |
| 106 | + kind load docker-image elixir-app:test --name kubectl-beam-test |
| 107 | +
|
| 108 | + - name: Deploy test pods |
| 109 | + run: | |
| 110 | + kubectl apply -f examples/k8s/erlang-app-sname.yaml |
| 111 | + kubectl apply -f examples/k8s/erlang-app-name.yaml |
| 112 | + kubectl apply -f examples/k8s/elixir-app-sname.yaml |
| 113 | + kubectl apply -f examples/k8s/elixir-app-name.yaml |
| 114 | +
|
| 115 | + - name: Wait for pods to be ready |
| 116 | + run: | |
| 117 | + kubectl wait --for=condition=ready pod/erlang-app-sname --timeout=120s || (kubectl describe pod erlang-app-sname && kubectl logs erlang-app-sname && exit 1) |
| 118 | + kubectl wait --for=condition=ready pod/erlang-app-name --timeout=120s || (kubectl describe pod erlang-app-name && kubectl logs erlang-app-name && exit 1) |
| 119 | + kubectl wait --for=condition=ready pod/elixir-app-sname --timeout=120s || (kubectl describe pod elixir-app-sname && kubectl logs elixir-app-sname && exit 1) |
| 120 | + kubectl wait --for=condition=ready pod/elixir-app-name --timeout=120s || (kubectl describe pod elixir-app-name && kubectl logs elixir-app-name && exit 1) |
| 121 | +
|
| 122 | + - name: Show pod status |
| 123 | + run: | |
| 124 | + kubectl get pods |
| 125 | + kubectl logs erlang-app-sname || true |
| 126 | + kubectl logs erlang-app-name || true |
| 127 | + kubectl logs elixir-app-sname || true |
| 128 | + kubectl logs elixir-app-name || true |
| 129 | +
|
| 130 | + - name: Run integration tests |
| 131 | + run: bats test/kubectl-beam-integration.bats |
| 132 | + |
| 133 | + - name: Show pod logs on failure |
| 134 | + if: failure() |
| 135 | + run: | |
| 136 | + echo "=== Erlang app (sname) logs ===" |
| 137 | + kubectl logs erlang-app-sname || true |
| 138 | + echo "=== Erlang app (name) logs ===" |
| 139 | + kubectl logs erlang-app-name || true |
| 140 | + echo "=== Elixir app (sname) logs ===" |
| 141 | + kubectl logs elixir-app-sname || true |
| 142 | + echo "=== Elixir app (name) logs ===" |
| 143 | + kubectl logs elixir-app-name || true |
0 commit comments