-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
088fc1b
commit 6effd1e
Showing
5 changed files
with
92 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,10 +36,20 @@ jobs: | |
validate_orb: | ||
timeout-minutes: 5 | ||
runs-on: ubuntu-22.04 | ||
outputs: | ||
job_id: ${{ steps.get-job-id.outputs.job_id }} | ||
steps: | ||
- name: Checkout 🛎️ | ||
uses: actions/[email protected] | ||
|
||
- name: Setup Python 🔧 | ||
uses: actions/[email protected] | ||
with: | ||
python-version: ">=3.12" | ||
|
||
- name: Install CLI | ||
run: pip install mergify-cli | ||
|
||
- name: Start mockServer with expectation initializer | ||
run: | | ||
docker compose up -d | ||
|
@@ -48,23 +58,42 @@ jobs: | |
- name: Test Orb upload script | ||
id: gigid | ||
run: | | ||
export FAKE_VALID_TOKEN=fake-valid-token | ||
bash src/scripts/upload.sh >> "$GITHUB_OUTPUT" | ||
env: | ||
REPO_URL: ${{ github.server_url }}/${{ github.repository }} | ||
TOKEN: FAKE_VALID_TOKEN | ||
MERGIFY_API_URL: http://localhost:1080 | ||
MERGIFY_TOKEN: fake-valid-token | ||
FILES: zfixtures/junit_example.xml | ||
# force fake test environment | ||
CIRCLECI: true | ||
GITHUB_ACTIONS: false | ||
CIRCLE_JOB: test | ||
CIRCLE_REPOSITORY_URL: ${{ github.event.repository.html_url }} | ||
CIRCLE_SHA1: 948da8c01b17ac2164039f3150221d5cfcae7ecc | ||
FILES: zfixtures/junit_example.xml | ||
MERGIFY_API_SERVER: http://localhost:1080 | ||
|
||
- name: Check GIGID | ||
env: | ||
CI_ISSUE_GIGID: ${{ steps.gigid.outputs.CI_ISSUE_GIGID }} | ||
run: | | ||
set -e | ||
test "$CI_ISSUE_GIGID" = "1234azertyuiop" | ||
export CIRCLECI=true | ||
export GITHUB_ACTIONS=false | ||
export CIRCLE_JOB=test | ||
export CIRCLE_REPOSITORY_URL=${{ github.event.repository.html_url }} | ||
export CIRCLE_SHA1=948da8c01b17ac2164039f3150221d5cfcae7ecc | ||
bash src/scripts/upload.sh | ||
- name: Get job ID | ||
id: get-job-id | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const { data } = await github.rest.actions.listJobsForWorkflowRun({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
run_id: context.runId | ||
}); | ||
// Looks for exact match | ||
let job = data.jobs.find( | ||
(j) => j.name === context.job | ||
) | ||
if (!job) { | ||
core.error("current job not found"); | ||
} | ||
core.setOutput("job_id", String(job.id)); | ||
- name: Mockserver logs | ||
if: always() | ||
|
@@ -77,3 +106,26 @@ jobs: | |
run: | | ||
circleci orb pack src > orb.yml | ||
circleci orb validate orb.yml | ||
test-annotations: | ||
needs: validate_orb | ||
timeout-minutes: 5 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check GIGID | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const annotations = await github.rest.checks.listAnnotations({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
check_run_id: ${{ needs.validate_orb.outputs.job_id }}, | ||
}); | ||
for (const annotation of annotations.data) { | ||
if (annotation.message === "CI_ISSUE_GIGID=1234azertyuiop") { | ||
core.info(`Annotations found: ${annotation.message}`) | ||
return | ||
} | ||
} | ||
console.log(annotations) | ||
throw new Error("Annotations not found") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,36 @@ | ||
description: Upload the XML report | ||
description: Upload the Junit XML report | ||
|
||
parameters: | ||
token: | ||
type: env_var_name | ||
description: CI Issues Application Key | ||
default: MERGIFY_CI_ISSUES_TOKEN | ||
repository_url: | ||
description: | | ||
URL of the repository (should provide pipeline.trigger_parameters.github_app.repo_url) | ||
type: string | ||
description: Mergify Application Key | ||
default: MERGIFY_TOKEN | ||
report_paths: | ||
description: Paths of the XML files to upload | ||
type: string | ||
mergify_api_server: | ||
mergify_api_url: | ||
description: URL of the Mergify API | ||
type: string | ||
default: https://api.mergify.com/v1 | ||
default: https://api.mergify.com | ||
|
||
steps: | ||
- run: | ||
name: Install Python | ||
when: always | ||
command: | | ||
sudo apt-get update | ||
sudo apt-get install -y python3 | ||
- run: | ||
name: Install mergify-cli | ||
when: always | ||
command: pip install mergify-cli | ||
|
||
- run: | ||
name: Uploading the reports to Mergify CI Issues | ||
when: always | ||
environment: | ||
TOKEN: <<parameters.token>> | ||
REPO_URL: <<parameters.repository_url>> | ||
MERGIFY_API_URL: <<parameters.mergify_api_url>> | ||
MERGIFY_TOKEN: <<parameters.token>> | ||
FILES: <<parameters.report_paths>> | ||
MERGIFY_API_SERVER: <<parameters.mergify_api_server>> | ||
when: always | ||
command: <<include(scripts/upload.sh)>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,5 @@ | ||
#!/bin/bash | ||
|
||
set -x | ||
set -e -x | ||
|
||
if [[ $REPO_URL =~ ^https:\/\/github\.com\/([a-zA-Z0-9._-]+)\/([a-zA-Z0-9._-]+)$ ]]; then | ||
REPO_FULL_NAME=${BASH_REMATCH[1]}/${BASH_REMATCH[2]} | ||
else | ||
echo "Invalid repository URL: $REPO_URL" | ||
exit 1 | ||
fi | ||
|
||
# Check if FILES and TOKEN are set and not empty | ||
if [ -z "${FILES}" ]; then | ||
echo "report_paths is not set or is empty" | ||
exit 1 | ||
fi | ||
if [ -z "${!TOKEN}" ]; then | ||
echo "${!TOKEN} is not set or is empty" | ||
exit 1 | ||
fi | ||
|
||
# TODO: support multiple files | ||
curl -X POST \ | ||
-H "Authorization: bearer ${!TOKEN}" \ | ||
-F name=${CIRCLE_JOB} \ | ||
-F provider=circleci \ | ||
-F head_sha=${CIRCLE_SHA1} \ | ||
-F files=@${FILES} \ | ||
-o result.json \ | ||
${MERGIFY_API_SERVER}/repos/${REPO_FULL_NAME}/ci_issues_upload \ | ||
|
||
GIGID=$(cat result.json | jq -r .gigid) | ||
echo "::notice title=CI Issues report::CI_ISSUE_GIGID=$GIGID" | ||
|
||
echo "CI_ISSUE_GIGID=$GIGID" | ||
mergify ci junit-upload "${FILES}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters