From 9554adfb5df3c2250ca62bfd19cf051364de2464 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=A5=96=E5=BB=BA?= Date: Mon, 20 Feb 2023 11:04:42 +0800 Subject: [PATCH] simplify github actions workflows (#2338) --- .github/workflows/build-arm64-image.yaml | 12 +-- .github/workflows/build-dpdk-image.yaml | 2 +- .github/workflows/build-windows.yaml | 52 +++++++++- .github/workflows/build-x86-image.yaml | 123 ++++++++++------------- .github/workflows/lint.yaml | 6 +- 5 files changed, 106 insertions(+), 89 deletions(-) diff --git a/.github/workflows/build-arm64-image.yaml b/.github/workflows/build-arm64-image.yaml index decb13ae6a8..98e925d6eed 100644 --- a/.github/workflows/build-arm64-image.yaml +++ b/.github/workflows/build-arm64-image.yaml @@ -19,9 +19,6 @@ concurrency: group: "${{ github.workflow }}-${{ github.ref }}" cancel-in-progress: true -env: - GO_VERSION: '1.19' - jobs: build: name: Build arm64 @@ -30,9 +27,8 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: '${{ env.GO_VERSION }}' + go-version-file: go.mod check-latest: true - id: go - name: Set up QEMU uses: docker/setup-qemu-action@v2 @@ -55,10 +51,10 @@ jobs: restore-keys: ${{ runner.os }}-${{ env.GO_FULL_VER }}-arm64- - name: Build - run: | - make release-arm || make release-arm + run: make release-arm || make release-arm + - name: Push - if: ${{ github.ref == 'refs/heads/master' || contains(github.ref, 'release') }} + if: github.ref == github.event.repository.default_branch || startsWith(github.ref, 'release-') env: DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} diff --git a/.github/workflows/build-dpdk-image.yaml b/.github/workflows/build-dpdk-image.yaml index bcdc6affdc1..92427bf3787 100644 --- a/.github/workflows/build-dpdk-image.yaml +++ b/.github/workflows/build-dpdk-image.yaml @@ -16,7 +16,7 @@ jobs: run: | make build-dpdk - name: Push - if: ${{ github.ref == 'refs/heads/master' || contains(github.ref, 'release') }} + if: github.ref == github.event.repository.default_branch || startsWith(github.ref, 'release-') env: DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} diff --git a/.github/workflows/build-windows.yaml b/.github/workflows/build-windows.yaml index b4485493156..dbac66b844c 100644 --- a/.github/workflows/build-windows.yaml +++ b/.github/workflows/build-windows.yaml @@ -1,6 +1,8 @@ name: Build Windows on: + workflow_dispatch: + release: pull_request: branches: - master @@ -21,13 +23,52 @@ concurrency: cancel-in-progress: true env: - GO_VERSION: '1.19' GOSEC_VERSION: '2.14.0' jobs: + filter: + name: Path Filter + runs-on: ubuntu-22.04 + outputs: + build-ovs-ovn: ${{ steps.filter.outputs.windows-ovs-ovn }} + build-kube-ovn: ${{ steps.filter.outputs.windows-kube-ovn }} + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version-file: go.mod + check-latest: true + + - name: Generate path filter + env: + GOOS: windows + run: | + filter=".github/path-filters.yaml" + workflow=$(echo ${{ github.workflow_ref }} | awk -F@ '{print $1}' | sed 's@^${{ github.repository }}/@@') + cat > $filter <> $filter + done + + - uses: dorny/paths-filter@v2 + id: filter + with: + filters: .github/path-filters.yaml + build-ovs-and-ovn: name: Build OVS and OVN + needs: + - filter runs-on: windows-2019 + if: github.event_name != 'pull_request' || needs.filter.outputs.build-ovs-ovn == 'true' steps: - name: Check out PTHREADS4W run: | @@ -131,14 +172,16 @@ jobs: build-kube-ovn: name: Build Kube-OVN + needs: + - filter runs-on: windows-2019 + if: github.event_name != 'pull_request' || needs.filter.outputs.build-kube-ovn == 'true' steps: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: '${{ env.GO_VERSION }}' + go-version-file: go.mod check-latest: true - id: go - name: Export Go full version run: | @@ -153,8 +196,7 @@ jobs: ~\AppData\Local\go-build ~\go\pkg\mod key: ${{ runner.os }}-${{ env.GO_FULL_VER }}-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-${{ env.GO_FULL_VER }}- + restore-keys: ${{ runner.os }}-${{ env.GO_FULL_VER }}- - name: Install gosec run: | diff --git a/.github/workflows/build-x86-image.yaml b/.github/workflows/build-x86-image.yaml index f7cfed8ab14..535d13e6610 100644 --- a/.github/workflows/build-x86-image.yaml +++ b/.github/workflows/build-x86-image.yaml @@ -2,6 +2,11 @@ name: Build x86 Image on: pull_request: + types: + - opened + - synchronize + - reopened + - labeled branches: - master - release-* @@ -21,9 +26,7 @@ concurrency: cancel-in-progress: true env: - GO_VERSION: '1.19' GOSEC_VERSION: '2.14.0' - KIND_VERSION: v0.17.0 HELM_VERSION: v3.10.1 jobs: @@ -35,9 +38,8 @@ jobs: - uses: docker/setup-buildx-action@v2 - uses: actions/setup-go@v3 with: - go-version: '${{ env.GO_VERSION }}' + go-version-file: go.mod check-latest: true - id: go - name: Export Go full version run: echo "GO_FULL_VER=$(go version | awk '{print $3}')" >> "$GITHUB_ENV" @@ -159,9 +161,8 @@ jobs: - uses: actions/setup-go@v3 with: - go-version: '${{ env.GO_VERSION }}' + go-version-file: ${{ env.E2E_DIR }}/go.mod check-latest: true - id: go - name: Export Go full version run: echo "GO_FULL_VER=$(go version | awk '{print $3}')" >> "$GITHUB_ENV" @@ -180,10 +181,9 @@ jobs: run: make e2e-compile - name: Install kind - run: | - curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-$(uname)-amd64 - chmod +x ./kind - sudo mv kind /usr/local/bin + uses: helm/kind-action@v1 + with: + install_only: true - name: Download image uses: actions/download-artifact@v3 @@ -214,6 +214,7 @@ jobs: k8s-netpol-e2e: name: Kubernetes Network Policy E2E + if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'network policy') needs: build-kube-ovn runs-on: ubuntu-22.04 timeout-minutes: 60 @@ -252,9 +253,8 @@ jobs: - uses: actions/setup-go@v3 with: - go-version: '${{ env.GO_VERSION }}' + go-version-file: ${{ env.E2E_DIR }}/go.mod check-latest: true - id: go - name: Export Go full version run: echo "GO_FULL_VER=$(go version | awk '{print $3}')" >> "$GITHUB_ENV" @@ -273,10 +273,9 @@ jobs: run: make e2e-compile - name: Install kind - run: | - curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-$(uname)-amd64 - chmod +x ./kind - sudo mv kind /usr/local/bin + uses: helm/kind-action@v1 + with: + install_only: true - name: Download image uses: actions/download-artifact@v3 @@ -303,6 +302,7 @@ jobs: cyclonus-netpol-e2e: name: Cyclonus Network Policy E2E + if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'network policy') needs: build-kube-ovn runs-on: ubuntu-22.04 timeout-minutes: 30 @@ -335,10 +335,9 @@ jobs: fi - name: Install kind - run: | - curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-$(uname)-amd64 - chmod +x ./kind - sudo mv kind /usr/local/bin + uses: helm/kind-action@v1 + with: + install_only: true - name: Download image uses: actions/download-artifact@v3 @@ -375,9 +374,6 @@ jobs: - ipv4 - ipv6 - dual - mode: - - overlay - - underlay steps: - uses: actions/checkout@v3 @@ -401,9 +397,8 @@ jobs: - uses: actions/setup-go@v3 with: - go-version: '${{ env.GO_VERSION }}' + go-version-file: ${{ env.E2E_DIR }}/go.mod check-latest: true - id: go - name: Export Go full version run: echo "GO_FULL_VER=$(go version | awk '{print $3}')" >> "$GITHUB_ENV" @@ -422,10 +417,9 @@ jobs: run: make e2e-compile - name: Install kind - run: | - curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-$(uname)-amd64 - chmod +x ./kind - sudo mv kind /usr/local/bin + uses: helm/kind-action@v1 + with: + install_only: true - name: Download image uses: actions/download-artifact@v3 @@ -444,14 +438,13 @@ jobs: sudo chown -R $(id -un). ~/.kube/ - name: Install Kube-OVN - run: make kind-install-${{ matrix.mode }}-${{ matrix.ip-family }} + run: make kind-install-${{ matrix.ip-family }} - name: Run E2E working-directory: ${{ env.E2E_DIR }} env: E2E_BRANCH: ${{ github.base_ref || github.ref_name }} E2E_IP_FAMILY: ${{ matrix.ip-family }} - E2E_NETWORK_MODE: ${{ matrix.mode }} run: make kube-ovn-conformance-e2e - name: Cleanup @@ -485,9 +478,8 @@ jobs: - uses: actions/setup-go@v3 with: - go-version: '${{ env.GO_VERSION }}' + go-version-file: ${{ env.E2E_DIR }}/go.mod check-latest: true - id: go - name: Go cache uses: actions/cache@v3 @@ -503,10 +495,9 @@ jobs: run: make e2e-compile - name: Install kind - run: | - curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-$(uname)-amd64 - chmod +x ./kind - sudo mv kind /usr/local/bin + uses: helm/kind-action@v1 + with: + install_only: true - name: Download image uses: actions/download-artifact@v3 @@ -540,10 +531,9 @@ jobs: - uses: actions/checkout@v3 - name: Install kind - run: | - curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-$(uname)-amd64 - chmod +x ./kind - sudo mv kind /usr/local/bin + uses: helm/kind-action@v1 + with: + install_only: true - name: Download image uses: actions/download-artifact@v3 @@ -576,10 +566,9 @@ jobs: - uses: actions/checkout@v3 - name: Install kind - run: | - curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-$(uname)-amd64 - chmod +x ./kind - sudo mv kind /usr/local/bin + uses: helm/kind-action@v1 + with: + install_only: true - name: Download image uses: actions/download-artifact@v3 @@ -612,10 +601,9 @@ jobs: - uses: actions/checkout@v3 - name: Install kind - run: | - curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-$(uname)-amd64 - chmod +x ./kind - sudo mv kind /usr/local/bin + uses: helm/kind-action@v1 + with: + install_only: true - name: Download image uses: actions/download-artifact@v3 @@ -650,10 +638,9 @@ jobs: - uses: actions/checkout@v3 - name: Install kind - run: | - curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-$(uname)-amd64 - chmod +x ./kind - sudo mv kind /usr/local/bin + uses: helm/kind-action@v1 + with: + install_only: true - name: Download image uses: actions/download-artifact@v3 @@ -688,10 +675,9 @@ jobs: - uses: actions/checkout@v3 - name: Install kind - run: | - curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-$(uname)-amd64 - chmod +x ./kind - sudo mv kind /usr/local/bin + uses: helm/kind-action@v1 + with: + install_only: true - name: Download image uses: actions/download-artifact@v3 @@ -751,9 +737,8 @@ jobs: - uses: actions/setup-go@v3 with: - go-version: '${{ env.GO_VERSION }}' + go-version-file: ${{ env.E2E_DIR }}/go.mod check-latest: true - id: go - name: Export Go full version run: echo "GO_FULL_VER=$(go version | awk '{print $3}')" >> "$GITHUB_ENV" @@ -772,10 +757,9 @@ jobs: run: make e2e-compile - name: Install kind - run: | - curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-$(uname)-amd64 - chmod +x ./kind - sudo mv kind /usr/local/bin + uses: helm/kind-action@v1 + with: + install_only: true - name: Download image uses: actions/download-artifact@v3 @@ -844,9 +828,8 @@ jobs: - uses: actions/setup-go@v3 with: - go-version: '${{ env.GO_VERSION }}' + go-version-file: ${{ env.E2E_DIR }}/go.mod check-latest: true - id: go - name: Export Go full version run: echo "GO_FULL_VER=$(go version | awk '{print $3}')" >> "$GITHUB_ENV" @@ -865,10 +848,9 @@ jobs: run: make e2e-compile - name: Install kind - run: | - curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-$(uname)-amd64 - chmod +x ./kind - sudo mv kind /usr/local/bin + uses: helm/kind-action@v1 + with: + install_only: true - name: Download image uses: actions/download-artifact@v3 @@ -917,6 +899,7 @@ jobs: - no-np-test - cilium-chaining-e2e - kube-ovn-security-e2e + if: always() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 @@ -958,7 +941,7 @@ jobs: make scan - name: Push - if: ${{ github.ref == 'refs/heads/master' || contains(github.ref, 'release') }} + if: github.ref_name == github.event.repository.default_branch || startsWith(github.ref_name, 'release-') env: DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index f8089572381..42c312db945 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -12,9 +12,6 @@ concurrency: group: "${{ github.workflow }}-${{ github.ref }}" cancel-in-progress: true -env: - GO_VERSION: '1.19' - jobs: golangci: name: lint @@ -23,9 +20,8 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: '${{ env.GO_VERSION }}' + go-version-file: go.mod check-latest: true - id: go - name: golangci-lint uses: golangci/golangci-lint-action@v3