From 768e1da0fe89c77110dbe556ef79db267710103b Mon Sep 17 00:00:00 2001 From: Viet Nguyen Duc Date: Sat, 20 Jul 2024 12:18:12 +0000 Subject: [PATCH] build: dynamic fetch upstream build Signed-off-by: Viet Nguyen Duc --- .circleci/config.yml | 2 + .../actions/get-latest-upstream/action.yml | 40 +++++++++++++++++++ .github/workflows/build-test.yml | 7 +++- .github/workflows/deploy.yml | 14 +++++-- .github/workflows/docker-test.yml | 12 +++--- .github/workflows/helm-chart-release.yml | 4 +- .github/workflows/helm-chart-test.yml | 12 +++--- .github/workflows/nightly.yml | 10 ++++- Makefile | 3 -- 9 files changed, 79 insertions(+), 25 deletions(-) create mode 100644 .github/actions/get-latest-upstream/action.yml diff --git a/.circleci/config.yml b/.circleci/config.yml index 9e5d3e90e..f06823cda 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -231,6 +231,7 @@ jobs: BUILD_DATE=${BUILD_DATE} TEST_EXISTING_KEDA=${TEST_EXISTING_KEDA} make chart_cluster_setup - run: name: "Build Docker images" + no_output_timeout: 30m command: | N=3 while [ $N -gt 0 ]; do @@ -254,6 +255,7 @@ jobs: source $BASH_ENV - run: name: "Test Selenium Grid on Kubernetes" + no_output_timeout: 30m command: | N=3 while [ $N -gt 0 ]; do diff --git a/.github/actions/get-latest-upstream/action.yml b/.github/actions/get-latest-upstream/action.yml new file mode 100644 index 000000000..7ed58233c --- /dev/null +++ b/.github/actions/get-latest-upstream/action.yml @@ -0,0 +1,40 @@ +name: Get Latest Upstream +description: Get the latest upstream release of Selenium +inputs: + release: + description: 'Test a new release process' + required: false + type: boolean + default: false + gh_cli_token: + description: 'GitHub CLI authentication token' + required: true + type: secret + +runs: + using: "composite" + steps: + - name: Get latest upstream + shell: bash + run: | + sudo apt update + sudo apt install gh + echo "${{ inputs.gh_cli_token }}" | gh auth login --with-token + if [ "${{ inputs.release }}" = "true" ]; then + echo "Getting the latest stable release." + RELEASE=$(gh release list -R SeleniumHQ/selenium | grep -v nightly | awk '{ print $4 }' | head -1) + else + echo "Getting the latest Nightly release." + RELEASE=$(gh release list -R SeleniumHQ/selenium | grep nightly | awk '{ print $3 }' | head -1) + if [ -z "${RELEASE}" ]; then + echo "Nightly release not found, getting the latest stable release." + RELEASE=$(gh release list -R SeleniumHQ/selenium | grep -v nightly | awk '{ print $4 }' | head -1) + fi + fi + jar_file=$(gh release view -R SeleniumHQ/selenium ${RELEASE} | grep jar | awk '{ print $2 }' | tail -n 1) + echo "Server package: ${jar_file}" + VERSION=$(echo $jar_file | sed 's/selenium-server-//;s/\.jar//') + echo "BASE_RELEASE=${RELEASE} | BASE_VERSION=${VERSION} | VERSION=${VERSION}" + echo "BASE_RELEASE=${RELEASE}" >> $GITHUB_ENV + echo "BASE_VERSION=${VERSION}" >> $GITHUB_ENV + echo "VERSION=${VERSION}" >> $GITHUB_ENV diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 73cf0685e..02a3852d8 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -6,8 +6,8 @@ on: release: description: 'Test a new release process' required: false - type: boolean - default: false + type: string + default: 'false' workflow_dispatch: inputs: rerunFailedOnly: @@ -32,16 +32,19 @@ env: jobs: docker-test: + name: Test Seleium Grid on Docker uses: ./.github/workflows/docker-test.yml with: release: ${{ inputs.release == 'true' }} helm-chart-test: + name: Test Selenium Grid on Kubernetes uses: ./.github/workflows/helm-chart-test.yml with: release: ${{ inputs.release == 'true' }} rerun-workflow-when-failure: + name: Rerun workflow when failure needs: - docker-test - helm-chart-test diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0e61520a2..cd2888874 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -6,8 +6,8 @@ on: release: description: 'Deploy a new release' required: false - type: boolean - default: false + type: string + default: 'true' skip-test: description: 'Skip the tests' required: false @@ -24,16 +24,17 @@ on: jobs: build-test: + name: Build and Test if: contains(toJson(github.event.commits), '[deploy]') == true || (github.event_name == 'workflow_dispatch' && github.event.inputs.skip-test == 'false') uses: ./.github/workflows/build-test.yml with: - release: ${{ github.event.inputs.release == 'true' }} + release: ${{ github.event.inputs.release || true }} deploy: needs: - build-test if: (contains(toJson(github.event.commits), '[deploy]') || (github.event_name == 'workflow_dispatch' && github.event.inputs.release == 'true')) && !failure() && !cancelled() - name: Deploy Docker images + name: Deploy and Release runs-on: ubuntu-latest permissions: write-all steps: @@ -57,6 +58,11 @@ jobs: make set_containerd_image_store - name: Output Docker info run: docker info + - name: Set Selenium base version + uses: ./.github/actions/get-latest-upstream + with: + release: ${{ github.event.inputs.release || true }} + gh_cli_token: ${{ secrets.GITHUB_TOKEN }} - name: Sets build date run: | echo "BUILD_DATE=$(date '+%Y%m%d')" >> $GITHUB_ENV diff --git a/.github/workflows/docker-test.yml b/.github/workflows/docker-test.yml index 5daf9c577..dab99b74e 100644 --- a/.github/workflows/docker-test.yml +++ b/.github/workflows/docker-test.yml @@ -6,8 +6,8 @@ on: release: description: 'Test a new release process' required: false - type: boolean - default: false + type: string + default: 'false' workflow_dispatch: inputs: request-timeout: @@ -100,10 +100,10 @@ jobs: - name: Output branch name run: echo ${BRANCH} - name: Set Selenium base version - if: inputs.release != 'true' - run: | - make set_build_nightly - cat .env | xargs -I {} echo {} >> $GITHUB_ENV + uses: ./.github/actions/get-latest-upstream + with: + release: ${{ inputs.release || false }} + gh_cli_token: ${{ secrets.GITHUB_TOKEN }} - name: Sets build date run: | echo "BUILD_DATE=$(date '+%Y%m%d')" >> $GITHUB_ENV diff --git a/.github/workflows/helm-chart-release.yml b/.github/workflows/helm-chart-release.yml index 3387191f8..68bc2b6d9 100644 --- a/.github/workflows/helm-chart-release.yml +++ b/.github/workflows/helm-chart-release.yml @@ -13,8 +13,8 @@ on: release: description: 'Deploy a new release' required: false - type: boolean - default: false + type: string + default: 'false' jobs: helm-chart-test: diff --git a/.github/workflows/helm-chart-test.yml b/.github/workflows/helm-chart-test.yml index 5d2ada608..7e02e2fda 100644 --- a/.github/workflows/helm-chart-test.yml +++ b/.github/workflows/helm-chart-test.yml @@ -6,8 +6,8 @@ on: release: description: 'Test a new release process' required: false - type: boolean - default: false + type: string + default: 'false' workflow_dispatch: inputs: request-timeout: @@ -108,10 +108,10 @@ jobs: - name: Output branch name run: echo ${BRANCH} - name: Set Selenium base version - if: inputs.release != 'true' - run: | - make set_build_nightly - cat .env | xargs -I {} echo {} >> $GITHUB_ENV + uses: ./.github/actions/get-latest-upstream + with: + release: ${{ inputs.release || false }} + gh_cli_token: ${{ secrets.GITHUB_TOKEN }} - name: Sets build date run: | echo "BUILD_DATE=$(date '+%Y%m%d')" >> $GITHUB_ENV diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 30376e9a3..4754d4378 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -12,6 +12,7 @@ on: jobs: build-test: + name: Build and Test Nightly if: github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && github.event.inputs.skip-test == 'false') uses: ./.github/workflows/build-test.yml with: @@ -21,7 +22,7 @@ jobs: needs: - build-test if: (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && !failure() && !cancelled() - name: Nightly build + name: Deploy and Release Nightly runs-on: ubuntu-latest permissions: write-all steps: @@ -45,6 +46,11 @@ jobs: make set_containerd_image_store - name: Output Docker info run: docker info + - name: Set Selenium base version + uses: ./.github/actions/get-latest-upstream + with: + release: false + gh_cli_token: ${{ secrets.GITHUB_TOKEN }} - name: Sets build date run: | echo "BUILD_DATE=$(date '+%Y%m%d')" >> $GITHUB_ENV @@ -59,7 +65,7 @@ jobs: NAMESPACE: ${{ vars.DOCKER_NAMESPACE || 'selenium' }} AUTHORS: ${{ vars.AUTHORS || 'SeleniumHQ' }} - name: Build base image to get Grid version - run: VERSION="local" BUILD_DATE=${BUILD_DATE} make base_nightly + run: VERSION="local" BUILD_DATE=${BUILD_DATE} make base - name: Get Grid version # sed used to remove last comma of Selenium version output run: | diff --git a/Makefile b/Makefile index 91937298f..255900bf0 100644 --- a/Makefile +++ b/Makefile @@ -70,9 +70,6 @@ ci: build test base: cd ./Base && docker buildx build --platform $(PLATFORMS) $(BUILD_ARGS) --build-arg VERSION=$(BASE_VERSION) --build-arg RELEASE=$(BASE_RELEASE) --build-arg AUTHORS=$(AUTHORS) -t $(NAME)/base:$(TAG_VERSION) . -base_nightly: - cd ./Base && docker buildx build --platform $(PLATFORMS) $(BUILD_ARGS) --build-arg VERSION=$(BASE_VERSION_NIGHTLY) --build-arg RELEASE=$(BASE_RELEASE_NIGHTLY) --build-arg AUTHORS=$(AUTHORS) -t $(NAME)/base:$(TAG_VERSION) . - hub: base cd ./Hub && docker buildx build --platform $(PLATFORMS) $(BUILD_ARGS) $(FROM_IMAGE_ARGS) -t $(NAME)/hub:$(TAG_VERSION) .