Skip to content

Commit 6639ec2

Browse files
authored
Merge pull request #246 from TechnologyEnhancedLearning/ci-dependabot-setup
chore(deps): refactor
2 parents 65cb2aa + 02114f0 commit 6639ec2

File tree

2 files changed

+123
-45
lines changed

2 files changed

+123
-45
lines changed
Lines changed: 24 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
# qqqq in development
2-
# qqqq not getting the events
32
# this script seperate major and minor but we do merge them into the same branch.
43
# having two steps allows us to easily turn off major changes in future and then script them to their own branch and pipeline.
54
name: auto-merge dependabot prs into collected branch
65
on:
7-
# pull_request:
8-
# synchronize
9-
# types: [opened, synchronize]
10-
# branches: [Automatic_version_update_dependabot] # make sure this matches your actual branch name
11-
check_suite:
12-
types: [completed]
13-
workflow_dispatch:
6+
pull_request:
7+
types: [opened, synchronize]
8+
branches: [Automatic_version_update_dependabot] # make sure this matches your actual branch name
9+
1410

1511
permissions:
1612
contents: write
@@ -26,54 +22,41 @@ jobs:
2622
echo "actor: ${{ github.actor }}"
2723
echo "pr title: ${{ github.event.pull_request.title }}"
2824
echo "github event_name: ${{ github.event_name }}"
29-
echo "github event_suite conlusion: ${{ github.event.check_suite.conclusion }}"
3025
echo "target branch: ${{ github.event.pull_request.base.ref }}"
3126
echo "source branch: ${{ github.event.pull_request.head.ref }}"
32-
echo "Check Suite ID: ${{ github.event.check_suite.id }}"
33-
echo "Conclusion: ${{ github.event.check_suite.conclusion }}"
34-
echo "Target Branch: ${{ github.event.check_suite.pull_requests[0].base.ref }}"
35-
echo "PR Number: ${{ github.event.check_suite.pull_requests[0].number }}"
27+
echo "PR Number: ${{ github.event.pull_request.number }}"
3628
3729
- name: Dump event payload
3830
run: |
3931
echo "==== EVENT NAME ===="
4032
echo "${{ github.event_name }}"
41-
echo "==== RAW CHECK_SUITE PAYLOAD ===="
42-
echo '${{ toJson(github.event.check_suite) }}'
43-
echo "==== PRs in this check suite ===="
44-
echo '${{ toJson(github.event.check_suite.pull_requests) }}'
33+
echo "==== RAW PULL_REQUEST PAYLOAD ===="
34+
echo '${{ toJson(github.event.pull_request) }}'
4535
46-
36+
# Branch rules ensure doesnt auto merge if shouldnt
4737
auto-merge:
4838
runs-on: ubuntu-latest
49-
# if: github.event.check_suite.pull_requests[0].base.ref == 'main'
50-
# if dependabot and checks ran
51-
# if: (github.event_name != 'check_suite' || github.event.check_suite.conclusion == 'success')
52-
# qqqq put back in later if: (github.actor == 'dependabot[bot]' || github.event_name == 'workflow_dispatch')&& (github.event_name != 'check_suite' || github.event.check_suite.conclusion == 'success')
53-
54-
55-
# qqqq add in after testing && github.actor == 'dependabot[bot]'
56-
if: github.event.check_suite.conclusion == 'success' && github.event.check_suite.pull_requests[0].base.ref == 'Automatic_version_update_dependabot'
39+
# qqqq add in after testing if: github.actor == 'dependabot[bot]'
5740
steps:
5841
- name: Checkout the repository
59-
uses: actions/checkout@v3
42+
uses: actions/checkout@v4
43+
44+
# - name: Set up GitHub CLI
45+
# run: |
46+
# # Install GitHub CLI (gh)
47+
# sudo apt-get update
48+
# sudo apt-get install gh
6049

6150
- name: Set up GitHub CLI
62-
run: |
63-
# Install GitHub CLI (gh)
64-
sudo apt-get update
65-
sudo apt-get install gh
51+
uses: github/gh-cli@v2
6652

6753
- name: extract update type
6854
id: extract
6955
env:
7056
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7157
run: |
7258
echo "get pr number"
73-
pr_number=${{ github.event.check_suite.pull_requests[0].number }}
74-
echo "PR title: $pr_number"
75-
# pr_title="${{ github.event.pull_request.title }}"
76-
pr_title=$(gh pr view "$pr_number" --json title --jq .title)
59+
pr_title=${{ github.event.pull_request.title }}
7760
echo "PR title: $pr_title"
7861
if [[ $pr_title == *"(major)"* ]]; then
7962
echo "update_type=major" >> $GITHUB_OUTPUT
@@ -83,18 +66,14 @@ jobs:
8366
8467
- name: auto-merge minor and patch updates
8568
if: steps.extract.outputs.update_type == 'minor_or_patch'
86-
# auto should set the the request to merge once checks complete
87-
# qqqq could squash for cleaner? --squash "${{ github.event.pull_request.html_url }}"
88-
# run: gh pr merge --auto 1
89-
run: gh pr merge --auto --merge ${{ github.event.check_suite.pull_requests[0].number }}
69+
run: |
70+
gh pr merge --auto --merge "${{ github.event.pull_request.number }}"
9071
env:
91-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9273

