Skip to content

Commit eb0696e

Browse files
chore: Synced local '.github/workflows/automation.yml' with remote 'sync-files/defaults/.github/workflows/automation.yml' (#385)
1 parent f618a9d commit eb0696e

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

.github/workflows/automation.yml

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
# limitations under the License.
1414
---
1515
name: Automation
16-
on: [pull_request]
16+
on: [push, pull_request, workflow_dispatch]
1717
jobs:
1818
dependabot:
1919
runs-on: ubuntu-latest
20-
if: ${{ github.actor == 'dependabot[bot]' }}
20+
if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request' }}
2121
env:
2222
PR_URL: ${{github.event.pull_request.html_url}}
2323
GITHUB_TOKEN: ${{secrets.GOOGLEWORKSPACE_BOT_TOKEN}}
@@ -26,3 +26,44 @@ jobs:
2626
run: gh pr review --approve "$PR_URL"
2727
- name: merge
2828
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

Comments
 (0)