|
| 1 | +# Copyright 2022 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +--- |
| 15 | +name: Automation |
| 16 | +on: [push, pull_request, workflow_dispatch] |
| 17 | +jobs: |
| 18 | + dependabot: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request' }} |
| 21 | + env: |
| 22 | + PR_URL: ${{github.event.pull_request.html_url}} |
| 23 | + GITHUB_TOKEN: ${{secrets.GOOGLEWORKSPACE_BOT_TOKEN}} |
| 24 | + steps: |
| 25 | + - name: approve |
| 26 | + run: gh pr review --approve "$PR_URL" |
| 27 | + - name: merge |
| 28 | + run: gh pr merge --auto --squash --delete-branch "$PR_URL" |
| 29 | + default-branch-migration: |
| 30 | + # this job helps with migrating the default branch to main |
| 31 | + # it pushes main to master if master exists and main is the default branch |
| 32 | + # it pushes master to main if master is the default branch |
| 33 | + runs-on: ubuntu-latest |
| 34 | + if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' }} |
| 35 | + steps: |
| 36 | + - uses: actions/checkout@v2 |
| 37 | + with: |
| 38 | + fetch-depth: 0 |
| 39 | + # required otherwise GitHub blocks infinite loops in pushes originating in an action |
| 40 | + token: ${{ secrets.GOOGLEWORKSPACE_BOT_TOKEN }} |
| 41 | + - name: Set env |
| 42 | + run: | |
| 43 | + # set DEFAULT BRANCH |
| 44 | + echo "DEFAULT_BRANCH=$(gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name')" >> $GITHUB_ENV; |
| 45 | +
|
| 46 | + # set HAS_MASTER_BRANCH |
| 47 | + if [ ! -z "$(git ls-remote --heads origin master)" ]; then |
| 48 | + echo "HAS_MASTER_BRANCH=true" >> $GITHUB_ENV |
| 49 | + else |
| 50 | + echo "HAS_MASTER_BRANCH=false" >> $GITHUB_ENV |
| 51 | + fi |
| 52 | + env: |
| 53 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 54 | + - name: configure git |
| 55 | + run: | |
| 56 | + git config --global user.name 'googleworkspace-bot' |
| 57 | + git config --global user.email 'googleworkspace-bot@google.com' |
| 58 | + - if: ${{ env.DEFAULT_BRANCH == 'main' && env.HAS_MASTER_BRANCH == 'true' }} |
| 59 | + name: Update master branch from main |
| 60 | + run: | |
| 61 | + git checkout -b master |
| 62 | + git reset --hard origin/main |
| 63 | + git push origin master |
| 64 | + - if: ${{ env.DEFAULT_BRANCH == 'master'}} |
| 65 | + name: Update main branch from master |
| 66 | + run: | |
| 67 | + git checkout -b main |
| 68 | + git reset --hard origin/master |
| 69 | + git push origin main |
0 commit comments