-
Notifications
You must be signed in to change notification settings - Fork 3
89 lines (83 loc) · 2.65 KB
/
auto-merge.yml
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
name: Tests and Dependabot PR Handling
on:
pull_request:
branches:
- master
- main
jobs:
# Verifies the boilerplate can start and run in GitHub Actions environment
test-for-workflow:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run tests
uses: cypress-io/github-action@v5
with:
build: npm run build
start: npm run start
# Verifies the boilerplate can start and run in codespace environment
test-for-codespaces:
permissions:
contents: read
packages: read
container:
image: ghcr.io/devskillshq/boilerplate-base-image:latest
credentials:
username: ${{ github.actor }}
password: ${{ secrets.github_token }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install
run: npm install
- name: Build
run: npm run build
- name: Start daemon
run: npm run start &
- name: Run tests
run: npm run test
check-dependabot:
needs:
- test-for-workflow
- test-for-codespaces
runs-on: ubuntu-20.04
outputs:
is_dependabot_pr: ${{ steps.dependabot-check.outputs.is_dependabot_pr }}
steps:
- id: dependabot-check
name: Check if PR is from Dependabot
run: |
echo "PR author: ${{ github.event.pull_request.user.login }}"
if [[ "${{ github.event.pull_request.user.login }}" == "dependabot[bot]" || "${{ github.event.pull_request.user.login }}" == "dependabot-preview[bot]" ]]; then
echo "::set-output name=is_dependabot_pr::true"
else
echo "::set-output name=is_dependabot_pr::false"
fi
auto-merge:
needs: check-dependabot
runs-on: ubuntu-20.04
if: ${{ needs.check-dependabot.outputs.is_dependabot_pr == 'true' }}
steps:
- name: Merge pull request
uses: actions/github-script@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pull_number = context.payload.pull_request.number;
await github.rest.pulls.merge({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pull_number
});
- name: Delete branch
uses: actions/github-script@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const branch_name = context.payload.pull_request.head.ref;
await github.rest.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'heads/' + branch_name
});