Nightly K8s Matrix #630
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: Nightly K8s Matrix | |
permissions: write-all | |
env: | |
CLUSTER_NAME: spider | |
E2E_TIME_OUT: 60m | |
PR_LABEL: pr/dependabot/github-actions, release/none | |
PR_REVIWER: weizhoublue, ty-dc | |
# The range of K8s versions that matrix tests expect to run. All distributions larger than it will be picked to run. | |
MINIMUM_K8S_VERSION: v1.21 | |
# TODO(ty-dc), refer: https://github.com/spidernet-io/spiderpool/issues/3937 | |
# Currently using kind/node v1.31, it is not possible to setup kind cluster | |
PENDING_K8S_VERSION: v1.31 | |
K8S_MATRIX_FILE_PATH: .github/workflows/auto-diff-k8s-ci.yaml | |
on: | |
schedule: | |
- cron: "0 20 * * *" | |
workflow_dispatch: | |
inputs: | |
ref: | |
description: 'sha, tag, branch' | |
required: true | |
default: main | |
k8s_version: | |
description: 'It should be the released version, for example: v1.25.2; if not set, the default version set will be run.' | |
required: false | |
type: string | |
e2e_enabled: | |
description: 'run e2e test' | |
required: false | |
type: choice | |
default: "false" | |
options: | |
- "true" | |
- "false" | |
e2e_labels: | |
description: 'e2e labels(if not set, ginkgo will run all test, multi labels separated by commas)' | |
required: false | |
type: string | |
jobs: | |
get_ref: | |
runs-on: ubuntu-latest | |
outputs: | |
ref: ${{ env.RUN_REF }} | |
run_push: ${{ env.RUN_PUSH }} | |
e2e_enabled: ${{ env.RUN_E2E_ENABLED }} | |
inputs_k8s_version: ${{ env.INPUTS_K8S_VERSION }} | |
default_k8s_version: ${{ env.DEFAULT_K8S_VERSION }} | |
steps: | |
- name: Get Ref | |
id: get_ref | |
run: | | |
if ${{ github.event_name == 'workflow_dispatch' }} ; then | |
echo "call by self workflow_dispatch" | |
echo "RUN_TAG=${{ github.event.inputs.ref }}" >> $GITHUB_ENV | |
if ${{ github.event.inputs.k8s_version == '' }}; then | |
echo "INPUTS_K8S_VERSION=false" >> $GITHUB_ENV | |
echo "DEFAULT_K8S_VERSION=true" >> $GITHUB_ENV | |
else | |
echo "A custom version of k8s will be run: ${{ github.event.inputs.k8s_version }} " | |
echo "INPUTS_K8S_VERSION=true" >> $GITHUB_ENV | |
echo "DEFAULT_K8S_VERSION=false" >> $GITHUB_ENV | |
fi | |
if ${{ github.event.inputs.e2e_enabled == 'true' }}; then | |
echo "RUN_E2E_ENABLED=true" >> $GITHUB_ENV | |
else | |
echo "RUN_E2E_ENABLED=false" >> $GITHUB_ENV | |
fi | |
else | |
# schedule event | |
# use main sha for ci image tag | |
echo "trigger by schedule" | |
echo "RUN_TAG=main" >> $GITHUB_ENV | |
echo "RUN_PUSH=false" >> $GITHUB_ENV | |
echo "RUN_E2E_ENABLED=true" >> $GITHUB_ENV | |
echo "INPUTS_K8S_VERSION=false" >> $GITHUB_ENV | |
echo "DEFAULT_K8S_VERSION=true" >> $GITHUB_ENV | |
fi | |
# some event, the tag is not sha, so checkout it and get sha | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
persist-credentials: false | |
ref: ${{ env.RUN_TAG }} | |
- name: Result Ref | |
id: result | |
run: | | |
ref=$( git show -s --format='format:%H') | |
echo "RUN_REF=${ref}" >> $GITHUB_ENV | |
call_build_ci_image: | |
needs: [get_ref] | |
uses: ./.github/workflows/build-image-ci.yaml | |
with: | |
ref: ${{ needs.get_ref.outputs.ref }} | |
push: false | |
secrets: inherit | |
lint_chart_against_release_image: | |
needs: get_ref | |
uses: ./.github/workflows/call-lint-chart.yaml | |
with: | |
ref: ${{ needs.get_ref.outputs.ref }} | |
secrets: inherit | |
call_release_chart: | |
needs: [get_ref] | |
uses: ./.github/workflows/call-release-chart.yaml | |
with: | |
ref: ${{ needs.get_ref.outputs.ref }} | |
submit: false | |
secrets: inherit | |
# update k8s matrix in step "call_k8s_matrix" | |
update_k8s_matrix: | |
needs: [get_ref] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
ref: ${{ needs.get_ref.outputs.ref }} | |
- name: get latest kind node version | |
run: | | |
bash ./test/scripts/update-kindnode-version.sh ${{ env.MINIMUM_K8S_VERSION }} ${{ env.K8S_MATRIX_FILE_PATH }} | |
if [ $? -ne 0 ]; then | |
echo "./test/scripts/update-kindnode-version.sh script failed" | |
echo "SKIP_CREATE_PR=true" >> $GITHUB_ENV | |
exit 0 | |
fi | |
git_status=$(git status --porcelain) | |
echo "git status: ${git_status}" | |
if [[ -n "$git_status" ]]; then | |
git_diff_version=$(git diff ${{ env.K8S_MATRIX_FILE_PATH }} | grep ${{ env.PENDING_K8S_VERSION }}) | |
# Avoid submitting PRs every day after checking for changes. | |
if [[ -n "$git_diff_version" ]]; then | |
echo "SKIP_CREATE_PR=true" >> $GITHUB_ENV | |
echo "The .github/workflows/auto-diff-k8s-ci.yaml of Spiderpool has changed." | |
else | |
echo "SKIP_CREATE_PR=false" >> $GITHUB_ENV | |
echo "The .github/workflows/auto-diff-k8s-ci.yaml of Spiderpool has changed." | |
fi | |
else | |
echo "The .github/workflows/auto-diff-k8s-ci.yaml of Spiderpool has not changed." | |
echo "SKIP_CREATE_PR=true" >> $GITHUB_ENV | |
fi | |
- uses: crazy-max/ghaction-import-gpg@v6 | |
if: ${{ env.SKIP_CREATE_PR != 'true' }} | |
with: | |
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} | |
passphrase: ${{ secrets.GPG_PASSPHRASE }} | |
git_user_signingkey: true | |
git_commit_gpgsign: true | |
# Allow auto-merge on general | |
- name: Create Pull Request | |
if: ${{ env.SKIP_CREATE_PR != 'true' }} | |
id: create_pr | |
uses: peter-evans/[email protected] | |
with: | |
title: "robot updates kind node version in k8s matrix test" | |
commit-message: "robot updates kind node version in k8s matrix test" | |
branch-suffix: timestamp | |
committer: ty-dc <[email protected]> | |
branch: robot/update_doc | |
delete-branch: true | |
signoff: true | |
base: main | |
token: ${{ secrets.WELAN_PAT }} | |
labels: ${{ env.PR_LABEL }} | |
reviewers: ${{ env.PR_REVIWER }} | |
call_k8s_matrix: | |
# k8s versions | |
strategy: | |
fail-fast: false | |
matrix: | |
# Synchronise with the latest releases of each version | |
# If a new version of kind/node is released, it will be updated automatically. | |
version: [v1.28.13, v1.29.8, v1.30.4, v1.27.16, v1.26.15, v1.25.16, v1.23.17, v1.24.17, v1.22.17] | |
needs: [call_build_ci_image, get_ref, call_release_chart] | |
uses: ./.github/workflows/e2e-init.yaml | |
with: | |
ip_family: dual | |
image_tag: ${{ needs.call_build_ci_image.outputs.imageTag }} | |
ref: ${{ needs.get_ref.outputs.ref }} | |
k8s_version: ${{ matrix.version }} | |
run_e2e: ${{ needs.get_ref.outputs.e2e_enabled }} | |
e2e_labels: ${{ inputs.e2e_labels }} | |
secrets: inherit | |
creat_issue: | |
runs-on: ubuntu-latest | |
needs: [call_k8s_matrix, lint_chart_against_release_image] | |
if: ${{ always() && needs.call_k8s_matrix.result == 'failure' || needs.lint_chart_against_release_image.result == 'failure' }} | |
steps: | |
- name: echo | |
run: | | |
echo ${{ github.repository }} | |
echo ${{ github.repository_owner }} | |
echo "TIMESTAMP=`date +%Y-%m-%d`" >> $GITHUB_ENV | |
- name: create an issue | |
uses: dacbd/[email protected] | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
title: "Nightly K8s Matrix CI ${{ ENV.TIMESTAMP }}: Failed" | |
body: | | |
action url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
labels: "kind/ci-bug" | |
assignees: "ty-dc" | |
call_inputs_k8s: | |
# workflow_dispatch event flow triggered by running the input k8s version | |
needs: [call_build_ci_image, get_ref, call_release_chart] | |
if: ${{ needs.get_ref.outputs.default_k8s_version == 'false' && needs.get_ref.outputs.inputs_k8s_version == 'true' }} | |
uses: ./.github/workflows/e2e-init.yaml | |
with: | |
ip_family: dual | |
image_tag: ${{ needs.call_build_ci_image.outputs.imageTag }} | |
ref: ${{ needs.get_ref.outputs.ref }} | |
k8s_version: ${{ inputs.k8s_version }} | |
run_e2e: ${{ needs.get_ref.outputs.e2e_enabled }} | |
e2e_labels: ${{ inputs.e2e_labels }} | |
secrets: inherit |