|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - '**' |
| 7 | + - '!dependabot/**' |
| 8 | + tags: |
| 9 | + - '**' |
| 10 | + pull_request: {} |
| 11 | + |
| 12 | +jobs: |
| 13 | + |
| 14 | + unit: |
| 15 | + env: |
| 16 | + TANZU_CLI_NO_INIT: true |
| 17 | + TANZU_HOME: $HOME/tanzu |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v3 |
| 21 | + - uses: actions/setup-go@v2 |
| 22 | + with: |
| 23 | + go-version: 1.17.x |
| 24 | + - name: Grype scan |
| 25 | + run: | |
| 26 | + echo "##[group]Install grype" |
| 27 | + curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b /usr/local/bin |
| 28 | + echo "##[endgroup]" |
| 29 | + echo "##[group]Scan source ." |
| 30 | + grype dir:. --exclude ./hack,./vendor |
| 31 | + echo "##[endgroup]" |
| 32 | + - name: Install tanzu cli |
| 33 | + run: | |
| 34 | + TANZU_VERSION=$(cat TANZU_VERSION) |
| 35 | + env |
| 36 | + mkdir -p ${TANZU_HOME} |
| 37 | + curl -Lo tanzu-framework.tar.gz https://github.com/vmware-tanzu/tanzu-framework/releases/download/${TANZU_VERSION}/tanzu-framework-linux-amd64.tar.gz |
| 38 | + tar -xzf tanzu-framework.tar.gz -C ${TANZU_HOME} |
| 39 | + sudo mv ${TANZU_HOME}/cli/core/${TANZU_VERSION}/tanzu-core-linux_amd64 /usr/local/bin/tanzu |
| 40 | + chmod +x /usr/local/bin/tanzu |
| 41 | + tanzu init |
| 42 | + tanzu plugin repo add -b tanzu-cli-admin-plugins -n admin -p artifacts-admin |
| 43 | + curl -Lo admin-plugins.tar.gz https://github.com/vmware-tanzu/tanzu-framework/releases/download/${TANZU_VERSION}/tanzu-framework-plugins-admin-linux-amd64.tar.gz |
| 44 | + tar -xzf admin-plugins.tar.gz -C ${TANZU_HOME} |
| 45 | + tanzu plugin install builder --local ${TANZU_HOME}/admin-plugins |
| 46 | + tanzu plugin install test --local ${TANZU_HOME}/admin-plugins |
| 47 | + tanzu plugin list |
| 48 | + - name: Test |
| 49 | + run: make test |
| 50 | + - uses: codecov/codecov-action@v2 |
| 51 | + with: |
| 52 | + token: c6e0ea67-1493-464a-b879-d8f06da7d313 |
| 53 | + - name: Build Version |
| 54 | + run: echo "BUILD_VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV |
| 55 | + if: startsWith(github.ref, 'refs/tags/') |
| 56 | + - name: Build |
| 57 | + run: make publish |
| 58 | + - uses: actions/upload-artifact@v2 |
| 59 | + with: |
| 60 | + name: tanzu-apps-plugin.tar.gz |
| 61 | + path: tanzu-apps-plugin*.tar.gz |
| 62 | + retention-days: 1 |
| 63 | + - name: Install |
| 64 | + run: make install |
| 65 | + - name: Verify docs |
| 66 | + run: | |
| 67 | + rm -rf docs/command-reference |
| 68 | + tanzu apps docs --directory docs/command-reference |
| 69 | + git diff --exit-code docs |
| 70 | + continue-on-error: true |
| 71 | + |
| 72 | + acceptance: |
| 73 | + needs: unit |
| 74 | + runs-on: ubuntu-latest |
| 75 | + strategy: |
| 76 | + matrix: |
| 77 | + k8s: |
| 78 | + - 1.20.2 |
| 79 | + - 1.21.2 |
| 80 | + - 1.22.5 |
| 81 | + env: |
| 82 | + REGISTRY_NAME: registry.local |
| 83 | + REGISTRY_PORT: 5000 |
| 84 | + TANZU_CLI_NO_INIT: true |
| 85 | + TANZU_HOME: $HOME/tanzu |
| 86 | + OS_ARCH: linux-amd64 |
| 87 | + steps: |
| 88 | + - uses: actions/checkout@v3 |
| 89 | + - uses: vmware-tanzu/carvel-setup-action@v1 |
| 90 | + - name: Download plugin bundle |
| 91 | + uses: actions/download-artifact@v2 |
| 92 | + with: |
| 93 | + name: tanzu-apps-plugin.tar.gz |
| 94 | + - name: Install tanzu cli |
| 95 | + run: | |
| 96 | + TANZU_VERSION=$(cat TANZU_VERSION) |
| 97 | + mkdir -p ${TANZU_HOME} |
| 98 | + curl -Lo tanzu-framework.tar.gz https://github.com/vmware-tanzu/tanzu-framework/releases/download/${TANZU_VERSION}/tanzu-framework-linux-amd64.tar.gz |
| 99 | + tar -xzf tanzu-framework.tar.gz -C ${TANZU_HOME} |
| 100 | + sudo mv ${TANZU_HOME}/cli/core/${TANZU_VERSION}/tanzu-core-linux_amd64 /usr/local/bin/tanzu |
| 101 | + chmod +x /usr/local/bin/tanzu |
| 102 | + env |
| 103 | + tanzu init |
| 104 | + - name: Build Version |
| 105 | + run: echo "BUILD_VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV |
| 106 | + if: startsWith(github.ref, 'refs/tags/') |
| 107 | + - name: Install CLI |
| 108 | + run: | |
| 109 | + set -o errexit |
| 110 | + set -o nounset |
| 111 | + set -o pipefail |
| 112 | +
|
| 113 | + tar -xvf tanzu-apps-plugin.tar.gz |
| 114 | + tanzu plugin install apps --local ./${OS_ARCH} --version ${BUILD_VERSION:-v0.0.0-dev} |
| 115 | + - name: Install kind |
| 116 | + run: | |
| 117 | + cd $(mktemp -d -t kind.XXXX) |
| 118 | + curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.11.1/kind-$(go env GOHOSTOS)-$(go env GOHOSTARCH) |
| 119 | + chmod +x ./kind |
| 120 | + sudo mv ./kind /usr/local/bin |
| 121 | + cd - |
| 122 | + - name: Create Cluster |
| 123 | + run: | |
| 124 | + set -o errexit |
| 125 | + set -o nounset |
| 126 | + set -o pipefail |
| 127 | +
|
| 128 | + # KinD configuration. |
| 129 | + cat > kind.yaml <<EOF |
| 130 | + apiVersion: kind.x-k8s.io/v1alpha4 |
| 131 | + kind: Cluster |
| 132 | + nodes: |
| 133 | + - role: control-plane |
| 134 | + image: kindest/node:v${{ matrix.k8s }} |
| 135 | + EOF |
| 136 | + kind create cluster --wait 5m --config kind.yaml |
| 137 | + - name: Deploy Cartographer |
| 138 | + run: | |
| 139 | + set -o errexit |
| 140 | + set -o nounset |
| 141 | + set -o pipefail |
| 142 | +
|
| 143 | + echo "##[group]Apply cartographer" |
| 144 | + kubectl create namespace cartographer-system |
| 145 | + kapp deploy -y -a cartographer -n kube-system -f ./acceptance/vendor/cartographer/ |
| 146 | + echo "##[endgroup]" |
| 147 | + echo "##[group]Apply static pod" |
| 148 | + kubectl apply -f ./.github/samples/pod.yaml |
| 149 | + echo "##[endgroup]" |
| 150 | + - name: Test CLI commands |
| 151 | + run: | |
| 152 | + set -o errexit |
| 153 | + set -o nounset |
| 154 | + set -o pipefail |
| 155 | +
|
| 156 | + echo "##[group]Create workload" |
| 157 | + tanzu apps workload create petclinic --git-repo example.com --git-branch main --annotation serving.knative.dev/maxScale=10 --yes |
| 158 | + echo "##[endgroup]" |
| 159 | + echo "##[group]List workload" |
| 160 | + tanzu apps workload list |
| 161 | + echo "##[endgroup]" |
| 162 | + echo "##[group]Get workload" |
| 163 | + tanzu apps workload get petclinic |
| 164 | + echo "##[endgroup]" |
| 165 | + echo "##[group]Update workload" |
| 166 | + tanzu apps workload update petclinic --label cli.ci/new-label=true --yes |
| 167 | + echo "##[endgroup]" |
| 168 | + - name: Collect diagnostics |
| 169 | + run: | |
| 170 | + echo "##[group]Static Pod" |
| 171 | + kubectl describe pod static-web |
| 172 | + echo "##[endgroup]" |
| 173 | + echo "##[group]Workload" |
| 174 | + kubectl describe workload petclinic |
| 175 | + echo "##[endgroup]" |
| 176 | + continue-on-error: true |
| 177 | + - name: Delete Gracefully |
| 178 | + run: | |
| 179 | + set -o errexit |
| 180 | + set -o nounset |
| 181 | + set -o pipefail |
| 182 | +
|
| 183 | + echo "##[group]Delete workload" |
| 184 | + printf 'y' | tanzu apps workload delete petclinic |
| 185 | + echo "##[endgroup]" |
| 186 | + echo "##[group]Delete pod" |
| 187 | + kubectl delete -f ./.github/samples/pod.yaml |
| 188 | + echo "##[endgroup]" |
| 189 | + echo "##[group]Delete cartographer" |
| 190 | + kapp delete -y -a cartographer -n kube-system |
| 191 | + kubectl delete namespace cartographer-system |
| 192 | + echo "##[endgroup]" |
| 193 | + if: always() |
| 194 | + - name: Cleanup cluster |
| 195 | + run: kind delete cluster |
| 196 | + if: always() |
| 197 | + |
| 198 | + create-release: |
| 199 | + needs: |
| 200 | + - unit |
| 201 | + - acceptance |
| 202 | + if: startsWith(github.ref, 'refs/tags/') |
| 203 | + runs-on: ubuntu-latest |
| 204 | + steps: |
| 205 | + - name: Get the version |
| 206 | + id: get_version |
| 207 | + run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} |
| 208 | + - name: Draft release |
| 209 | + id: create_release |
| 210 | + uses: actions/create-release@v1.1.4 |
| 211 | + env: |
| 212 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token |
| 213 | + with: |
| 214 | + tag_name: ${{ github.ref }} |
| 215 | + release_name: Release ${{ steps.get_version.outputs.VERSION }} |
| 216 | + draft: true |
| 217 | + - name: Create release info files |
| 218 | + run: | |
| 219 | + echo "${{ steps.get_version.outputs.VERSION }}" > RELEASE_INFO_VERSION |
| 220 | + echo "${{ steps.create_release.outputs.upload_url }}" > RELEASE_INFO_UPLOAD_URL |
| 221 | + - name: Upload release files |
| 222 | + uses: actions/upload-artifact@v2 |
| 223 | + with: |
| 224 | + name: tanzu-apps-plugin.tar.gz |
| 225 | + path: RELEASE_INFO_* |
| 226 | + retention-days: 1 |
| 227 | + |
| 228 | + |
| 229 | + release: |
| 230 | + needs: |
| 231 | + - create-release |
| 232 | + if: startsWith(github.ref, 'refs/tags/') |
| 233 | + strategy: |
| 234 | + matrix: |
| 235 | + os-arch: ["", -darwin-amd64, -linux-amd64, -windows-amd64] |
| 236 | + runs-on: ubuntu-latest |
| 237 | + env: |
| 238 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 239 | + steps: |
| 240 | + - name: Download staged CLI binaries${{ matrix.os-arch }} |
| 241 | + uses: actions/download-artifact@v2.0.10 |
| 242 | + with: |
| 243 | + name: tanzu-apps-plugin.tar.gz |
| 244 | + - name: Get release info |
| 245 | + run: | |
| 246 | + echo "RELEASE_VERSION=$(cat RELEASE_INFO_VERSION)" >> $GITHUB_ENV |
| 247 | + echo "UPLOAD_URL=$(cat RELEASE_INFO_UPLOAD_URL)" >> $GITHUB_ENV |
| 248 | + - name: Upload CLI release${{ matrix.os-arch }} |
| 249 | + uses: actions/upload-release-asset@v1.0.2 |
| 250 | + with: |
| 251 | + upload_url: ${{ env.UPLOAD_URL }} |
| 252 | + asset_path: tanzu-apps-plugin${{ matrix.os-arch }}.tar.gz |
| 253 | + asset_name: tanzu-apps-plugin${{ matrix.os-arch }}-${{ env.RELEASE_VERSION }}.tar.gz |
| 254 | + asset_content_type: application/gzip |
| 255 | + |
0 commit comments