Skip to content

Commit

Permalink
Clean up build workflow
Browse files Browse the repository at this point in the history
Signed-off-by: Antonin Bas <antonin.bas@broadcom.com>
  • Loading branch information
antoninbas committed Sep 9, 2024
1 parent cf9292d commit 942e6ef
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 49 deletions.
95 changes: 47 additions & 48 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 }}
Expand All @@ -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 }}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 942e6ef

Please sign in to comment.