9374
- name: auto-merge major updates
9475
if: steps.extract.outputs.update_type == 'major'
95-
# auto should set the the request to merge once checks complete
96-
# qqqq could squash for cleaner? --squash "${{ github.event.pull_request.html_url }}"
97-
# run: gh pr merge --auto 1
98-
run: gh pr merge --auto --merge ${{ github.event.check_suite.pull_requests[0].number }}
76+
run: |
77+
gh pr merge --auto --merge "${{ github.event.pull_request.number }}"
9978
env:
100-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
79+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# qqqq this does add auto merge but seems to trigger on the first set of checks git guardian (it seems),
2+
# also it calls for checks not specifically for out branch
3+
# so an approach based one the branch is likely better
4+
name: auto-merge dependabot prs into collected branch
5+
on:
6+
# pull_request:
7+
# synchronize
8+
# types: [opened, synchronize]
9+
# branches: [Automatic_version_update_dependabot] # make sure this matches your actual branch name
10+
check_suite:
11+
types: [completed]
12+
workflow_dispatch:
13+
14+
permissions:
15+
contents: write
16+
pull-requests: write
17+
checks: read
18+
19+
jobs:
20+
debug:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: debug info
24+
run: |
25+
echo "actor: ${{ github.actor }}"
26+
echo "pr title: ${{ github.event.pull_request.title }}"
27+
echo "github event_name: ${{ github.event_name }}"
28+
echo "github event_suite conlusion: ${{ github.event.check_suite.conclusion }}"
29+
echo "target branch: ${{ github.event.pull_request.base.ref }}"
30+
echo "source branch: ${{ github.event.pull_request.head.ref }}"
31+
echo "Check Suite ID: ${{ github.event.check_suite.id }}"
32+
echo "Conclusion: ${{ github.event.check_suite.conclusion }}"
33+
echo "Target Branch: ${{ github.event.check_suite.pull_requests[0].base.ref }}"
34+
echo "PR Number: ${{ github.event.check_suite.pull_requests[0].number }}"
35+
36+
- name: Dump event payload
37+
run: |
38+
echo "==== EVENT NAME ===="
39+
echo "${{ github.event_name }}"
40+
echo "==== RAW CHECK_SUITE PAYLOAD ===="
41+
echo '${{ toJson(github.event.check_suite) }}'
42+
echo "==== PRs in this check suite ===="
43+
echo '${{ toJson(github.event.check_suite.pull_requests) }}'
44+
45+
46+
auto-merge:
47+
runs-on: ubuntu-latest
48+
# if: github.event.check_suite.pull_requests[0].base.ref == 'main'
49+
# if dependabot and checks ran
50+
# if: (github.event_name != 'check_suite' || github.event.check_suite.conclusion == 'success')
51+
# qqqq put back in later if: (github.actor == 'dependabot[bot]' || github.event_name == 'workflow_dispatch')&& (github.event_name != 'check_suite' || github.event.check_suite.conclusion == 'success')
52+
53+
54+
# qqqq add in after testing && github.actor == 'dependabot[bot]'
55+
if: github.event.check_suite.conclusion == 'success' && github.event.check_suite.pull_requests[0].base.ref == 'Automatic_version_update_dependabot'
56+
steps:
57+
- name: Checkout the repository
58+
uses: actions/checkout@v3
59+
60+
- name: Set up GitHub CLI
61+
run: |
62+
# Install GitHub CLI (gh)
63+
sudo apt-get update
64+
sudo apt-get install gh
65+
66+
- name: extract update type
67+
id: extract
68+
env:
69+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
70+
run: |
71+
echo "get pr number"
72+
pr_number=${{ github.event.check_suite.pull_requests[0].number }}
73+
echo "PR title: $pr_number"
74+
# pr_title="${{ github.event.pull_request.title }}"
75+
pr_title=$(gh pr view "$pr_number" --json title --jq .title)
76+
echo "PR title: $pr_title"
77+
if [[ $pr_title == *"(major)"* ]]; then
78+
echo "update_type=major" >> $GITHUB_OUTPUT
79+
else
80+
echo "update_type=minor_or_patch" >> $GITHUB_OUTPUT
81+
fi
82+
83+
- name: auto-merge minor and patch updates
84+
if: steps.extract.outputs.update_type == 'minor_or_patch'
85+
# auto should set the the request to merge once checks complete
86+
# qqqq could squash for cleaner? --squash "${{ github.event.pull_request.html_url }}"
87+
# run: gh pr merge --auto 1
88+
run: gh pr merge --auto --merge ${{ github.event.check_suite.pull_requests[0].number }}
89+
env:
90+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
91+
92+
- name: auto-merge major updates
93+
if: steps.extract.outputs.update_type == 'major'
94+
# auto should set the the request to merge once checks complete
95+
# qqqq could squash for cleaner? --squash "${{ github.event.pull_request.html_url }}"
96+
# run: gh pr merge --auto 1
97+
run: gh pr merge --auto --merge ${{ github.event.check_suite.pull_requests[0].number }}
98+
env:
99+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)