docs: Add documentation-test for run-command.md #84
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Azure Kubernetes Service kubectl plugin CI | |
env: | |
GO_VERSION: 1.18 | |
AZURE_PREFIX: kubectl-aks-ci | |
AZURE_NODE_COUNT: 4 | |
concurrency: | |
# Only one workflow can run at a time unless | |
# we create a new AKS cluster per github_ref (branch) | |
group: kubectl-aks-ci | |
on: | |
pull_request: | |
push: | |
branches: | |
- main | |
tags: | |
- 'v*' | |
jobs: | |
build: | |
name: Build kubectl-aks | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
os: [ linux, darwin, windows ] | |
arch: [ amd64, arm64 ] | |
exclude: | |
- os: windows | |
arch: arm64 | |
steps: | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
check-latest: true | |
- name: Cache Go | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.cache/go-build | |
~/go/pkg/mod | |
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
restore-keys: | | |
${{ runner.os }}-go- | |
- name: Check out code | |
uses: actions/checkout@v3 | |
- name: Build and generate tarball | |
run: | | |
target=kubectl-aks-${{ matrix.os }}-${{ matrix.arch }} | |
make $target | |
binary_name=kubectl-aks | |
if [ ${{ matrix.os }} = "windows" ]; then | |
binary_name=kubectl-aks.exe | |
fi | |
# Prepare binary as artifact, it will be used by other jobs | |
mv $target $binary_name | |
tar --sort=name --owner=root:0 --group=root:0 \ | |
-czf ${target}.tar.gz \ | |
$binary_name LICENSE | |
- name: Add kubectl-aks-${{ matrix.os }}-${{ matrix.arch }}.tar.gz as artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: kubectl-aks-${{ matrix.os }}-${{ matrix.arch }}-tar-gz | |
path: kubectl-aks-${{ matrix.os }}-${{ matrix.arch }}.tar.gz | |
lint: | |
name: Run linter | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
check-latest: true | |
- name: Lint | |
uses: golangci/golangci-lint-action@v3.5.0 | |
with: | |
# This version number must be kept in sync with Makefile lint one. | |
version: v1.53.2 | |
working-directory: /home/runner/work/kubectl-aks/kubectl-aks | |
# Workaround to display the output: | |
# https://github.com/golangci/golangci-lint-action/issues/119#issuecomment-981090648 | |
args: "--out-${NO_FUTURE}format colored-line-number" | |
unit-tests: | |
name: Run unit tests | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
check-latest: true | |
- name: Check out code | |
uses: actions/checkout@v3 | |
- name: Cache Go | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.cache/go-build | |
~/go/pkg/mod | |
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
restore-keys: | | |
${{ runner.os }}-go- | |
- name: Run tests | |
run: make unit-test | |
create-aks-cluster: | |
name: Create AKS cluster | |
needs: [ build, lint, unit-tests ] | |
runs-on: ubuntu-latest | |
outputs: | |
nodes: ${{ steps.nodes.outputs.result }} | |
strategy: | |
fail-fast: false | |
matrix: | |
arch: [ amd64 ] | |
environment: aks | |
permissions: | |
# This is needed to use federated credentials: | |
# https://learn.microsoft.com/en-us/azure/developer/github/connect-from-azure?tabs=azure-cli%2Clinux#set-up-azure-login-with-openid-connect-authentication | |
id-token: write | |
contents: read | |
steps: | |
- name: Login to Azure | |
uses: azure/login@v1 | |
with: | |
client-id: ${{ secrets.AZURE_AKS_CLIENT_ID }} | |
tenant-id: ${{ secrets.AZURE_AKS_TENANT_ID }} | |
subscription-id: ${{ secrets.AZURE_AKS_SUBSCRIPTION_ID }} | |
- name: Create AKS cluster ${{ env.AZURE_PREFIX }}-${{ matrix.arch }}-cluster | |
shell: bash | |
run: | | |
az aks create \ | |
--resource-group ${{ env.AZURE_PREFIX }}-rg \ | |
--name ${{ env.AZURE_PREFIX }}-${{ matrix.arch }}-cluster \ | |
--node-count ${{ env.AZURE_NODE_COUNT }} \ | |
--generate-ssh-keys | |
- name: Prepare list of nodes | |
id: nodes | |
shell: bash | |
run: | | |
az aks get-credentials \ | |
--resource-group ${{ env.AZURE_PREFIX }}-rg \ | |
--name ${{ env.AZURE_PREFIX }}-${{ matrix.arch }}-cluster \ | |
--admin | |
echo "result=$(kubectl get nodes -o jsonpath='{.items[*].metadata.name}' | jq -R -s -c 'split(" ")')" >> $GITHUB_OUTPUT | |
delete-aks-cluster: | |
name: Delete AKS cluster | |
if: always() | |
needs: [ integration-tests ] | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
arch: [ amd64 ] | |
environment: aks | |
permissions: | |
# This is needed to use federated credentials: | |
# https://learn.microsoft.com/en-us/azure/developer/github/connect-from-azure?tabs=azure-cli%2Clinux#set-up-azure-login-with-openid-connect-authentication | |
id-token: write | |
contents: read | |
steps: | |
- name: Login to Azure | |
uses: azure/login@v1 | |
with: | |
client-id: ${{ secrets.AZURE_AKS_CLIENT_ID }} | |
tenant-id: ${{ secrets.AZURE_AKS_TENANT_ID }} | |
subscription-id: ${{ secrets.AZURE_AKS_SUBSCRIPTION_ID }} | |
- name: Delete AKS cluster ${{ env.AZURE_PREFIX }}-${{ matrix.arch }}-cluster | |
shell: bash | |
run: | | |
az aks delete \ | |
--resource-group ${{ env.AZURE_PREFIX }}-rg \ | |
--name ${{ env.AZURE_PREFIX }}-${{ matrix.arch }}-cluster \ | |
--yes | |
integration-tests: | |
name: Run integration tests | |
needs: [ build, unit-tests , create-aks-cluster ] | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ ubuntu-latest, macOS-latest, windows-latest ] | |
arch: [ amd64 ] # TODO: Support ARM | |
environment: aks | |
permissions: | |
# This is needed to use federated credentials: | |
# https://learn.microsoft.com/en-us/azure/developer/github/connect-from-azure?tabs=azure-cli%2Clinux#set-up-azure-login-with-openid-connect-authentication | |
id-token: write | |
contents: read | |
steps: | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
check-latest: true | |
- name: Check out code | |
uses: actions/checkout@v3 | |
- name: Set environment variables | |
shell: bash | |
run: | | |
case ${{ matrix.os }} in | |
ubuntu-latest) | |
echo "os=linux" >> $GITHUB_ENV | |
;; | |
macOS-latest) | |
echo "os=darwin" >> $GITHUB_ENV | |
;; | |
windows-latest) | |
echo "os=windows" >> $GITHUB_ENV | |
;; | |
*) | |
echo "Not supported OS: ${{ matrix.os }}" | |
exit 1 | |
;; | |
esac | |
- name: Get kubectl-aks from artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: kubectl-aks-${{ env.os }}-${{ matrix.arch }}-tar-gz | |
- name: Prepare kubectl-aks binary | |
shell: bash | |
run: | | |
tar zxvf kubectl-aks-${{ env.os }}-${{ matrix.arch }}.tar.gz | |
chmod +x kubectl-aks | |
ls -la | |
- name: Login to Azure | |
uses: azure/login@v1 | |
with: | |
client-id: ${{ secrets.AZURE_AKS_CLIENT_ID }} | |
tenant-id: ${{ secrets.AZURE_AKS_TENANT_ID }} | |
subscription-id: ${{ secrets.AZURE_AKS_SUBSCRIPTION_ID }} | |
- name: Set AKS cluster context | |
uses: azure/aks-set-context@v3 | |
with: | |
cluster-name: ${{ env.AZURE_PREFIX }}-${{ matrix.arch }}-cluster | |
resource-group: ${{ env.AZURE_PREFIX }}-rg | |
admin: false | |
- if: matrix.os != 'ubuntu-latest' | |
# kubectl is already installed in Linux runners | |
uses: azure/setup-kubectl@v3 | |
# https://github.com/Azure/setup-kubectl/issues/88 | |
with: | |
version: 'v1.28.2' | |
- name: Run integration tests | |
shell: bash | |
run: | | |
export AZURE_RESOURCE_GROUP=${{ env.AZURE_PREFIX }}-rg | |
export AZURE_CLUSTER_NAME=${{ env.AZURE_PREFIX }}-${{ matrix.arch }}-cluster | |
export AZURE_SUBSCRIPTION_ID=${{ secrets.AZURE_AKS_SUBSCRIPTION_ID }} | |
export AZURE_NODE_NAME=$(echo '${{ needs.create-aks-cluster.outputs.nodes }}' | jq -r ".[${{ strategy.job-index }}]") | |
make integration-test -o kubectl-aks | |
test-docs: | |
name: Test docs | |
runs-on: ubuntu-latest | |
needs: [ build, unit-tests, create-aks-cluster ] | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '>=1.20.0' # ie requires go 1.20+ | |
check-latest: true | |
- name: Get kubectl-aks from artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: kubectl-aks-linux-amd64-tar-gz | |
- name: Prepare kubectl-aks binary | |
shell: bash | |
run: | | |
tar zxvf kubectl-aks-linux-amd64.tar.gz | |
chmod +x kubectl-aks | |
mv kubectl-aks /usr/local/bin | |
ls -la | |
- name: Download ie | |
run: | | |
go install github.com/Azure/InnovationEngine/cmd/ie@03880d11fadcf98e39c465248aa1d5b64f99cdb7 | |
- name: Prepare variables files | |
run: | | |
VAR_FILES="./docs/run-command.ini" | |
for f in $VAR_FILES; do | |
echo "mySubID = ${{ secrets.AZURE_AKS_SUBSCRIPTION_ID }}" >> $f | |
echo "myRG = ${{ env.AZURE_PREFIX }}-rg" >> $f | |
echo "myCluster = ${{ env.AZURE_PREFIX }}-amd64-cluster" >> $f | |
echo "myNode = $(echo '${{ needs.create-aks-cluster.outputs.nodes }}' | jq -r ".[3]")" >> $f | |
done | |
- name: Test docs | |
run: make test-docs | |
release: | |
name: Release | |
needs: [ integration-tests ] | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
if: startsWith(github.ref, 'refs/tags/v') | |
steps: | |
# Checkout the repo to get the .krew.yaml file | |
- uses: actions/checkout@v3 | |
- name: Get all artifacts. | |
uses: actions/download-artifact@v3 | |
- name: Rename all artifacts to kubectl-aks-${{ github.ref_name }}.tar.gz | |
shell: bash | |
run: | | |
for i in kubectl-aks-*-*-tar-gz/kubectl-aks-*-*.tar.gz; do | |
mv $i $(dirname $i)/$(basename $i .tar.gz)-${{ github.ref_name }}.tar.gz | |
done | |
- name: Create Release | |
id: create_release | |
uses: softprops/action-gh-release@v1 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
name: Release ${{ github.ref }} | |
- name: Upload kubectl-aks binaries to the release | |
uses: csexton/release-asset-action@v2 | |
with: | |
pattern: "kubectl-aks-*-*-tar-gz/kubectl-aks-*-*.tar.gz" | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
release-url: ${{ steps.create_release.outputs.upload_url }} | |
- name: Update new version in krew-index | |
if: github.repository == 'azure/kubectl-aks' | |
uses: rajatjindal/krew-release-bot@v0.0.46 |