|
| 1 | +# Workflow to handle packaging the Unity SDK |
| 2 | +name: Update Versions |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + operating_systems: |
| 8 | + description: 'CSV of VMs to run on' |
| 9 | + default: 'ubuntu-latest' |
| 10 | + required: true |
| 11 | + package_version_number: |
| 12 | + description: "The Unity SDK version to upgrade to" |
| 13 | + default: 8.6.0 |
| 14 | + |
| 15 | +jobs: |
| 16 | + update_versions: |
| 17 | + name: package-${{matrix.os}} |
| 18 | + runs-on: ${{matrix.os}} |
| 19 | + strategy: |
| 20 | + fail-fast: false |
| 21 | + matrix: |
| 22 | + os: [ubuntu-latest] |
| 23 | + include: |
| 24 | + - os: ubuntu-latest |
| 25 | + package_dir: output |
| 26 | + steps: |
| 27 | + - name: Check out base branch |
| 28 | + |
| 29 | + with: |
| 30 | + path: firebase-unity-sdk |
| 31 | + fetch-depth: 0 |
| 32 | + ref: ${{ github.event.inputs.baseBranch }} |
| 33 | + |
| 34 | + - name: Checkout CPP Repo |
| 35 | + uses: actions/checkout@v2 |
| 36 | + with: |
| 37 | + repository: firebase/firebase-cpp-sdk |
| 38 | + path: firebase-cpp-sdk |
| 39 | + ref: ${{ github.event.inputs.firebase_cpp_sdk_version }} |
| 40 | + submodules: true |
| 41 | + |
| 42 | + - name: Get token for firebase-workflow-trigger |
| 43 | + uses: tibdex/github-app-token@v1 |
| 44 | + id: generate-token |
| 45 | + with: |
| 46 | + app_id: ${{ secrets.WORKFLOW_TRIGGER_APP_ID }} |
| 47 | + private_key: ${{ secrets.WORKFLOW_TRIGGER_APP_PRIVATE_KEY }} |
| 48 | + |
| 49 | + - name: Setup Python |
| 50 | + uses: actions/setup-python@v2 |
| 51 | + with: |
| 52 | + python-version: 3.7 |
| 53 | + |
| 54 | + - name: Install python deps |
| 55 | + shell: bash |
| 56 | + run: | |
| 57 | + cd firebase-unity-sdk |
| 58 | + pip install -r scripts/gha/requirements.txt |
| 59 | +
|
| 60 | + - name: Name new branch |
| 61 | + run: | |
| 62 | + date_str=$(date "+%Y%m%d-%H%M%S") |
| 63 | + echo "NEW_BRANCH=${{env.branchPrefix}}${{github.event.inputs.package_version_number}}-${date_str}" >> $GITHUB_ENV |
| 64 | +
|
| 65 | + - name: Create new branch |
| 66 | + run: | |
| 67 | + cd firebase-unity-sdk |
| 68 | + git remote update |
| 69 | + git checkout -b "${NEW_BRANCH}" |
| 70 | + echo "UPDATE_LOGFILE=update_log.txt" >> $GITHUB_ENV |
| 71 | +
|
| 72 | + - name: Update Unity SDK version and dependencies |
| 73 | + run: | |
| 74 | + cd firebase-unity-sdk |
| 75 | + python scripts/update_versions.py --unity_sdk_version=${{github.event.inputs.package_version_number}} |
| 76 | +
|
| 77 | + - name: Push branch if there are changes |
| 78 | + id: push-branch |
| 79 | + run: | |
| 80 | + cd firebase-unity-sdk |
| 81 | + if ! git update-index --refresh; then |
| 82 | + date_str=$(date "+%a %b %d %Y") |
| 83 | + commit_title="Update Unity SDK dependencies - ${date_str}" |
| 84 | + commit_body= |
| 85 | + if [[ -n '${{ github.event.inputs.comment }}' ]]; then |
| 86 | + # If a comment was provided, start with that instead of blank. |
| 87 | + commit_body='${{ github.event.inputs.comment }} |
| 88 | +
|
| 89 | + ' |
| 90 | + fi |
| 91 | +
|
| 92 | + commit_body="${commit_body} |
| 93 | +
|
| 94 | + > Created by [${{github.workflow}} workflow]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID)." |
| 95 | + git config user.email "[email protected]" |
| 96 | + git config user.name "firebase-workflow-trigger-bot" |
| 97 | + git config core.commentChar "%" # so we can use # in git commit messages |
| 98 | + git commit -a -m "${commit_title} |
| 99 | +
|
| 100 | + ${commit_body}" |
| 101 | + echo "::set-output name=branch_pushed::1" |
| 102 | + # Show changes in git log |
| 103 | + git diff |
| 104 | + # Push branch |
| 105 | + git push --set-upstream origin "${NEW_BRANCH}" |
| 106 | + # Create pull request |
| 107 | + pr_number=$(python scripts/gha/create_pull_request.py --token ${{ steps.generate-token.outputs.token }} --head "${NEW_BRANCH}" --base "${{ github.event.inputs.baseBranch }}" --title "${commit_title}" --body "${commit_body}") |
| 108 | + echo "::set-output name=created_pr_number::${pr_number}" |
| 109 | + else |
| 110 | + echo "::warning ::No changes detected, won't create pull request." |
| 111 | + echo "::set-output name=branch_pushed::0" |
| 112 | + fi |
| 113 | +
|
| 114 | + trigger_build_sdks: |
| 115 | + needs: [update_versions] |
| 116 | + name: trigger-build-${{matrix.platform}} |
| 117 | + runs-on: ubuntu-latest |
| 118 | + strategy: |
| 119 | + fail-fast: false |
| 120 | + matrix: |
| 121 | + platform: [android, ios, desktop] |
| 122 | + include: |
| 123 | + - platform: android |
| 124 | + trigger_file: android.yml |
| 125 | + - platform: ios |
| 126 | + trigger_file: ios.yml |
| 127 | + - platform: desktop |
| 128 | + trigger_file: sdk_build.yml |
| 129 | + |
| 130 | + steps: |
| 131 | + - name: Checkout repo |
| 132 | + |
| 133 | + |
| 134 | + - name: Setup python |
| 135 | + uses: actions/setup-python@v2 |
| 136 | + with: |
| 137 | + python-version: 3.7 |
| 138 | + |
| 139 | + - name: Generate token for GitHub API |
| 140 | + # This step is necessary because the existing GITHUB_TOKEN cannot be used inside one workflow to trigger another. |
| 141 | + # |
| 142 | + # Instead, generate a new token here, using our GitHub App's private key and App ID (saved as Secrets). |
| 143 | + # |
| 144 | + # This method is preferred over the "personal access token" solution, as the GitHub App's scope is limited to just |
| 145 | + # the firebase-cpp-sdk repository. |
| 146 | + uses: tibdex/github-app-token@v1 |
| 147 | + id: generate-token |
| 148 | + with: |
| 149 | + app_id: ${{ secrets.WORKFLOW_TRIGGER_APP_ID }} |
| 150 | + private_key: ${{ secrets.WORKFLOW_TRIGGER_APP_PRIVATE_KEY }} |
| 151 | + |
| 152 | + - name: Use GitHub API to start workflow |
| 153 | + shell: bash |
| 154 | + run: | |
| 155 | + pip install -r scripts/gha/requirements.txt |
| 156 | + if [[ "${{ github.event_name }}" == "schedule" ]]; then |
| 157 | + # reuse flag --test_pull_request=nightly-packaging to generate report |
| 158 | + generate_report=(-p test_pull_request nightly-packaging) |
| 159 | + fi |
| 160 | + set -e |
| 161 | + python scripts/gha/trigger_workflow.py -t ${{ steps.generate-token.outputs.token }} -w ${{ matrix.trigger_file }} -p test_packaged_sdk ${{ github.run_id }} -s 10 -A -v |
0 commit comments