Skip to content

Commit 9646b77

Browse files
authored
refactor: use mergify-cli (#19)
uses the new cli to upload the reports Related to: MRGFY-4340 Depends-On: Mergifyio/mergify-cli#550
1 parent 7a9465e commit 9646b77

File tree

3 files changed

+21
-55
lines changed

3 files changed

+21
-55
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
with:
5757
token: fake-valid-token
5858
report_paths: zfixtures/junit_example.xml
59-
mergify_api_server: http://localhost:1080
59+
mergify_api_url: http://localhost:1080
6060

6161
- name: Get job ID
6262
id: get-job-id
@@ -77,17 +77,14 @@ jobs:
7777
}
7878
core.setOutput("job_id", String(job.id));
7979
80-
- name: Clear result file
81-
run: rm result.json
82-
8380
- name: Run action with error scenario ❌
8481
id: error500
8582
continue-on-error: true
8683
uses: ./
8784
with:
8885
token: fake-valid-token
8986
report_paths: zfixtures/junit_example.xml
90-
mergify_api_server: http://localhost:1085
87+
mergify_api_url: http://localhost:1085
9188

9289
- name: Check error was reported
9390
if: ${{ steps.error500.outcome == 'success' }}

action.yml

Lines changed: 16 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,60 +11,29 @@ inputs:
1111
report_paths:
1212
required: true
1313
description: Paths of the files to upload
14-
mergify_api_server:
14+
mergify_api_url:
1515
required: false
1616
description: URL of the Mergify API
17-
default: https://api.mergify.com/v1
18-
name:
19-
description: Name of the current workflow job
17+
default: https://api.mergify.com
2018
runs:
2119
using: composite
2220
steps:
21+
- name: Setup Python 🔧
22+
uses: actions/setup-python@v5.3.0
23+
with:
24+
python-version: 3.12.7
25+
26+
- name: Install dependencies
27+
shell: bash
28+
run: |
29+
pip install mergify-cli
30+
2331
- shell: bash
2432
id: gigid
2533
env:
26-
MERGIFY_API_SERVER: ${{ inputs.mergify_api_server }}
27-
MERGIFY_CI_ISSUES_TOKEN: ${{ inputs.token }}
34+
MERGIFY_API_URL: ${{ inputs.mergify_api_url }}
35+
MERGIFY_TOKEN: ${{ inputs.token }}
2836
FILES: ${{ inputs.report_paths }}
29-
REPOSITORY: ${{ github.repository }}
30-
HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
31-
WORKFLOW_JOB_NAME: ${{ inputs.name || github.job }}
3237
run: |
33-
set -x
34-
35-
# Check if FILES and MERGIFY_CI_ISSUES_TOKEN are set and not empty
36-
if [ -z "$FILES" ]; then
37-
echo "::error:: report_paths is not set or is empty"
38-
exit 1
39-
fi
40-
41-
if [ -z "$MERGIFY_CI_ISSUES_TOKEN" ]; then
42-
echo "::error:: token is not set or is empty"
43-
exit 1
44-
fi
45-
46-
set +e
47-
48-
# TODO(sileht): support multiple files
49-
curl -X POST \
50-
--fail \
51-
-v \
52-
-H "Authorization: bearer ${MERGIFY_CI_ISSUES_TOKEN}" \
53-
-F name=${WORKFLOW_JOB_NAME} \
54-
-F provider=github_action \
55-
-F head_sha=${HEAD_SHA} \
56-
-F files=@${FILES} \
57-
-o result.json \
58-
${MERGIFY_API_SERVER}/repos/${REPOSITORY}/ci_issues_upload
59-
60-
if [ $? = 22 ]; then
61-
echo "Upload failed"
62-
test -f result.json && cat result.json
63-
exit 22
64-
fi
65-
66-
set -e
67-
68-
GIGID=$(jq -r .gigid result.json)
69-
70-
echo "::notice title=CI Issues report::CI_ISSUE_GIGID=$GIGID"
38+
set -x -e
39+
mergify ci junit-upload "${FILES}"

zfixtures/fake-ci-issue-api.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
{
33
"httpRequest": {
44
"method": "POST",
5-
"path": "/repos/Mergifyio/gha-ci-issues/ci_issues_upload",
5+
"path": "/v1/repos/Mergifyio/gha-ci-issues/ci_issues_upload",
66
"headers": {
7-
"Authorization": "bearer fake-valid-token"
7+
"Authorization": "Bearer fake-valid-token"
88
},
99
"body": {
1010
"type": "REGEX",
11-
"regex": ".*Content-Disposition: form-data; name=\"name\"\r\n\r\ntest\r\n.*Content-Disposition: form-data; name=\"provider\"\r\n\r\ngithub_action\r\n.*Content-Disposition: form-data; name=\"files\"; filename=\"junit_example.xml\"\r\nContent-Type: application/xml\r\n\r\n.*"
11+
"regex": ".*Content-Disposition: form-data; name=\\\"head_sha\\\"\\r\\n\\r\\n.*\\r\\n.*\\r\\nContent-Disposition: form-data; name=\"name\"\r\n\r\nContinuous Integration\r\n.*Content-Disposition: form-data; name=\"provider\"\r\n\r\ngithub_action\r\n.*Content-Disposition: form-data; name=\"files\"; filename=\"junit_example.xml\"\r\nContent-Type: application/xml\r\n\r\n.*"
1212
}
1313
},
1414
"httpResponse": {

0 commit comments

Comments
 (0)