|
| 1 | +name: Microsoft Azure CLI kubectl plugin CI |
| 2 | +env: |
| 3 | + GO_VERSION: 1.17 # TODO: Update |
| 4 | + AZURE_PREFIX: kubectl-az-ci |
| 5 | +concurrency: |
| 6 | + # Only one workflow can run at a time unless |
| 7 | + # we create a new AKS cluster per github_ref (branch) |
| 8 | + group: kubectl-az-ci |
| 9 | + |
| 10 | +on: |
| 11 | + pull_request: |
| 12 | + push: |
| 13 | + branches: |
| 14 | + - main |
| 15 | + |
| 16 | +jobs: |
| 17 | + build: |
| 18 | + name: Build kubectl-az |
| 19 | + runs-on: ubuntu-latest |
| 20 | + strategy: |
| 21 | + matrix: |
| 22 | + os: [ linux, darwin, windows ] |
| 23 | + arch: [ amd64, arm64 ] |
| 24 | + exclude: |
| 25 | + - os: windows |
| 26 | + arch: arm64 |
| 27 | + steps: |
| 28 | + - name: Set up Go |
| 29 | + uses: actions/setup-go@v4 |
| 30 | + with: |
| 31 | + go-version: ${{ env.GO_VERSION }} |
| 32 | + check-latest: true |
| 33 | + - name: Cache Go |
| 34 | + uses: actions/cache@v3 |
| 35 | + with: |
| 36 | + path: | |
| 37 | + ~/.cache/go-build |
| 38 | + ~/go/pkg/mod |
| 39 | + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} |
| 40 | + restore-keys: | |
| 41 | + ${{ runner.os }}-go- |
| 42 | + - name: Check out code |
| 43 | + uses: actions/checkout@v3 |
| 44 | + - name: Build and generate tarball |
| 45 | + run: | |
| 46 | + target=kubectl-az-${{ matrix.os }}-${{ matrix.arch }} |
| 47 | +
|
| 48 | + make $target |
| 49 | +
|
| 50 | + binary_name=kubectl-az |
| 51 | + if [ ${{ matrix.os }} = "windows" ]; then |
| 52 | + binary_name=kubectl-az.exe |
| 53 | + fi |
| 54 | +
|
| 55 | + # Prepare binary as artifact, it will be used by other jobs |
| 56 | + mv $target $binary_name |
| 57 | + tar --sort=name --owner=root:0 --group=root:0 \ |
| 58 | + -czf ${target}.tar.gz \ |
| 59 | + $binary_name LICENSE |
| 60 | + - name: Add kubectl-az-${{ matrix.os }}-${{ matrix.arch }}.tar.gz as artifact |
| 61 | + uses: actions/upload-artifact@v3 |
| 62 | + with: |
| 63 | + name: kubectl-az-${{ matrix.os }}-${{ matrix.arch }} |
| 64 | + path: kubectl-az-${{ matrix.os }}-${{ matrix.arch }}.tar.gz |
| 65 | + |
| 66 | + unit-tests: |
| 67 | + name: Run unit tests |
| 68 | + runs-on: ubuntu-latest |
| 69 | + steps: |
| 70 | + - name: Set up Go |
| 71 | + uses: actions/setup-go@v4 |
| 72 | + with: |
| 73 | + go-version: ${{ env.GO_VERSION }} |
| 74 | + check-latest: true |
| 75 | + - name: Check out code |
| 76 | + uses: actions/checkout@v3 |
| 77 | + - name: Cache Go |
| 78 | + uses: actions/cache@v3 |
| 79 | + with: |
| 80 | + path: | |
| 81 | + ~/.cache/go-build |
| 82 | + ~/go/pkg/mod |
| 83 | + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} |
| 84 | + restore-keys: | |
| 85 | + ${{ runner.os }}-go- |
| 86 | + - name: Run tests |
| 87 | + run: make unit-test |
| 88 | + |
| 89 | + create-aks-cluster: |
| 90 | + name: Create AKS cluster |
| 91 | + needs: [ build, unit-tests ] |
| 92 | + runs-on: ubuntu-latest |
| 93 | + strategy: |
| 94 | + fail-fast: false |
| 95 | + matrix: |
| 96 | + arch: [ amd64 ] |
| 97 | + steps: |
| 98 | + - name: Login to Azure |
| 99 | + uses: azure/login@v1 |
| 100 | + with: |
| 101 | + creds: ${{ secrets.AZURE_CREDENTIALS }} |
| 102 | + - name: Create AKS cluster ${{ env.AZURE_PREFIX }}-${{ matrix.arch }}-cluster |
| 103 | + shell: bash |
| 104 | + run: | |
| 105 | + az aks create \ |
| 106 | + --resource-group ${{ env.AZURE_PREFIX }}-rg \ |
| 107 | + --name ${{ env.AZURE_PREFIX }}-${{ matrix.arch }}-cluster \ |
| 108 | + --node-count 1 \ |
| 109 | + --generate-ssh-keys |
| 110 | +
|
| 111 | + delete-aks-cluster: |
| 112 | + name: Delete AKS cluster |
| 113 | + if: always() |
| 114 | + needs: [ integration-tests ] |
| 115 | + runs-on: ubuntu-latest |
| 116 | + strategy: |
| 117 | + fail-fast: false |
| 118 | + matrix: |
| 119 | + arch: [ amd64 ] |
| 120 | + steps: |
| 121 | + - name: Login to Azure |
| 122 | + uses: azure/login@v1 |
| 123 | + with: |
| 124 | + creds: ${{ secrets.AZURE_CREDENTIALS }} |
| 125 | + - name: Delete AKS cluster ${{ env.AZURE_PREFIX }}-${{ matrix.arch }}-cluster |
| 126 | + shell: bash |
| 127 | + run: | |
| 128 | + az aks delete \ |
| 129 | + --resource-group ${{ env.AZURE_PREFIX }}-rg \ |
| 130 | + --name ${{ env.AZURE_PREFIX }}-${{ matrix.arch }}-cluster \ |
| 131 | + --yes |
| 132 | +
|
| 133 | + integration-tests: |
| 134 | + name: Run integration tests |
| 135 | + needs: [ build, unit-tests , create-aks-cluster ] |
| 136 | + runs-on: ${{ matrix.os }} |
| 137 | + strategy: |
| 138 | + fail-fast: false |
| 139 | + # 'run-command' is not supported in parallel for a given node |
| 140 | + # (don't want to create a new cluster for each OS) |
| 141 | + max-parallel: 1 |
| 142 | + matrix: |
| 143 | + os: [ ubuntu-latest, macOS-latest, windows-latest ] |
| 144 | + arch: [ amd64 ] # TODO: Support ARM |
| 145 | + steps: |
| 146 | + - name: Set up Go |
| 147 | + uses: actions/setup-go@v4 |
| 148 | + with: |
| 149 | + go-version: ${{ env.GO_VERSION }} |
| 150 | + check-latest: true |
| 151 | + - name: Check out code |
| 152 | + uses: actions/checkout@v3 |
| 153 | + - name: Set environment variables |
| 154 | + shell: bash |
| 155 | + run: | |
| 156 | + case ${{ matrix.os }} in |
| 157 | + ubuntu-latest) |
| 158 | + echo "os=linux" >> $GITHUB_ENV |
| 159 | + ;; |
| 160 | + macOS-latest) |
| 161 | + echo "os=darwin" >> $GITHUB_ENV |
| 162 | + ;; |
| 163 | + windows-latest) |
| 164 | + echo "os=windows" >> $GITHUB_ENV |
| 165 | + ;; |
| 166 | + *) |
| 167 | + echo "Not supported OS: ${{ matrix.os }}" |
| 168 | + exit 1 |
| 169 | + ;; |
| 170 | + esac |
| 171 | + - name: Get kubectl-az from artifact |
| 172 | + uses: actions/download-artifact@v3 |
| 173 | + with: |
| 174 | + name: kubectl-az-${{ env.os }}-${{ matrix.arch }} |
| 175 | + - name: Prepare kubectl-az binary |
| 176 | + shell: bash |
| 177 | + run: | |
| 178 | + tar zxvf kubectl-az-${{ env.os }}-${{ matrix.arch }}.tar.gz |
| 179 | + chmod +x kubectl-az |
| 180 | + ls -la |
| 181 | + - name: Login to Azure |
| 182 | + uses: azure/login@v1 |
| 183 | + with: |
| 184 | + creds: ${{ secrets.AZURE_CREDENTIALS }} |
| 185 | + - name: Set AKS cluster context |
| 186 | + uses: azure/aks-set-context@v3 |
| 187 | + with: |
| 188 | + cluster-name: ${{ env.AZURE_PREFIX }}-${{ matrix.arch }}-cluster |
| 189 | + resource-group: ${{ env.AZURE_PREFIX }}-rg |
| 190 | + admin: false |
| 191 | + - if: matrix.os != 'ubuntu-latest' |
| 192 | + # kubectl is already installed in Linux runners |
| 193 | + uses: azure/setup-kubectl@v3 |
| 194 | + - name: Run integration tests |
| 195 | + shell: bash |
| 196 | + run: | |
| 197 | + make integration-test -o kubectl-az |
0 commit comments