diff --git a/.github/workflows/build_starter.yml b/.github/workflows/build_starter.yml index 2777c445f..23c8e51a9 100644 --- a/.github/workflows/build_starter.yml +++ b/.github/workflows/build_starter.yml @@ -23,8 +23,8 @@ on: default: '' required: false platforms: - description: 'CSV of Android,iOS,Windows,macOS,Linux' - default: 'Android,iOS,Windows,macOS,Linux' + description: 'Test Platforms of Android,iOS,Windows,macOS,Linux,Playmode' + default: 'Android,iOS,Windows,macOS,Linux,Playmode' required: true apis: description: 'CSV of apis to build and test' @@ -50,9 +50,9 @@ on: default: true type: boolean required: true - skipIntegrationTests: - description: 'If we want to skip integration test' - default: '0' + runIntegrationTests: + description: 'run integration tests? (0 will not run integrations)' + default: '1' required: true env: @@ -68,7 +68,7 @@ jobs: apis: ${{ steps.set_outputs.outputs.apis }} release_version: ${{ steps.set_outputs.outputs.release_version }} should_trigger_package: ${{ steps.set_outputs.outputs.should_trigger_package }} - skipIntegrationTests: ${{ steps.set_outputs.outputs.skipIntegrationTests }} + runIntegrationTests: ${{ steps.set_outputs.outputs.runIntegrationTests }} firebase_cpp_sdk_version: ${{ steps.set_outputs.outputs.firebase_cpp_sdk_version }} unity_branch: ${{ steps.set_outputs.outputs.unity_branch }} additional_cmake_flags: ${{ steps.set_outputs.outputs.additional_cmake_flags }} @@ -94,7 +94,7 @@ jobs: echo "::set-output name=apis::${{ github.event.inputs.apis }}" echo "::set-output name=unity_version::${{ github.event.inputs.unity_version }}" echo "::set-output name=should_trigger_package::${{ github.event.inputs.should_trigger_package }}" - echo "::set-output name=skipIntegrationTests::${{ github.event.inputs.skipIntegrationTests }}" + echo "::set-output name=runIntegrationTests::${{ github.event.inputs.runIntegrationTests }}" echo "::set-output name=unity_branch::${{ github.event.inputs.unity_branch }}" echo "::set-output name=additional_cmake_flags::${{ github.event.inputs.unity_branch }}" else @@ -104,11 +104,33 @@ jobs: echo "::set-output name=apis::'analytics,auth,crashlytics,database,dynamic_links,firestore,functions,installations,messaging,remote_config,storage'" echo "::set-output name=unity_version::2019" echo "::set-output name=should_trigger_package::true" - echo "::set-output name=skipIntegrationTests::0" echo "::set-output name=firebase_cpp_sdk_version::" echo "::set-output name=unity_branch::" echo "::set-output name=additional_cmake_flags::" + if [[ "${{ github.event_name }}" == "schedule" ]]; then + echo "::set-output name=runIntegrationTests::nightly-packaging" + elif [[ "${{ github.event_name }}" == "pull_request" ]]; then + if [[ "${{ github.event.action }}" == "labeled" && "${{ github.event.label.name }}" == "tests-requested: quick" ]]; then + echo "::set-output name=runIntegrationTests::${{ github.event.pull_request.number }}:label-quick-packaging" + elif [[ "${{ github.event.action }}" == "labeled" && "${{ github.event.label.name }}" == "tests-requested: full" ]]; then + echo "::set-output name=runIntegrationTests::${{ github.event.pull_request.number }}:label-full-packaging" + elif [[ "${{ github.event.action }}" == "closed" && "${{ github.event.pull_request.merged == true}}" == "true" ]]; then + echo "::set-output name=runIntegrationTests::${{ github.event.pull_request.number }}:pr-close-packaging" + else + echo "::set-output name=invalid_trigger::1" + fi + else + echo "::set-output name=invalid_trigger::1" + fi fi + - name: Cancel workflow + if: ${{ steps.set_outputs.outputs.invalid_trigger }} + uses: andymckay/cancel-action@0.2 + - name: Wait for workflow cancellation + if: ${{ steps.set_outputs.outputs.invalid_trigger }} + run: | + sleep 300 + exit 1 # fail out if the cancellation above somehow failed. - name: Print output run: | @@ -118,7 +140,7 @@ jobs: echo outputs.apis : ${{ steps.set_outputs.outputs.apis }} echo outputs.unity_version : ${{ steps.set_outputs.outputs.unity_version }} echo outputs.should_trigger_package : ${{ steps.set_outputs.outputs.should_trigger_package }} - echo outputs.skipIntegrationTests : ${{ steps.set_outputs.outputs.skipIntegrationTests }} + echo outputs.runIntegrationTests : ${{ steps.set_outputs.outputs.runIntegrationTests }} echo outputs.firebase_cpp_sdk_version : ${{ steps.set_outputs.outputs.firebase_cpp_sdk_version }} echo outputs.unity_branch : ${{ steps.set_outputs.outputs.unity_branch }} echo outputs.additional_cmake_flags : ${{ steps.set_outputs.outputs.additional_cmake_flags }} @@ -222,7 +244,7 @@ jobs: if: (needs.check_and_prepare.outputs.should_trigger_package == 'true') && !cancelled() && !failure() with: release_label: ${{ needs.check_and_prepare.outputs.release_label }} - skipIntegrationTests: ${{ needs.check_and_prepare.outputs.skipIntegrationTests }} + runIntegrationTests: ${{ needs.check_and_prepare.outputs.runIntegrationTests }} build_run_id: ${{ github.run_id }} working_branch: ${{ needs.decide_build_branch.outputs.build_branch }} platforms: ${{ needs.check_and_prepare.outputs.platform }} diff --git a/.github/workflows/integration_tests.yml b/.github/workflows/integration_tests.yml index 30d6f4900..6c4a82cdc 100644 --- a/.github/workflows/integration_tests.yml +++ b/.github/workflows/integration_tests.yml @@ -1,11 +1,6 @@ name: Integration tests on: - schedule: - - cron: "0 9 * * *" # 9am UTC = 1am PST / 2am PDT - - pull_request: - types: [ labeled, closed ] workflow_dispatch: inputs: @@ -75,66 +70,53 @@ jobs: ### trigger value: manual_trigger, scheduled_trigger, label_trigger, postsubmit_trigger - id: set_outputs run: | - if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then - if [[ "${{ github.event.inputs.test_pull_request }}" != "nightly-packaging" ]]; then - # Triggered manually - echo "::set-output name=trigger::manual_trigger" - if [[ "${{ github.event.inputs.use_expanded_matrix }}" == "1" ]]; then - echo "::set-output name=requested_tests::expanded" - fi - if [[ -z "${{github.event.inputs.test_pull_request}}" ]]; then - # test_pull_request not specified - echo "::set-output name=github_ref::$GITHUB_SHA" - elif [[ "${{github.event.inputs.test_pull_request}}" == *:* ]]; then - # If specified as pr:commit_hash, split them. - echo "::set-output name=github_ref::$(echo ${{ github.event.inputs.test_pull_request }} | cut -d: -f2)" - echo "::set-output name=pr_number::$(echo ${{ github.event.inputs.test_pull_request }} | cut -d: -f1)" - else - # Just the PR specified, use refs/pull//merge as the ref. - echo "::set-output name=github_ref::refs/pull/${{github.event.inputs.test_pull_request}}/merge" - echo "::set-output name=pr_number::${{ github.event.inputs.test_pull_request }}" - fi - elif [[ "${{ github.event.inputs.test_pull_request }}" == "nightly-packaging" ]]; then - # Triggered by scheduled packaging SDK workflow. - echo "::set-output name=trigger::scheduled_trigger" - echo "::set-output name=github_ref::$GITHUB_SHA" - echo "::set-output name=requested_tests::expanded" - fi - elif [[ "${{ github.event_name }}" == "schedule" ]]; then + if [[ "${{ github.event.inputs.test_pull_request }}" == *"label-quick-packaging" ]]; then + # Triggered by build_starter SDK workflow. + echo "::set-output name=trigger::label_trigger" + echo "::set-output name=requested_tests::auto" + echo "::set-output name=github_ref::${{github.sha}}" + echo "::set-output name=pr_number::$(echo ${{ github.event.inputs.test_pull_request }} | cut -d: -f1)" + elif [[ "${{ github.event.inputs.test_pull_request }}" == *"label-full-packaging" ]]; then + # Triggered by build_starter SDK workflow. + echo "::set-output name=trigger::label_trigger" + echo "::set-output name=requested_tests::expanded" + echo "::set-output name=github_ref::${{github.sha}}" + echo "::set-output name=pr_number::$(echo ${{ github.event.inputs.test_pull_request }} | cut -d: -f1)" + elif [[ "${{ github.event.inputs.test_pull_request }}" == *"pr-close-packaging" ]]; then + # Triggered by build_starter SDK workflow. + echo "::set-output name=trigger::postsubmit_trigger" + echo "::set-output name=requested_tests::auto" + echo "::set-output name=github_ref::${{github.sha}}" + echo "::set-output name=pr_number::$(echo ${{ github.event.inputs.test_pull_request }} | cut -d: -f1)" + elif [[ "${{ github.event.inputs.test_pull_request }}" == "nightly-packaging" ]]; then + # Triggered by build_starter SDK workflow. echo "::set-output name=trigger::scheduled_trigger" - echo "::set-output name=github_ref::$GITHUB_SHA" echo "::set-output name=requested_tests::expanded" - elif [[ "${{ github.event_name }}" == "pull_request" ]]; then - echo "::set-output name=github_ref::$GITHUB_SHA" - if [[ "${{ github.event.action }}" == "labeled" && "${{ github.event.label.name }}" == "${{ env.triggerLabelPrefix }}"* ]]; then - echo "::set-output name=trigger::label_trigger" - echo "::set-output name=pr_number::${{ github.event.pull_request.number }}" - if [[ "${{ github.event.label.name }}" == "${{ env.triggerLabelQuick }}" ]]; then - echo "::set-output name=requested_tests::auto" - else - echo "::set-output name=requested_tests::expanded" - fi - elif [[ "${{ github.event.action }}" == "closed" && "${{ github.event.pull_request.merged == true}}" == "true" ]]; then - echo "::set-output name=trigger::postsubmit_trigger" - echo "::set-output name=pr_number::${{ github.event.pull_request.number }}" - echo "::set-output name=requested_tests::auto" + echo "::set-output name=github_ref::${{github.sha}}" + elif [[ "${{ github.event.inputs.test_pull_request }}" == "1" ]]; then + # Triggered by build_starter SDK workflow. + echo "::set-output name=trigger::manual_trigger" + echo "::set-output name=requested_tests::auto" + echo "::set-output name=github_ref::${{github.sha}}" + else + # Triggered manually + echo "::set-output name=trigger::manual_trigger" + if [[ "${{ github.event.inputs.use_expanded_matrix }}" == "1" ]]; then + echo "::set-output name=requested_tests::expanded" + fi + if [[ -z "${{github.event.inputs.test_pull_request}}" ]]; then + # test_pull_request not specified + echo "::set-output name=github_ref::${{github.sha}}" + elif [[ "${{github.event.inputs.test_pull_request}}" == *:* ]]; then + # If specified as pr:commit_hash, split them. + echo "::set-output name=github_ref::$(echo ${{ github.event.inputs.test_pull_request }} | cut -d: -f2)" + echo "::set-output name=pr_number::$(echo ${{ github.event.inputs.test_pull_request }} | cut -d: -f1)" + else + # Just the PR specified, use refs/pull//merge as the ref. + echo "::set-output name=github_ref::refs/pull/${{github.event.inputs.test_pull_request}}/merge" + echo "::set-output name=pr_number::${{ github.event.inputs.test_pull_request }}" fi fi - ### If it's not a defined trigger, cancel workflow - ### e.g. Triggered by non-"test-request" label; triggered by not merged PR close event. - - name: Cancel workflow - if: ${{ !steps.set_outputs.outputs.trigger }} - uses: andymckay/cancel-action@0.2 - - name: Wait for workflow cancellation - if: ${{ !steps.set_outputs.outputs.trigger }} - run: | - sleep 300 - exit 1 # fail out if the cancellation above somehow failed. - - name: Cancel previous runs on the same PR - if: steps.set_outputs.outputs.trigger == 'label_trigger' - uses: styfle/cancel-workflow-action@0.8.0 - with: - access_token: ${{ github.token }} - uses: actions/checkout@v2 with: ref: ${{steps.set_outputs.outputs.github_ref}} @@ -262,7 +244,7 @@ jobs: workflow: 'build_starter.yml' run_id: ${{ github.event.inputs.packaged_sdk_run_id }} - name: Build integration tests - timeout-minutes: 180 + timeout-minutes: 240 shell: bash run: | unzip -q firebase_unity_sdk.zip -d ~/Downloads/ diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml index 77a4a383e..da5a8abd3 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/package.yml @@ -4,10 +4,10 @@ name: Package SDKs on: workflow_call: inputs: - skipIntegrationTests: - description: 'skip integration tests?' - default: '0' - required: false + runIntegrationTests: + description: 'run integration tests?' + default: '1' + required: true type: string create_new_branch: description: 'Check if we need to create new branch to package guids update. If working_branch set, will ignore this value. ' @@ -48,50 +48,27 @@ jobs: runs-on: ubuntu-latest strategy: fail-fast: false - outputs: - skipIntegrationTests: ${{ steps.decide_input.outputs.skipIntegrationTests }} - platforms: ${{ steps.decide_input.outputs.platforms }} - apis: ${{ steps.decide_input.outputs.apis }} steps: - - name: Decide inputs - id: decide_input - shell: bash - run: | - # Triggered by callable - echo "::set-output name=workflow_conclusion::in_progress" - echo "::set-output name=skipIntegrationTests::${{ inputs.skipIntegrationTests }}" - echo "::set-output name=create_new_branch::${{ inputs.create_new_branch }}" - echo "::set-output name=release_label::${{ inputs.release_label }}" - echo "::set-output name=working_branch::${{ inputs.working_branch }}" - echo "::set-output name=download_android_run::${{ inputs.build_run_id }}" - echo "::set-output name=download_ios_run::${{ inputs.build_run_id }}" - echo "::set-output name=download_linux_run::${{ inputs.build_run_id }}" - echo "::set-output name=download_macos_run::${{ inputs.build_run_id }}" - echo "::set-output name=download_windows_run::${{ inputs.build_run_id }}" - echo "::set-output name=platforms::${{ inputs.platforms }}" - echo "::set-output name=apis::${{ inputs.apis }}" - - name: Print inputs shell: bash run: | - echo workflow_conclusion: ${{ steps.decide_input.outputs.workflow_conclusion }} - echo skipIntegrationTests: ${{ steps.decide_input.outputs.skipIntegrationTests }} - echo create_new_branch: ${{ steps.decide_input.outputs.create_new_branch }} - echo release_label: ${{ steps.decide_input.outputs.release_label }} - echo working_branch: ${{ steps.decide_input.outputs.working_branch }} - echo download_android_run: ${{ steps.decide_input.outputs.download_android_run }} - echo download_ios_run: ${{ steps.decide_input.outputs.download_ios_run }} - echo download_linux_run: ${{ steps.decide_input.outputs.download_linux_run }} - echo download_macos_run: ${{ steps.decide_input.outputs.download_macos_run }} - echo download_windows_run: ${{ steps.decide_input.outputs.download_windows_run }} - echo platforms: ${{ steps.decide_input.outputs.platforms }}" - echo apis: ${{ steps.decide_input.outputs.apis }}" + echo runIntegrationTests: ${{ inputs.runIntegrationTests }} + echo create_new_branch: ${{ inputs.create_new_branch }} + echo release_label: ${{ inputs.release_label }} + echo working_branch: ${{ inputs.working_branch }} + echo download_android_run: ${{ inputs.download_android_run }} + echo download_ios_run: ${{ inputs.download_ios_run }} + echo download_linux_run: ${{ inputs.download_linux_run }} + echo download_macos_run: ${{ inputs.download_macos_run }} + echo download_windows_run: ${{ inputs.download_windows_run }} + echo platforms: ${{ inputs.platforms }}" + echo apis: ${{ inputs.apis }}" - name: Check out base branch uses: actions/checkout@v2.3.1 with: fetch-depth: 0 - ref: ${{ steps.decide_input.outputs.working_branch }} + ref: ${{ inputs.working_branch }} - name: Setup Python uses: actions/setup-python@v2 @@ -117,25 +94,25 @@ jobs: private_key: ${{ secrets.WORKFLOW_TRIGGER_APP_PRIVATE_KEY }} - name: Name new branch - if: steps.decide_input.outputs.working_branch == '' && steps.decide_input.outputs.create_new_branch == '1' + if: inputs.working_branch == '' && inputs.create_new_branch == '1' run: | date_str=$(date "+%Y%m%d-%H%M%S") echo "NEW_BRANCH=new_branch-${date_str}" >> $GITHUB_ENV - name: Create new branch - if: steps.decide_input.outputs.working_branch == '' && steps.decide_input.outputs.create_new_branch == '1' + if: inputs.working_branch == '' && inputs.create_new_branch == '1' run: | git remote update git checkout -b "${NEW_BRANCH}" echo "UPDATE_LOGFILE=update_log.txt" >> $GITHUB_ENV - name: Checkout working branch - if: steps.decide_input.outputs.working_branch != '' + if: inputs.working_branch != '' run: | git remote update - git checkout ${{ steps.decide_input.outputs.working_branch }} + git checkout ${{ inputs.working_branch }} echo "UPDATE_LOGFILE=update_log.txt" >> $GITHUB_ENV - echo "NEW_BRANCH=${{ steps.decide_input.outputs.working_branch }}" >> $GITHUB_ENV + echo "NEW_BRANCH=${{ inputs.working_branch }}" >> $GITHUB_ENV # If called by build_start.xml, ignore name search, just grab all artifact exists - name: Fetch All in build_starter @@ -161,7 +138,7 @@ jobs: python scripts/build_scripts/build_package.py --zip_dir=built_artifact - name: Commit Changes if there is any - if: steps.decide_input.outputs.working_branch != '' || steps.decide_input.outputs.create_new_branch == '1' + if: inputs.working_branch != '' || inputs.create_new_branch == '1' run: | if ! git update-index --refresh; then git config user.email "firebase-workflow-trigger-bot@google.com" @@ -176,7 +153,7 @@ jobs: fi - name: Create PR if there is None - if: steps.decide_input.outputs.working_branch != '' || steps.decide_input.outputs.create_new_branch == '1' + if: inputs.working_branch != '' || inputs.create_new_branch == '1' id: push-branch run: | if ! git update-index --refresh; then @@ -266,7 +243,7 @@ jobs: trigger_integration_tests: # Trigger the integration_tests workflow. needs: [package_sdks] - if: (needs.package_sdks.outputs.skipIntegrationTests == '0') && !cancelled() && !failure() + if: (inputs.runIntegrationTests != '0') && !cancelled() && !failure() runs-on: ubuntu-latest steps: - name: Checkout repo @@ -288,19 +265,19 @@ jobs: with: app_id: ${{ secrets.WORKFLOW_TRIGGER_APP_ID }} private_key: ${{ secrets.WORKFLOW_TRIGGER_APP_PRIVATE_KEY }} + - name: Get branch name + id: branch-name + uses: tj-actions/branch-names@v5.4 - name: Use GitHub API to start workflow shell: bash run: | pip install -r scripts/gha/requirements.txt - if [[ "${{ github.event_name }}" == "schedule" ]]; then - # reuse flag --test_pull_request=nightly-packaging to generate report - generate_report=(-p test_pull_request nightly-packaging) - fi set -e - python scripts/gha/trigger_workflow.py \ - -t ${{ steps.generate-token.outputs.token }} \ + python scripts/gha/trigger_workflow.py -t ${{ steps.generate-token.outputs.token }} \ + -b ${{ steps.branch-name.outputs.current_branch }} \ -w integration_tests.yml \ -p packaged_sdk_run_id ${{ github.run_id }} \ - -p platforms ${{ needs.package_sdks.outputs.platforms }} \ - -p apis ${{ needs.package_sdks.outputs.apis }} \ + -p platforms ${{ inputs.platforms }} \ + -p apis ${{ inputs.apis }} \ + -p test_pull_request ${{ inputs.runIntegrationTests }} \ -s 10 -A -v diff --git a/scripts/gha/trigger_workflow.py b/scripts/gha/trigger_workflow.py index c3e0be990..03463c613 100644 --- a/scripts/gha/trigger_workflow.py +++ b/scripts/gha/trigger_workflow.py @@ -67,12 +67,10 @@ def main(): workflows = github.list_workflows(args.token, args.workflow, args.branch) run_id = 0 if "workflow_runs" in workflows: - branch_sha = subprocess.check_output(['git', 'rev-parse', args.branch]).decode('utf-8').rstrip('\n') for workflow in workflows['workflow_runs']: # Use a heuristic to get the new workflow's run ID. - # Must match the branch name and commit sha, and be queued/in progress. + # Must match the branch name, and be queued/in progress. if (workflow['status'] in ('queued', 'in_progress') and - workflow['head_sha'] == branch_sha and workflow['head_branch'] == args.branch): run_id = workflow['id'] break diff --git a/scripts/gha/unity_installer.py b/scripts/gha/unity_installer.py index 2e6cdbc08..faafdf7a7 100644 --- a/scripts/gha/unity_installer.py +++ b/scripts/gha/unity_installer.py @@ -83,7 +83,7 @@ from print_matrix_configuration import UNITY_SETTINGS -FLAGS = flags.FLAGS +_CMD_TIMEOUT = 600 _DEFALUT = "Default" _ANDROID = "Android" @@ -93,6 +93,8 @@ _LINUX = "Linux" _SUPPORTED_PLATFORMS = (_ANDROID, _IOS, _WINDOWS, _MACOS, _LINUX) +FLAGS = flags.FLAGS + # These are the three actions supported by the tool. flags.DEFINE_bool( "install", False, @@ -258,9 +260,10 @@ def get_unity_path(version): raise RuntimeError("Only Windows and MacOS are supported.") -def run(args, check=True): +def run(args, check=True, timeout=_CMD_TIMEOUT): """Runs args in a subprocess, throwing an error on non-zero return code.""" - subprocess.run(args=args, check=check) + logging.info("run cmd: %s", " ".join(args)) + subprocess.run(args=args, check=check, timeout=timeout) if __name__ == "__main__":