diff --git a/.github/workflows/lvbs-smoke-test.yml b/.github/workflows/lvbs-smoke-test.yml index 3daec430d..93cf0d9ff 100755 --- a/.github/workflows/lvbs-smoke-test.yml +++ b/.github/workflows/lvbs-smoke-test.yml @@ -6,6 +6,10 @@ on: - opened - synchronize - reopened + # Test-only trigger for PR #1344. Remove before merging the workflow. + pull_request: + types: + - synchronize permissions: contents: read @@ -29,69 +33,86 @@ jobs: allow-no-subscriptions: true - name: Trigger ADO pipeline and wait for completion - uses: azure/cli@v2 + shell: bash env: ADO_ORGANIZATION: https://dev.azure.com/msazure ADO_PIPELINE_ID: "471678" ADO_PROJECT: LSG-linux LITEBOX_COMMIT: ${{ github.event.pull_request.head.sha }} LITEBOX_REPO_URL: ${{ github.event.pull_request.head.repo.clone_url }} - with: - inlineScript: | - set -eu + run: | + set -eu - BUILD_ID="" - cancel_build() { - trap - INT TERM - if [ -n "${BUILD_ID}" ]; then - echo "Cancelling superseded ADO build ${BUILD_ID}..." - az pipelines build cancel \ - --build-id "${BUILD_ID}" \ - --organization "${ADO_ORGANIZATION}" \ - --project "${ADO_PROJECT}" \ - --output none || true - fi - exit 130 - } - trap cancel_build INT TERM + BUILD_ID="" + cancel_build() { + trap - INT TERM + if [ -n "${BUILD_ID}" ]; then + echo "Cancelling superseded ADO build ${BUILD_ID}..." + az pipelines build cancel \ + --build-id "${BUILD_ID}" \ + --organization "${ADO_ORGANIZATION}" \ + --project "${ADO_PROJECT}" \ + --output none || true + fi + exit 130 + } + trap cancel_build INT TERM - echo "Triggering ADO pipeline for Litebox commit ${LITEBOX_COMMIT}..." - BUILD_RESULT="$(az pipelines run \ - --id "${ADO_PIPELINE_ID}" \ - --organization "${ADO_ORGANIZATION}" \ - --project "${ADO_PROJECT}" \ - --parameters "liteboxCommit=${LITEBOX_COMMIT}" "liteboxRepoUrl=${LITEBOX_REPO_URL}" \ - --output json)" + az config set extension.use_dynamic_install=yes_without_prompt - BUILD_ID="$(printf '%s\n' "${BUILD_RESULT}" | jq -r '.id // empty')" - if [ -z "${BUILD_ID}" ]; then - echo "Failed to get the build ID from the pipeline trigger." - exit 1 - fi + echo "Triggering ADO pipeline for Litebox commit ${LITEBOX_COMMIT}..." + BUILD_RESULT="$(az pipelines run \ + --id "${ADO_PIPELINE_ID}" \ + --organization "${ADO_ORGANIZATION}" \ + --project "${ADO_PROJECT}" \ + --parameters "liteboxCommit=${LITEBOX_COMMIT}" "liteboxRepoUrl=${LITEBOX_REPO_URL}" \ + --output json)" - BUILD_URL="https://msazure.visualstudio.com/${ADO_PROJECT}/_build/results?buildId=${BUILD_ID}" - echo "Triggered ADO build ${BUILD_ID}: ${BUILD_URL}" + BUILD_ID="$(printf '%s\n' "${BUILD_RESULT}" | jq -r '.id // empty')" + if [ -z "${BUILD_ID}" ]; then + echo "Failed to get the build ID from the pipeline trigger." + exit 1 + fi + echo "ADO_BUILD_ID=${BUILD_ID}" >> "${GITHUB_ENV}" - while true; do - BUILD_JSON="$(az pipelines build show \ - --id "${BUILD_ID}" \ - --organization "${ADO_ORGANIZATION}" \ - --project "${ADO_PROJECT}" \ - --output json)" + BUILD_URL="https://msazure.visualstudio.com/${ADO_PROJECT}/_build/results?buildId=${BUILD_ID}" + echo "Triggered ADO build ${BUILD_ID}: ${BUILD_URL}" - BUILD_STATUS="$(printf '%s\n' "${BUILD_JSON}" | jq -r '.status')" - BUILD_RESULT_STATUS="$(printf '%s\n' "${BUILD_JSON}" | jq -r '.result // "none"')" - echo "ADO build status: ${BUILD_STATUS}; result: ${BUILD_RESULT_STATUS}" + while true; do + BUILD_JSON="$(az pipelines build show \ + --id "${BUILD_ID}" \ + --organization "${ADO_ORGANIZATION}" \ + --project "${ADO_PROJECT}" \ + --output json)" - if [ "${BUILD_STATUS}" = "completed" ]; then - trap - INT TERM - if [ "${BUILD_RESULT_STATUS}" = "succeeded" ]; then - exit 0 - fi + BUILD_STATUS="$(printf '%s\n' "${BUILD_JSON}" | jq -r '.status')" + BUILD_RESULT_STATUS="$(printf '%s\n' "${BUILD_JSON}" | jq -r '.result // "none"')" + echo "ADO build status: ${BUILD_STATUS}; result: ${BUILD_RESULT_STATUS}" - echo "ADO build ${BUILD_ID} did not succeed: ${BUILD_URL}" - exit 1 + if [ "${BUILD_STATUS}" = "completed" ]; then + trap - INT TERM + if [ "${BUILD_RESULT_STATUS}" = "succeeded" ]; then + exit 0 fi - sleep 60 - done + echo "ADO build ${BUILD_ID} did not succeed: ${BUILD_URL}" + exit 1 + fi + + sleep 60 + done + + - name: Cancel superseded ADO pipeline + if: cancelled() && env.ADO_BUILD_ID != '' + shell: bash + env: + ADO_ORGANIZATION: https://dev.azure.com/msazure + ADO_PROJECT: LSG-linux + run: | + echo "Cancelling superseded ADO build ${ADO_BUILD_ID}..." + az config set extension.use_dynamic_install=yes_without_prompt + az pipelines build cancel \ + --build-id "${ADO_BUILD_ID}" \ + --organization "${ADO_ORGANIZATION}" \ + --project "${ADO_PROJECT}" \ + --output none