-
Notifications
You must be signed in to change notification settings - Fork 23
128 lines (113 loc) · 4.26 KB
/
merge-pr.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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
###############################################################################
# _ _ _ _ _____ _
# | | | | | | | | | __ \(_)
# | | ___ | |__ _ __ | |_| |__ ___ | |__) |_ _ __ _ __ ___ _ __
# _ | |/ _ \| '_ \| '_ \ | __| '_ \ / _ \ | _ /| | '_ \| '_ \ / _ \ '__|
# | |__| | (_) | | | | | | | | |_| | | | __/ | | \ \| | |_) | |_) | __/ |
# \____/ \___/|_| |_|_| |_| \__|_| |_|\___| |_| \_\_| .__/| .__/ \___|_|
# | | | |
# |_| |_|
#
# Copyright (c) 2024 Claudio André <[email protected]>
#
# This program comes with ABSOLUTELY NO WARRANTY; express or implied.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, as expressed in version 2, seen at
# http://www.gnu.org/licenses/gpl-2.0.html
###############################################################################
# GitHub Action that performs the actual merge
# More info at https://github.com/openwall/john-packages
---
name: doMerge
"on":
workflow_call:
inputs:
branch:
description: "The name of the branch to be merged."
required: false
type: string
owner:
description: "The owner of the repository the PR comes from"
required: false
type: string
repo:
description: "The name of the repository the PR comes from"
required: false
type: string
pr-number:
description: "The number of the PR to merge"
required: true
type: number
request:
description: "The command to be executed"
required: true
type: string
permissions:
contents: read
jobs:
merger:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
if: github.actor == 'claudioandre-br' || github.actor == 'solardiz'
steps:
- name: Harden Runner
uses: step-security/harden-runner@4d991eb9b905ef189e4c376166672c3f2f230481 # v2.11.0
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
api.github.com:443
github.com:443
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
ref: main
- name: GitHub context
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Get PR info
id: context
run: |
PR_URL="https://github.com/openwall/john-packages/pull/$PR_NUMBER"
if [[ -z "${{ inputs.branch }}" ]]; then
BRANCH="$(gh pr view "$PR_URL" --json headRefName --jq '.headRefName')"
OWNER="$(gh pr view "$PR_URL" --json headRepositoryOwner --jq '.headRepositoryOwner.login')"
REPO="$(gh pr view "$PR_URL" --json headRepository --jq '.headRepository.name')"
else
BRANCH="${{ inputs.branch }}"
OWNER="${{ inputs.owner }}"
REPO="${{ inputs.repo }}"
fi
if [[ "${{ inputs.request }}" == "true" ]]; then
REQUEST="bot: MERGE trial"
elif [[ "${{ inputs.request }}" == "false" ]]; then
REQUEST="bot: MERGE"
else
REQUEST="${{ inputs.request }}"
fi
{
echo "branch=$BRANCH"
echo "owner=$OWNER"
echo "repo=$REPO"
echo "pr-url=$PR_URL"
echo "request=$REQUEST"
} >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ inputs.pr-number }}
- name: Auto-merge PRs
run: |
export BRANCH="${{ steps.context.outputs.branch }}"
export OWNER="${{ steps.context.outputs.owner }}"
export REPO="${{ steps.context.outputs.repo }}"
export PR_URL="${{ steps.context.outputs.pr-url }}"
export REQUEST="${{ steps.context.outputs.request }}"
source "./scripts/merge_procedures.sh" # @main
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}