-
Notifications
You must be signed in to change notification settings - Fork 2
167 lines (143 loc) · 5.41 KB
/
issue_to_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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
name: Issue to Pull Request
on:
issues:
types:
- opened
- edited
- reopened
if: contains(github.event.issue.labels.*.name, 'new contribution')
permissions:
contents: write
issues: write
pull-requests: write
jobs:
validate:
runs-on: ubuntu-latest
outputs:
props: ${{ steps.parseProps.outputs.props }}
comment-id: ${{ steps.issueComment.outputs.comment-id }}
steps:
- name: Parse issue
id: parseIssue
uses: onmax/[email protected]
with:
issue_number: ${{ github.event.issue.number }}
- name: Checkout sources
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Install dependencies
run: pip install -r requirements.txt
- name: Determine category from labels
id: determineCategory
run: |
category=$(
if [[ $(echo "${{ github.event.issue.labels.*.name }}" | grep -q 'examples') ]]; then
echo 'examples'
elif [[ $(echo "${{ github.event.issue.labels.*.name }}" | grep -q 'mode') ]]; then
echo 'mode'
elif [[ $(echo "${{ github.event.issue.labels.*.name }}" | grep -q 'tool') ]]; then
echo 'tool'
elif [[ $(echo "${{ github.event.issue.labels.*.name }}" | grep -q 'library') ]]; then
echo 'library'
fi
)
echo "category=$category" >> $GITHUB_OUTPUT
- name: Debug payload
run: echo "${{ steps.parseIssue.outputs.payload }}"
- name: Validate properties URL
id: validateUrl
run: |
properties_url="${{ fromJson(steps.parseIssue.outputs.payload)['Properties File URL'] }}"
if [ -z "$properties_url"; then
echo "Properties URL is empty. Please provide a valid URL."
exit 1
fi
if ! curl --output /dev/null --silent --head --fail "$properties_url"; then
echo "Url not valid: $properties_url"
exit 1
fi
- name: Read and validate properties txt file
id: parseProps
run: |
properties_url="${{ fromJson(steps.parseIssue.outputs.payload)['Properties File URL'] }}"
python -u scripts/parse_and_validate_properties_txt.py \
${{ steps.determineCategory.outputs.category }} \
"$properties_url"
- name: add comment to issue
id: issueComment
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.issue.number }}
body: |
Your properties file was successfully parsed.
- name: if failure, add comment to issue
if: failure()
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.issue.number }}
body: |
There was an error in reading your properties file or parsing it.
Please ensure that the URL is correct and the file follows the required format.
${{ steps.parseProps.outputs.error }}
create-pr:
needs: validate
env:
BRANCH_NAME: issue-${{ github.event.issue.number }}
ISSUE_NUM: ${{ github.event.issue.number }}
ISSUE_TITLE: ${{ github.event.issue.title }}
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Install dependencies
run: pip install -r requirements.txt
- name: check if target branch exists
id: branchExists
uses: GuillaumeFalourd/branch-exists@v1
with:
branch: ${{ env.BRANCH_NAME }}
- name: delete target branch if exists
if: steps.branchExists.outputs.exists == 'true'
uses: dawidd6/action-delete-branch@v3
with:
github_token: ${{github.token}}
branches: ${{ env.BRANCH_NAME }}
- name: create branch
env:
GH_TOKEN: ${{ github.token }}
run: gh issue develop $ISSUE_NUM --name $BRANCH_NAME --checkout
- name: edit database
run: |
cd scripts
python add_new_contribution_to_yaml.py '${{ needs.validate.outputs.props }}'
- name: commit changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: new contribution from issue ${{ env.ISSUE_NUM }}
branch: ${{ env.BRANCH_NAME }}
add_options: '-u'
- name: Create pull request
run: gh pr create -B main -H $BRANCH_NAME --title "new contribution issue $ISSUE_NUM" --body "${{github.event.issue.title }}"
env:
GH_TOKEN: ${{ github.token }}
- name: add comment to issue
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ needs.validate.outputs.comment-id }}
body: |
A pull request with your contribution has been successfully created.
- name: if failure, add comment to issue
if: failure()
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ needs.validate.outputs.comment-id }}
body: |
An error was encountered when adding your contribution.
We will look into this issue as soon as possible. Please check the details of your submission and try again if necessary.