-
Notifications
You must be signed in to change notification settings - Fork 1
114 lines (108 loc) · 4.3 KB
/
pr-utils.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# Contains different utility checks for Pull Requests.
name: PR Utils
# Only apply to PRs which target 'master' branch.
on:
pull_request:
branches:
- master
types:
- opened
- edited
- reopened
- synchronize
jobs:
lint-commits:
name: Lint commits
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' && github.actor != 'dependabot[bot]'
steps:
- name: Run linter
uses: abinnovision/actions@run-commitlint-v1
dependabot:
name: "Dependabot automations"
# Only run for Dependabot PRs.
if: github.event.pull_request.user.login == 'dependabot[bot]'
runs-on: ubuntu-latest
permissions:
pull-requests: write
issues: write
repository-projects: write
contents: write
steps:
- uses: actions/checkout@v4
- id: status
name: Resolve current status
run: |
echo "HAS_REVIEWS=$(if [[ $(gh pr status --json reviews | jq '.currentBranch.reviews | length') -eq '0' ]];then echo 'false'; else echo 'true'; fi)" >> $GITHUB_OUTPUT
echo "LAST_REVIEW_DISMISSED=$(if [[ $(gh pr status --json reviews | jq '.currentBranch.reviews[-1].state' | sed 's/"//g') -eq 'DISMISSED' ]];then echo 'true'; else echo 'false'; fi)" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Metadata
id: metadata
uses: dependabot/[email protected]
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: Enable auto-rebase
id: enable-auto-rebase
run: gh pr merge --auto --squash "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: "Approve (minor & patch)"
id: approve
if: (steps.status.outputs.HAS_REVIEWS == 'false' || steps.status.outputs.LAST_REVIEW_DISMISSED == 'true') && steps.metadata.outputs.update-type == 'version-update:semver-minor' || steps.metadata.outputs.update-type == 'version-update:semver-patch'
run: gh pr review --approve "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
dependabot-dedupe:
name: "Dependabot / Yarn deduplication"
runs-on: ubuntu-latest
# Only run for Dependabot PRs.
if: github.event.pull_request.user.login == 'dependabot[bot]'
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: abinnovision/actions@setup-node-v1
- name: Dedupe
id: dedupe
run: |
yarn install --immutable
yarn dedupe
# If there are changes, commit them.
if [[ $(git status --porcelain yarn.lock | wc -l) -ne "0" ]]; then
echo "has-changes=true" >> $GITHUB_OUTPUT
else
echo "has-changes=false" >> $GITHUB_OUTPUT
fi
- name: Setup GCP Authentication
if: steps.dedupe.outputs.has-changes == 'true'
uses: abinnovision/actions/actions/setup-gcp@master
with:
auth: ${{ vars.GCP_AUTH }}
- id: token
if: steps.dedupe.outputs.has-changes == 'true'
name: Generate GitHub App token
uses: abinnovision/actions/actions/get-github-app-token@master
with:
identification: ${{ secrets.GH_APP_IDENTIFICATION_RELEASER }}
- name: Fetch Bot metadata
if: steps.dedupe.outputs.has-changes == 'true'
env:
GITHUB_TOKEN: ${{ steps.token.outputs.token }}
run: |
bot_data=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /user)
echo "bot-login=$(echo $bot_data | jq -r .login)" >> $GITHUB_OUTPUT
echo "bot-email=$(echo $bot_data | jq -r .email)" >> $GITHUB_OUTPUT
- name: Commit changes
if: steps.dedupe.outputs.has-changes == 'true'
run: |
git config --global user.name '${{ steps.bot-login.outputs.bot-login }}'
git config --global user.email '${{ steps.bot-email.outputs.bot-email }}'
git commit -am "build: deduplicate dependencies"
- name: Push changes
if: steps.dedupe.outputs.has-changes == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ steps.token.outputs.token }}
branch: ${{ github.head_ref }}