-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
127 lines (123 loc) · 3.81 KB
/
action.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
---
name: "Create PR"
description: 'Commit and create PR'
inputs:
base:
description: 'Base branch to create PR against'
required: true
default: 'main'
token:
description: 'PAT for creating PR'
required: true
add-paths:
description: 'Paths to add to commit'
required: false
default: '.'
commit-message:
description: 'Commit message'
required: false
default: 'Automated commit'
pr-branch:
description: 'Branch to create PR from'
required: false
default: 'automated-pr'
pr-title:
description: 'PR title'
required: false
default: 'Automated PR'
pr-body:
description: 'PR body'
required: false
default: 'Automated PR'
pr-condition-cmd:
description: 'Command to check if PR should be created'
required: false
default: git status --porcelain
pr-assignee:
description: 'Default assignee for the Pull rrequest'
required: false
default: null
pr-automerge:
description: 'Whether to automatically merge the Pull Request'
required: false
default: 'false'
commit-user:
description: 'Username to use for commit'
required: false
default: 'Forgejo Bot'
commit-email:
description: 'Email to use for commit'
required: false
default: 'forgejo@users.noreply.git'
runs:
using: "composite"
steps:
- run: |
git config --global user.name "${{ inputs.commit-user }}" >> $GITHUB_OUTPUT
git config --global user.email "${{ inputs.commit-email }}" >> $GITHUB_OUTPUT
shell: bash
name: "Configure git"
- name: "Pre-setup"
run: |
git fetch --all
git checkout -b "${{ inputs.pr-branch }}"
shell: bash
- name: "Check changes"
id: git
shell: bash
run: |
if [[ -n "$(git status --porcelain)" ]]; then
echo changes=true >> $GITHUB_OUTPUT
else
echo changes=false >> $GITHUB_OUTPUT
fi
- name: "Commit and create PR"
if: steps.git.outputs.changes == 'true'
id: commit
shell: bash
env:
REPO: ${{ github.repository }}
run: |
git add ${{ inputs.add-paths }}
git commit -m "${{ inputs.commit-message }}"
git push --force-with-lease origin "${{ inputs.pr-branch }}"
echo "URL: $GITHUB_SERVER_URL/api/v1/repos/$REPO/pulls"
response=$(curl -X 'POST' \
"$GITHUB_SERVER_URL/api/v1/repos/$REPO/pulls" \
-H 'accept: application/json' \
-H 'Authorization: token ${{ inputs.token }}' \
-H 'Content-Type: application/json' \
-d '{
"assignee": "${{ inputs.pr-asignee }}",
"base": "${{ inputs.base }}",
"body": "${{ inputs.pr-body }}",
"head": "${{ inputs.pr-branch }}",
"title": "${{ inputs.pr-title }}"
}')
# echo $response | jq .
pr_number=$(echo $response | jq -r '.number')
echo "PR Number: $pr_number"
echo pr_number=$pr_number >> $GITHUB_OUTPUT
- name: "Auto merge PR"
shell: bash
if: steps.git.outputs.changes == 'true' && steps.commit.outputs.pr_number != 'null'
env:
PR_NUMBER: ${{ steps.commit.outputs.pr_number }}
REPO: ${{ github.repository }}
run: |
echo "Settig auto merge for PR $PR_NUMBER"
echo "URL: $GITHUB_SERVER_URL/api/v1/repos/$REPO/pulls/$PR_NUMBER/merge"
response=$(curl -X 'POST' \
"$GITHUB_SERVER_URL/api/v1/repos/$REPO/pulls/$PR_NUMBER/merge" \
-H 'accept: application/json' \
-H 'Authorization: token ${{ inputs.token }}' \
-H 'Content-Type: application/json' \
-d '{
"Do": "merge",
"merge_when_checks_succeed": true,
"delete_branch_after_merge": true
}')
echo $response
branding:
icon: 'check'
color: 'blue'