|
13 | 13 | # limitations under the License.
|
14 | 14 | ---
|
15 | 15 | name: Automation
|
16 |
| -on: [pull_request] |
| 16 | +on: [push, pull_request, workflow_dispatch] |
17 | 17 | jobs:
|
18 | 18 | dependabot:
|
19 | 19 | runs-on: ubuntu-latest
|
20 |
| - if: ${{ github.actor == 'dependabot[bot]' }} |
| 20 | + if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request' }} |
21 | 21 | env:
|
22 | 22 | PR_URL: ${{github.event.pull_request.html_url}}
|
23 | 23 | GITHUB_TOKEN: ${{secrets.GOOGLEWORKSPACE_BOT_TOKEN}}
|
|
26 | 26 | run: gh pr review --approve "$PR_URL"
|
27 | 27 | - name: merge
|
28 | 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