From ad3d55102060a9c2be8d2bc3e25b7362a3205a59 Mon Sep 17 00:00:00 2001 From: Hang Date: Mon, 21 Oct 2024 17:03:52 +0800 Subject: [PATCH] test --- .github/actions/setup-build-env/action.yml | 1 + .github/workflows/push-release.yml | 147 ++++++++++-------- .github/workflows/unit-test.yml | 9 +- .github/workflows/validate.yml | 12 ++ .../verify-generated-code-changes.yml | 11 +- scripts/export-config | 4 + scripts/validate | 2 +- .../steve/vai/secret_sort_test_cases.go | 5 +- tests/v2/validation/steve/vai/vai.go | 5 +- 9 files changed, 124 insertions(+), 72 deletions(-) diff --git a/.github/actions/setup-build-env/action.yml b/.github/actions/setup-build-env/action.yml index 4197780eea2..43d98f355a6 100644 --- a/.github/actions/setup-build-env/action.yml +++ b/.github/actions/setup-build-env/action.yml @@ -34,6 +34,7 @@ runs: - id: vars shell: bash run: | + ls -l source scripts/export-config CATTLE_KDM_BRANCH=$(grep -m1 'ARG CATTLE_KDM_BRANCH=' package/Dockerfile | cut -d '=' -f2) CATTLE_K3S_VERSION=$(grep -m1 'ENV CATTLE_K3S_VERSION' package/Dockerfile | awk '{print $3}') diff --git a/.github/workflows/push-release.yml b/.github/workflows/push-release.yml index 7c4696129cd..1d8e71a5ec1 100644 --- a/.github/workflows/push-release.yml +++ b/.github/workflows/push-release.yml @@ -2,8 +2,7 @@ name: build-docker-images on: push: branches: - - "master" - - "release/v*" + - "!release/v2.9-gha-test" tags: - "v*" env: @@ -13,11 +12,22 @@ env: IMAGE_AGENT: ${{ github.repository_owner }}/rancher-agent IMAGE_INSTALLER: ${{ github.repository_owner }}/system-agent-installer-rancher jobs: - unit-tests: - uses: ./.github/workflows/unit-test.yml + # unit-tests: + # uses: ./.github/workflows/unit-test.yml build-chart: - runs-on: ubuntu-latest + if: false + runs-on: test-runner-1 + container: ubuntu:22.04 steps: + - name: Install tools + run: | + export TZ=Asia/Kolkata + export DEBIAN_FRONTEND=noninteractive + apt update && apt install -y --no-install-recommends curl git-all sudo + curl -sLf https://github.com/mikefarah/yq/releases/download/v4.40.2/yq_linux_amd64.tar.gz -o yq_linux_amd64.tar.gz + tar zxvf yq_linux_amd64.tar.gz + mv yq_linux_amd64 /usr/bin/yq + git config --global --add safe.directory '*' - name: Checkout code uses: actions/checkout@v4 - name: Setup Tag Env Variables @@ -30,7 +40,7 @@ jobs: HELM_URL: https://get.helm.sh/helm-${{ steps.env.outputs.HELM_VERSION }}-linux-amd64.tar.gz HELM_UNITTEST_VERSION: ${{ steps.env.outputs.HELM_UNITTEST_VERSION }} run: | - sudo snap install yq + # sudo snap install yq curl ${{ env.HELM_URL }} | tar xvzf - --strip-components=1 -C /tmp/ && \ sudo mv /tmp/helm /usr/bin/helm_v3 && \ sudo chmod +x /usr/bin/helm_v3 @@ -52,7 +62,7 @@ jobs: retention-days: 1 overwrite: true publish-chart: - runs-on: ubuntu-latest + runs-on: test-runner-1 needs: [build-chart, push-images] if: github.event_name == 'push' && contains(github.ref, 'tags/') # Only run on push permissions: @@ -84,12 +94,22 @@ jobs: headers: |- cache-control: public,no-cache,proxy-revalidate build-server: - runs-on: ubuntu-latest + # container: summerwind/actions-runner-dind:ubuntu-22.04 + runs-on: test-runner-dind strategy: matrix: os: [linux] - arch: [amd64, arm64] + arch: [amd64] steps: + - name: Install tools + run: | + export TZ=Asia/Kolkata + export DEBIAN_FRONTEND=noninteractive + sudo apt update && sudo apt install -y --no-install-recommends curl git-all + sudo curl -sLf https://github.com/mikefarah/yq/releases/download/v4.40.2/yq_linux_amd64.tar.gz -o yq_linux_amd64.tar.gz + sudo tar zxvf yq_linux_amd64.tar.gz + sudo mv yq_linux_amd64 /usr/bin/yq + git config --global --add safe.directory '*' - name: Checkout code uses: actions/checkout@v4 # Cleaning the runner is important to free enough space to build rancher, otherwise the build will fail @@ -152,7 +172,7 @@ jobs: overwrite: false build-agent: needs: [build-server] - runs-on: ubuntu-latest + runs-on: test-runner-1 strategy: matrix: os: [linux] @@ -236,45 +256,46 @@ jobs: if-no-files-found: error retention-days: 1 overwrite: false - integration-tests: - needs: [build-agent] - uses: ./.github/workflows/integration-tests.yml - with: - parent_run_id: ${{ github.run_id }} - build-agent-windows: - needs: [integration-tests] - strategy: - matrix: - os: [windows] - version: [2019, 2022] - runs-on: ${{ matrix.os }}-${{ matrix.version }} - permissions: - contents: read - id-token: write - steps: - - name: Checkout code - uses: actions/checkout@v4 - - name: Setup Environment Variables - uses: ./.github/actions/setup-tag-env - - name: Load Secrets from Vault - uses: rancher-eio/read-vault-secrets@main - with: - secrets: | - secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials username | DOCKER_USERNAME ; - secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials password | DOCKER_PASSWORD - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ env.DOCKER_USERNAME }} - password: ${{ env.DOCKER_PASSWORD }} - - name: Build Windows Server Image - run: | - docker build -t ${{ env.IMAGE_AGENT }}:${{ env.TAG }}-windows-${{ matrix.version }} --build-arg VERSION=${{ env.TAG }} --build-arg SERVERCORE_VERSION=ltsc${{ matrix.version }} -f package/windows/Dockerfile.agent . - docker push ${{ env.IMAGE_AGENT }}:${{ env.TAG }}-windows-${{ matrix.version }} - shell: bash + # integration-tests: + # needs: [build-agent] + # uses: ./.github/workflows/integration-tests.yml + # with: + # parent_run_id: ${{ github.run_id }} + # build-agent-windows: + # needs: [integration-tests] + # strategy: + # matrix: + # os: [windows] + # version: [2019, 2022] + # runs-on: ${{ matrix.os }}-${{ matrix.version }} + # permissions: + # contents: read + # id-token: write + # steps: + # - name: Checkout code + # uses: actions/checkout@v4 + # - name: Setup Environment Variables + # uses: ./.github/actions/setup-tag-env + # - name: Load Secrets from Vault + # uses: rancher-eio/read-vault-secrets@main + # with: + # secrets: | + # secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials username | DOCKER_USERNAME ; + # secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials password | DOCKER_PASSWORD + # - name: Login to Docker Hub + # uses: docker/login-action@v3 + # with: + # username: ${{ env.DOCKER_USERNAME }} + # password: ${{ env.DOCKER_PASSWORD }} + # - name: Build Windows Server Image + # run: | + # docker build -t ${{ env.IMAGE_AGENT }}:${{ env.TAG }}-windows-${{ matrix.version }} --build-arg VERSION=${{ env.TAG }} --build-arg SERVERCORE_VERSION=ltsc${{ matrix.version }} -f package/windows/Dockerfile.agent . + # docker push ${{ env.IMAGE_AGENT }}:${{ env.TAG }}-windows-${{ matrix.version }} + # shell: bash push-images: - runs-on: ubuntu-latest - needs: [unit-tests, integration-tests] + runs-on: test-runner-1 + # needs: [unit-tests] + if: false permissions: contents: read id-token: write @@ -323,7 +344,7 @@ jobs: docker tag "$image_agent_id" docker.io/${{ env.IMAGE_AGENT }}:${{ env.TAG }}-${{ matrix.arch }} docker push docker.io/${{ env.IMAGE_AGENT }}:${{ env.TAG }}-${{ matrix.arch }} merge-server-manifest: - runs-on: ubuntu-latest + runs-on: test-runner-1 needs: [push-images] permissions: contents: read @@ -358,8 +379,8 @@ jobs: run: | docker buildx imagetools inspect ${{ env.IMAGE }}:${{ env.TAG }} merge-agent-manifest: - runs-on: ubuntu-latest - needs: [push-images, build-agent-windows] + runs-on: test-runner-1 + needs: [push-images] permissions: contents: read id-token: write @@ -384,21 +405,21 @@ jobs: - name: Create manifest list and push run: | # docker manifest is used with windows images to maintain os.version in the manifest - docker manifest create ${{ env.IMAGE_AGENT }}:${{ env.TAG }} \ - ${{ env.IMAGE_AGENT }}:${{ env.TAG }}-windows-2019 \ - ${{ env.IMAGE_AGENT }}:${{ env.TAG }}-windows-2022 + # docker manifest create ${{ env.IMAGE_AGENT }}:${{ env.TAG }} \ + # ${{ env.IMAGE_AGENT }}:${{ env.TAG }}-windows-2019 \ + # ${{ env.IMAGE_AGENT }}:${{ env.TAG }}-windows-2022 - docker manifest push ${{ env.IMAGE_AGENT }}:${{ env.TAG }} + # docker manifest push ${{ env.IMAGE_AGENT }}:${{ env.TAG }} docker buildx imagetools create -t ${{ env.IMAGE_AGENT }}:${{ env.TAG }} \ --append ${{ env.IMAGE_AGENT }}:${{ env.TAG }}-amd64 \ --append ${{ env.IMAGE_AGENT }}:${{ env.TAG }}-arm64 if [[ "${{ github.ref_name }}" == release/v* ]]; then - docker manifest create ${{ env.IMAGE_AGENT }}:${{ env.HEAD_TAG }} \ - ${{ env.IMAGE_AGENT }}:${{ env.TAG }}-windows-2019 \ - ${{ env.IMAGE_AGENT }}:${{ env.TAG }}-windows-2022 - docker manifest push ${{ env.IMAGE_AGENT }}:${{ env.HEAD_TAG }} + # docker manifest create ${{ env.IMAGE_AGENT }}:${{ env.HEAD_TAG }} \ + # ${{ env.IMAGE_AGENT }}:${{ env.TAG }}-windows-2019 \ + # ${{ env.IMAGE_AGENT }}:${{ env.TAG }}-windows-2022 + # docker manifest push ${{ env.IMAGE_AGENT }}:${{ env.HEAD_TAG }} docker buildx imagetools create -t ${{ env.IMAGE_AGENT }}:${{ env.HEAD_TAG }} \ --append ${{ env.IMAGE_AGENT }}:${{ env.TAG }}-amd64 \ @@ -411,7 +432,7 @@ jobs: needs: - merge-server-manifest - build-chart - runs-on: ubuntu-latest + runs-on: test-runner-1 strategy: matrix: os: [linux] @@ -470,7 +491,7 @@ jobs: file: ./package/Dockerfile.installer labels: "${{ steps.meta.outputs.labels }}" merge-installer-manifest: - runs-on: ubuntu-latest + runs-on: test-runner-1 needs: [build-installer] permissions: contents: read @@ -511,7 +532,7 @@ jobs: docker buildx imagetools inspect ${{ env.IMAGE_INSTALLER }}:${{ env.TAG }} create-images-files: if: github.event_name == 'push' && contains(github.ref, 'tags/') # Only run on push - runs-on: ubuntu-latest + runs-on: test-runner-1 steps: - name: Checkout code uses: actions/checkout@v4 @@ -545,7 +566,7 @@ jobs: run: gh release upload -R ${{ env.REPOSITORY_OWNER }}/rancher ${{ env.TAG }} ./dist/* --clobber docker-image-digests: if: github.event_name == 'push' && contains(github.ref, 'tags/') # Only run on tag - runs-on: ubuntu-latest + runs-on: test-runner-1 needs: [create-images-files] env: DOCKER_REGISTRY: "docker.io" diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index a1949daeb07..42a9a983fa3 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -2,12 +2,17 @@ name: Unit Tests on: [workflow_dispatch, workflow_call] jobs: unit-test: - runs-on: ubuntu-latest + env: + GOLANG_VERSION: '1.22' + runs-on: test-runner-1 timeout-minutes: 60 steps: - name: Checkout code uses: actions/checkout@v4 - + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: "${{ env.GOLANG_VERSION }}" - name: Run unit tests run: go test -cover -tags=test ./pkg/... diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 158ea24f265..b6239795111 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -2,12 +2,20 @@ name: Validate on: [pull_request, push] jobs: validate: + if: false runs-on: test-runner-1 + container: ubuntu:22.04 env: GOLANG_CI_LINT_VERSION: v1.54.2 PYTHON_VERSION: '3.11' GOLANG_VERSION: '1.22' steps: + - name: Install tools + run: | + export TZ=Asia/Kolkata + export DEBIAN_FRONTEND=noninteractive + apt update && apt install -y --no-install-recommends unzip curl sudo ca-certificates git-all + git config --global --add safe.directory '/__w/rancher/rancher' - name: Checkout code uses: actions/checkout@v4 - name: Uninstall existing Python versions @@ -30,6 +38,10 @@ jobs: uses: actions/setup-go@v5 with: go-version: "${{ env.GOLANG_VERSION }}" + - name: Install golangci-lint + run: | + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin "v1.59.0" + curl -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/fossas/spectrometer/master/install.sh | sh - name: Install Python and dependencies run: | sudo apt-get update diff --git a/.github/workflows/verify-generated-code-changes.yml b/.github/workflows/verify-generated-code-changes.yml index 45d7afbacde..67841196251 100644 --- a/.github/workflows/verify-generated-code-changes.yml +++ b/.github/workflows/verify-generated-code-changes.yml @@ -15,9 +15,16 @@ env: jobs: check-changes: - runs-on: ubuntu-latest - + if: false + runs-on: test-runner-1 + container: ubuntu:22.04 steps: + - name: Install tools + run: | + export TZ=Asia/Kolkata + export DEBIAN_FRONTEND=noninteractive + apt update && apt install -y --no-install-recommends curl sudo ca-certificates git-all + git config --global --add safe.directory '/__w/rancher/rancher' - uses: actions/checkout@v3 with: diff --git a/scripts/export-config b/scripts/export-config index 3686650baec..239dcb0e7da 100755 --- a/scripts/export-config +++ b/scripts/export-config @@ -6,8 +6,12 @@ if [ -n "$DEBUG" ]; then set -x fi +echo "before git" + file="$(git rev-parse --show-toplevel)/build.yaml" +echo "after git" + CATTLE_RANCHER_WEBHOOK_VERSION=$(yq -e '.webhookVersion' "$file") CATTLE_RANCHER_PROVISIONING_CAPI_VERSION=$(yq -e '.provisioningCAPIVersion' "$file") CATTLE_CSP_ADAPTER_MIN_VERSION=$(yq -e '.cspAdapterMinVersion' "$file") diff --git a/scripts/validate b/scripts/validate index abea2e8b51f..d673b29720e 100755 --- a/scripts/validate +++ b/scripts/validate @@ -14,7 +14,7 @@ if ! command -v golangci-lint; then fi echo Running: golangci-lint -golangci-lint run +golangci-lint run --timeout=20m echo Tidying up modules cd pkg/apis/ diff --git a/tests/v2/validation/steve/vai/secret_sort_test_cases.go b/tests/v2/validation/steve/vai/secret_sort_test_cases.go index 3134f333279..b08adeea5c8 100644 --- a/tests/v2/validation/steve/vai/secret_sort_test_cases.go +++ b/tests/v2/validation/steve/vai/secret_sort_test_cases.go @@ -2,12 +2,13 @@ package vai import ( "fmt" - namegen "github.com/rancher/shepherd/pkg/namegenerator" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "net/url" "sort" "strings" + namegen "github.com/rancher/shepherd/pkg/namegenerator" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + v1 "k8s.io/api/core/v1" ) diff --git a/tests/v2/validation/steve/vai/vai.go b/tests/v2/validation/steve/vai/vai.go index 735308c2c6c..ef27399a83a 100644 --- a/tests/v2/validation/steve/vai/vai.go +++ b/tests/v2/validation/steve/vai/vai.go @@ -2,10 +2,11 @@ package vai import ( "fmt" - "github.com/rancher/shepherd/clients/rancher" - "github.com/rancher/shepherd/extensions/vai" "strings" "sync" + + "github.com/rancher/shepherd/clients/rancher" + "github.com/rancher/shepherd/extensions/vai" ) const (