Skip to content

Commit

Permalink
refactor: use mergify-cli (#19)
Browse files Browse the repository at this point in the history
uses the new cli to upload the reports

Related to: MRGFY-4340
Depends-On: Mergifyio/mergify-cli#550
  • Loading branch information
lecrepont01 authored Dec 3, 2024
1 parent 7a9465e commit 9646b77
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 55 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
with:
token: fake-valid-token
report_paths: zfixtures/junit_example.xml
mergify_api_server: http://localhost:1080
mergify_api_url: http://localhost:1080

- name: Get job ID
id: get-job-id
Expand All @@ -77,17 +77,14 @@ jobs:
}
core.setOutput("job_id", String(job.id));
- name: Clear result file
run: rm result.json

- name: Run action with error scenario ❌
id: error500
continue-on-error: true
uses: ./
with:
token: fake-valid-token
report_paths: zfixtures/junit_example.xml
mergify_api_server: http://localhost:1085
mergify_api_url: http://localhost:1085

- name: Check error was reported
if: ${{ steps.error500.outcome == 'success' }}
Expand Down
63 changes: 16 additions & 47 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,60 +11,29 @@ inputs:
report_paths:
required: true
description: Paths of the files to upload
mergify_api_server:
mergify_api_url:
required: false
description: URL of the Mergify API
default: https://api.mergify.com/v1
name:
description: Name of the current workflow job
default: https://api.mergify.com
runs:
using: composite
steps:
- name: Setup Python 🔧
uses: actions/setup-python@v5.3.0
with:
python-version: 3.12.7

- name: Install dependencies
shell: bash
run: |
pip install mergify-cli
- shell: bash
id: gigid
env:
MERGIFY_API_SERVER: ${{ inputs.mergify_api_server }}
MERGIFY_CI_ISSUES_TOKEN: ${{ inputs.token }}
MERGIFY_API_URL: ${{ inputs.mergify_api_url }}
MERGIFY_TOKEN: ${{ inputs.token }}
FILES: ${{ inputs.report_paths }}
REPOSITORY: ${{ github.repository }}
HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
WORKFLOW_JOB_NAME: ${{ inputs.name || github.job }}
run: |
set -x
# Check if FILES and MERGIFY_CI_ISSUES_TOKEN are set and not empty
if [ -z "$FILES" ]; then
echo "::error:: report_paths is not set or is empty"
exit 1
fi
if [ -z "$MERGIFY_CI_ISSUES_TOKEN" ]; then
echo "::error:: token is not set or is empty"
exit 1
fi
set +e
# TODO(sileht): support multiple files
curl -X POST \
--fail \
-v \
-H "Authorization: bearer ${MERGIFY_CI_ISSUES_TOKEN}" \
-F name=${WORKFLOW_JOB_NAME} \
-F provider=github_action \
-F head_sha=${HEAD_SHA} \
-F files=@${FILES} \
-o result.json \
${MERGIFY_API_SERVER}/repos/${REPOSITORY}/ci_issues_upload
if [ $? = 22 ]; then
echo "Upload failed"
test -f result.json && cat result.json
exit 22
fi
set -e
GIGID=$(jq -r .gigid result.json)
echo "::notice title=CI Issues report::CI_ISSUE_GIGID=$GIGID"
set -x -e
mergify ci junit-upload "${FILES}"
6 changes: 3 additions & 3 deletions zfixtures/fake-ci-issue-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
{
"httpRequest": {
"method": "POST",
"path": "/repos/Mergifyio/gha-ci-issues/ci_issues_upload",
"path": "/v1/repos/Mergifyio/gha-ci-issues/ci_issues_upload",
"headers": {
"Authorization": "bearer fake-valid-token"
"Authorization": "Bearer fake-valid-token"
},
"body": {
"type": "REGEX",
"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.*"
"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.*"
}
},
"httpResponse": {
Expand Down

0 comments on commit 9646b77

Please sign in to comment.