Skip to content

Commit

Permalink
ci(actions): use a more readable way to generate e2e matrix
Browse files Browse the repository at this point in the history
Signed-off-by: Jay Chen <[email protected]>
  • Loading branch information
jijiechen committed Nov 22, 2023
1 parent 0bb456e commit c40f055
Showing 1 changed file with 55 additions and 47 deletions.
102 changes: 55 additions & 47 deletions .github/workflows/build-test-distribute.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,11 @@ jobs:
gen_e2e_matrix:
runs-on: ubuntu-latest
needs: ["build"]
if: ${{ !contains(github.event.pull_request.labels.*.name, 'ci/skip-test') && !contains(github.event.pull_request.labels.*.name, 'ci/skip-e2e-test') }}
outputs:
slow: ${{ steps.generate-matrix.outputs.slow }}
main: ${{ steps.generate-matrix.outputs.main }}
delta_kds: ${{ steps.generate-matrix.outputs.delta_kds }}
legacy_kds: ${{ steps.generate-matrix.outputs.legacy_kds }}
cni: ${{ steps.generate-matrix.outputs.cni }}
steps:
- name: Install jq
Expand All @@ -188,56 +189,47 @@ jobs:
- id: generate-matrix
name: Generate matrix
run: |
SKIP_CI_LABEL="${{ contains(github.event.pull_request.labels.*.name, 'ci/skip-test') || contains(github.event.pull_request.labels.*.name, 'ci/skip-e2e-test') }}"
if [[ "$SKIP_CI_LABEL" == "true" ]]; then
echo "Skipping e2e jobs because the pull request contained a 'ci/skip-*' label."
exit 0
fi
JQ_PATH=$(which jq)
if [ "$JQ_PATH" == "" ]; then
echo "Could not find devtool 'jq', please check if 'check' job has run correctly prior to this job."
exit 1
fi
ALL_K8S_VERSION='{"k8sVersion":["kind", "kindIpv6", "${{ env.K8S_MIN_VERSION }}", "${{ env.K8S_MAX_VERSION }}"]}'
ALL_ARCH='{"arch": ["amd64", "arm64"]}'
ALL_TARGET='{"target": ["kubernetes", "universal", "multizone"]}'
BASE_MATRIX=$(cat <<-END
{
"target": ["kubernetes", "universal", "multizone"],
"k8sVersion": ["kind", "kindIpv6", "${{ env.K8S_MIN_VERSION }}", "${{ env.K8S_MAX_VERSION }}"],
"arch": ["amd64", "arm64"],
"cniNetworkPlugin": ["flannel"],
"legacyKDS": [false],
"exclude":[
{"target": "kubernetes", "k8sVersion":"kind"},
{"target": "multizone", "k8sVersion":"kind"},
{"target":"universal", "k8sVersion":"${{ env.K8S_MIN_VERSION }}"},
{"target":"universal", "k8sVersion":"${{ env.K8S_MAX_VERSION }}"}
]
}
END
)
SLOW=$(echo $BASE_MATRIX | jq -rc '.target = [""]')
MAIN=$(echo $BASE_MATRIX | jq -rc)
SINGLE_ENV='{"k8sVersion": ["${{ env.K8S_MAX_VERSION }}"], "target": ["multizone"], "arch":["amd64"]}'
ALL_DELTA_KDS='{"deltaKDS": [true]}'
ALL_CNI='{"cniNetworkPlugin": ["calico"]}'
# GitHub Actions does not support ARM64
EXCLUDE_ARM64='[{"arch": "arm64"}]'
LEGACY_KDS=$(echo '{}' | jq -rc ".legacyKDS = [true] | . += $SINGLE_ENV")
CNI=$(echo '{}' | jq -rc ".cniNetworkPlugin = [\"calico\"] | . += $SINGLE_ENV")
# kind should only be used when testing ipv6 or with e2e-universal
EXCLUDE_KIND='[{"k8sVersion":"kind", "target": "kubernetes"}, {"k8sVersion":"kind", "target": "multizone"}]'
# universal only runs on kind
EXCLUDE_UNIVERSAL='[{"target":"universal", "k8sVersion":"${{ env.K8S_MIN_VERSION }}"}, {"target":"universal", "k8sVersion":"${{ env.K8S_MAX_VERSION }}"}]'
# non priority main e2e
EXCLUDE_MAIN_NON_PRIORITY='[{"k8sVersion":"kindIpv6"}, {"k8sVersion": "${{ env.K8S_MIN_VERSION }}"}]'
# Default matrix
SLOW=$(echo '{}' | $JQ_PATH -rc ".exclude += $EXCLUDE_ARM64" | $JQ_PATH -rc ". += $ALL_K8S_VERSION | . += $ALL_ARCH")
MAIN=$(echo '{}' | $JQ_PATH -rc ".exclude += $EXCLUDE_ARM64" | $JQ_PATH -rc ". += $ALL_K8S_VERSION | . += $ALL_ARCH | . += $ALL_TARGET" | $JQ_PATH -rc ".exclude += $EXCLUDE_KIND | .exclude += $EXCLUDE_UNIVERSAL" )
DELTA_KDS=$(echo '{}' | $JQ_PATH -rc ".exclude += $EXCLUDE_ARM64" | $JQ_PATH -rc ". += $ALL_DELTA_KDS | . += $SINGLE_ENV")
CNI=$(echo '{}' | $JQ_PATH -rc ".exclude += $EXCLUDE_ARM64" | $JQ_PATH -rc ". += $ALL_CNI | . += $SINGLE_ENV")
RUN_FULL_MATRIX="${{ contains(github.event.pull_request.labels.*.name, 'ci/run-full-matrix') }}"
RUN_FULL_MATRIX="${{ github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'ci/run-full-matrix') }}"
if [[ "$RUN_FULL_MATRIX" == "false" ]]; then
echo "Skipping non priority e2e tests, because no label 'ci/run-full-matrix' was found on the pull request."
echo "Skipping non priority e2e tests, because no label 'ci/run-full-matrix' was found on the pull request and not pushing on a releasable branch."
SLOW='' # target==""
DELTA_KDS='' # deltaKDS=="true"
LEGACY_KDS='' # legacyKDS=="true"
CNI='' # cniNetworkPlugin=="calico"
MAIN=$(echo $MAIN | $JQ_PATH -rc ".exclude += $EXCLUDE_ARM64 | .exclude += $EXCLUDE_MAIN_NON_PRIORITY")
# non priority main e2e
EXCLUDE_ARM64='[{"arch": "arm64"}]'
EXCLUDE_MAIN_NON_PRIORITY='[{"k8sVersion":"kindIpv6"}, {"k8sVersion": "${{ env.K8S_MIN_VERSION }}"}]'
MAIN=$(echo $MAIN | jq -rc ".exclude += $EXCLUDE_ARM64 | .exclude += $EXCLUDE_MAIN_NON_PRIORITY")
fi
echo "slow=$SLOW" >> $GITHUB_OUTPUT
echo "main=$MAIN" >> $GITHUB_OUTPUT
echo "delta_kds=$DELTA_KDS" >> $GITHUB_OUTPUT
echo "legacy_kds=$LEGACY_KDS" >> $GITHUB_OUTPUT
echo "cni=$CNI" >> $GITHUB_OUTPUT
e2e_slow:
name: "legacy-k8s:${{ matrix.arch }}-${{ matrix.k8sVersion }}"
Expand All @@ -250,6 +242,9 @@ jobs:
- run: |
echo "k8sVersion: ${{ matrix.k8sVersion }}"
echo "arch: ${{ matrix.arch }}"
- name: Install jq
run: |
sudo apt-get install -y jq
- uses: actions/checkout@v4
with:
fetch-depth: 0
Expand All @@ -259,6 +254,7 @@ jobs:
arch: ${{ matrix.arch }}
parallelism: 3
target: ""
secureCircleCIToken: ${{ secrets.CIRCLECI_TOKEN }}
e2e_main:
name: "${{ matrix.target }}:${{ matrix.arch }}-${{ matrix.k8sVersion }}"
runs-on: ubuntu-latest
Expand All @@ -271,6 +267,9 @@ jobs:
echo "k8sVersion: ${{ matrix.k8sVersion }}"
echo "target: ${{ matrix.target }}"
echo "arch: ${{ matrix.arch }}"
- name: Install jq
run: |
sudo apt-get install -y jq
- uses: actions/checkout@v4
with:
fetch-depth: 0
Expand All @@ -279,19 +278,23 @@ jobs:
k8sVersion: ${{ matrix.k8sVersion }}
target: ${{ matrix.target }}
arch: ${{ matrix.arch }}
e2e_delta_kds:
name: "${{ matrix.target }}:${{ matrix.arch }}-${{ matrix.k8sVersion }}-delta-kds"
secureCircleCIToken: ${{ secrets.CIRCLECI_TOKEN }}
e2e_legacy_kds:
name: "${{ matrix.target }}:${{ matrix.arch }}-${{ matrix.k8sVersion }}-legacy-kds"
runs-on: ubuntu-latest
needs: ["gen_e2e_matrix"]
if: needs.gen_e2e_matrix.outputs.delta_kds != ''
if: needs.gen_e2e_matrix.outputs.legacy_kds != ''
strategy:
matrix: ${{ fromJSON(needs.gen_e2e_matrix.outputs.delta_kds) }}
matrix: ${{ fromJSON(needs.gen_e2e_matrix.outputs.legacy_kds) }}
steps:
- run: |
echo "k8sVersion: ${{ matrix.k8sVersion }}"
echo "target: ${{ matrix.target }}"
echo "arch: ${{ matrix.arch }}"
echo "deltaKDS: ${{ matrix.arch }}"
echo "legacyKDS: ${{ matrix.arch }}"
- name: Install jq
run: |
sudo apt-get install -y jq
- uses: actions/checkout@v4
with:
fetch-depth: 0
Expand All @@ -300,7 +303,8 @@ jobs:
k8sVersion: ${{ matrix.k8sVersion }}
target: ${{ matrix.arch }}
arch: ${{ matrix.arch }}
deltaKDS: ${{ matrix.deltaKDS }}
legacyKDS: ${{ matrix.legacyKDS }}
secureCircleCIToken: ${{ secrets.CIRCLECI_TOKEN }}
e2e_calico:
name: "${{ matrix.target }}:${{ matrix.arch }}-${{ matrix.k8sVersion }}-calico"
runs-on: ubuntu-latest
Expand All @@ -314,6 +318,9 @@ jobs:
echo "target: ${{ matrix.target }}"
echo "arch: ${{ matrix.arch }}"
echo "cniNetworkPlugin: ${{ matrix.cniNetworkPlugin }}"
- name: Install jq
run: |
sudo apt-get install -y jq
- uses: actions/checkout@v4
with:
fetch-depth: 0
Expand All @@ -323,3 +330,4 @@ jobs:
target: ${{ matrix.arch }}
arch: ${{ matrix.arch }}
cniNetworkPlugin: ${{ matrix.cniNetworkPlugin }}
secureCircleCIToken: ${{ secrets.CIRCLECI_TOKEN }}

0 comments on commit c40f055

Please sign in to comment.