From 942e6efd244a8e6f338da8623972e8b757fbdd4a Mon Sep 17 00:00:00 2001 From: Antonin Bas Date: Mon, 9 Sep 2024 13:56:19 -0700 Subject: [PATCH] Clean up build workflow Signed-off-by: Antonin Bas --- .github/workflows/build.yml | 95 ++++++++++++++++----------------- .github/workflows/build_tag.yml | 2 +- 2 files changed, 48 insertions(+), 49 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e7eab6a9d70..007ca0a4619 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,24 +13,37 @@ on: - feature/* jobs: - check-changes: - name: Check whether tests need to be run based on diff - runs-on: [ubuntu-latest] + check-env: + name: Compute outputs for use by other jobs + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 show-progress: false - - uses: antrea-io/has-changes@v2 + - name: Check whether tests need to be run based on diff + uses: antrea-io/has-changes@v2 id: check_diff with: paths-ignore: docs/* ci/jenkins/* *.md hack/.notableofcontents + - name: Checking if image needs to be pushed + id: check_push + run: | + if [ "${{ github.repository }}" == "antrea-io/antrea" ] && [ "${{ github.event_name }}" == "push" ] && [ "${{ github.ref }}" == "refs/heads/main" ]; then + echo "push_needed=true" >> $GITHUB_OUTPUT + echo "docker_driver=docker-container" >> $GITHUB_OUTPUT + else + echo "push_needed=false" >> $GITHUB_OUTPUT + echo "docker_driver=docker" >> $GITHUB_OUTPUT + fi outputs: has_changes: ${{ steps.check_diff.outputs.has_changes }} + push_needed: ${{ steps.check_push.outputs.push_needed }} + docker_driver: ${{ steps.check_push.outputs.docker_driver }} build: - needs: check-changes - if: ${{ needs.check-changes.outputs.has_changes == 'yes' || github.event_name == 'push' }} + needs: check-env + if: ${{ needs.check-env.outputs.has_changes == 'yes' || github.event_name == 'push' }} strategy: matrix: include: @@ -50,25 +63,16 @@ jobs: - uses: actions/checkout@v4 with: show-progress: false - - name: Checking if image needs to be pushed - run: | - if [ "${{ github.repository }}" == "antrea-io/antrea" ] && [ "${{ github.event_name }}" == "push" ] && [ "${{ github.ref }}" == "refs/heads/main" ]; then - echo "push_needed=true" >> $GITHUB_ENV - echo "docker_driver=docker-container" >> $GITHUB_ENV - else - echo "push_needed=false" >> $GITHUB_ENV - echo "docker_driver=docker" >> $GITHUB_ENV - fi - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 with: - driver: ${{ env.docker_driver }} + driver: ${{ needs.check-env.outputs.docker_driver }} - name: Build Antrea Docker image without pushing to registry - if: ${{ env.push_needed == 'false' }} + if: ${{ needs.check-env.outputs.push_needed == 'false' }} run: | ./hack/build-antrea-linux-all.sh --platform ${{ matrix.platform }} --pull - name: Build and push Antrea Docker image to registry - if: ${{ env.push_needed == 'true' }} + if: ${{ needs.check-env.outputs.push_needed == 'true' }} env: DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} @@ -81,14 +85,16 @@ jobs: docker push antrea/antrea-agent-ubuntu-${{ matrix.suffix }}:"${DOCKER_TAG}" push-manifest: - needs: build - if: ${{ github.repository == 'antrea-io/antrea' && github.event_name == 'push' && github.ref == 'refs/heads/main' }} + needs: [check-env, build] + if: ${{ needs.check-env.outputs.push_needed == 'true' }} runs-on: ubuntu-latest env: DOCKER_TAG: latest steps: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + with: + driver: ${{ needs.check-env.outputs.docker_driver }} - name: Docker login env: DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} @@ -116,12 +122,14 @@ jobs: ref: refs/heads/main workflow: Test Antrea ARM images token: ${{ secrets.ANTREA_BUILD_INFRA_WORKFLOW_DISPATCH_PAT }} - inputs: ${{ format('{{ "antrea-repository":"antrea-io/antrea", "antrea-ref":"{0}", "docker-tag":"{1}" }}', github.ref, 'latest') }} + inputs: ${{ format('{{ "antrea-repository":"antrea-io/antrea", "antrea-ref":"{0}", "docker-tag":"{1}" }}', github.ref, env.DOCKER_TAG) }} build-ubi: - needs: check-changes - if: ${{ needs.check-changes.outputs.has_changes == 'yes' || github.event_name == 'push' }} - runs-on: [ubuntu-latest] + needs: check-env + if: ${{ needs.check-env.outputs.has_changes == 'yes' || github.event_name == 'push' }} + runs-on: ubuntu-latest + env: + DOCKER_TAG: latest steps: - name: Free disk space # https://github.com/actions/virtual-environments/issues/709 @@ -131,40 +139,31 @@ jobs: - uses: actions/checkout@v4 with: show-progress: false - - name: Checking if image needs to be pushed - run: | - if [ "${{ github.repository }}" == "antrea-io/antrea" ] && [ "${{ github.event_name }}" == "push" ] && [ "${{ github.ref }}" == "refs/heads/main" ]; then - echo "push_needed=true" >> $GITHUB_ENV - echo "docker_driver=docker-container" >> $GITHUB_ENV - else - echo "push_needed=false" >> $GITHUB_ENV - echo "docker_driver=docker" >> $GITHUB_ENV - fi - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 with: - driver: ${{ env.docker_driver }} + driver: ${{ needs.check-env.outputs.docker_driver }} - uses: actions/setup-go@v5 with: go-version-file: 'go.mod' - name: Build Antrea UBI9 Docker image without pushing to registry - if: ${{ env.push_needed == 'false' }} + if: ${{ needs.check-env.outputs.push_needed == 'false' }} run: | ./hack/build-antrea-linux-all.sh --pull --distro ubi - name: Build and push Antrea UBI9 Docker image to registry - if: ${{ env.push_needed == 'true' }} + if: ${{ needs.check-env.outputs.push_needed == 'true' }} env: DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} run: | echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin ./hack/build-antrea-linux-all.sh --pull --push-base-images --distro ubi - docker push antrea/antrea-agent-ubi:latest - docker push antrea/antrea-controller-ubi:latest + docker push antrea/antrea-agent-ubi:"${DOCKER_TAG}" + docker push antrea/antrea-controller-ubi:"${DOCKER_TAG}" build-scale: - needs: check-changes - if: ${{ needs.check-changes.outputs.has_changes == 'yes' || github.event_name == 'push' }} + needs: check-env + if: ${{ needs.check-env.outputs.has_changes == 'yes' || github.event_name == 'push' }} runs-on: [ubuntu-latest] steps: - uses: actions/checkout@v4 @@ -182,8 +181,8 @@ jobs: docker push antrea/antrea-ubuntu-simulator:latest build-windows: - needs: check-changes - if: ${{ needs.check-changes.outputs.has_changes == 'yes' || github.event_name == 'push' }} + needs: check-env + if: ${{ needs.check-env.outputs.has_changes == 'yes' || github.event_name == 'push' }} runs-on: [ubuntu-latest] steps: - uses: actions/checkout@v4 @@ -203,8 +202,8 @@ jobs: shell: bash build-antrea-mc-controller: - needs: check-changes - if: ${{ needs.check-changes.outputs.has_changes == 'yes' || github.event_name == 'push' }} + needs: check-env + if: ${{ needs.check-env.outputs.has_changes == 'yes' || github.event_name == 'push' }} runs-on: [ubuntu-latest] steps: - uses: actions/checkout@v4 @@ -222,8 +221,8 @@ jobs: docker push antrea/antrea-mc-controller:latest build-flow-aggregator: - needs: check-changes - if: ${{ needs.check-changes.outputs.has_changes == 'yes' || github.event_name == 'push' }} + needs: check-env + if: ${{ needs.check-env.outputs.has_changes == 'yes' || github.event_name == 'push' }} runs-on: [ubuntu-latest] steps: - uses: actions/checkout@v4 @@ -243,8 +242,8 @@ jobs: docker push antrea/flow-aggregator:latest build-antrea-migrator: - needs: check-changes - if: ${{ needs.check-changes.outputs.has_changes == 'yes' || github.event_name == 'push' }} + needs: check-env + if: ${{ needs.check-env.outputs.has_changes == 'yes' || github.event_name == 'push' }} runs-on: [ubuntu-latest] steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/build_tag.yml b/.github/workflows/build_tag.yml index 70ef61434ff..85c881c3357 100644 --- a/.github/workflows/build_tag.yml +++ b/.github/workflows/build_tag.yml @@ -91,7 +91,7 @@ jobs: ref: refs/heads/main workflow: Test Antrea ARM images token: ${{ secrets.ANTREA_BUILD_INFRA_WORKFLOW_DISPATCH_PAT }} - inputs: ${{ format('{{ "antrea-repository":"antrea-io/antrea", "antrea-ref":"{0}", "docker-tag":"{1}" }}', github.ref, needs.get-version.outputs.version) }} + inputs: ${{ format('{{ "antrea-repository":"antrea-io/antrea", "antrea-ref":"{0}", "docker-tag":"{1}" }}', github.ref, env.DOCKER_TAG) }} build-ubi: runs-on: [ubuntu-latest]