From 64e8177196f2946c0a00a03da524238495b5273a Mon Sep 17 00:00:00 2001 From: leoecrepont Date: Wed, 28 Aug 2024 08:53:22 +0200 Subject: [PATCH] chore(ci): test upload script --- .github/workflows/continuous_integration.yml | 49 ++++++----- docker-compose.yml | 10 +++ orb_old.yml | 85 ------------------- src/scripts/upload.sh | 14 +-- .../expectationInitializer.json | 2 +- .../fixtures => zfixtures}/junit_example.xml | 0 6 files changed, 42 insertions(+), 118 deletions(-) create mode 100644 docker-compose.yml delete mode 100644 orb_old.yml rename {.github/workflows/fixtures => zfixtures}/expectationInitializer.json (50%) rename {.github/workflows/fixtures => zfixtures}/junit_example.xml (100%) diff --git a/.github/workflows/continuous_integration.yml b/.github/workflows/continuous_integration.yml index d55ecc8..bf0ae69 100644 --- a/.github/workflows/continuous_integration.yml +++ b/.github/workflows/continuous_integration.yml @@ -36,35 +36,44 @@ jobs: validate_orb: timeout-minutes: 5 runs-on: ubuntu-22.04 - services: - mockServer: - image: mockserver/mockserver:5.15.0 - ports: - - 1080:1080 - volumes: - - ./fixtures:/fixtures - env: - MOCKSERVER_LOG_LEVEL: DEBUG - MOCKSERVER_INITIALIZATION_JSON_PATH: /fixtures/expectationInitialiser.json steps: - name: Checkout 🛎️ uses: actions/checkout@v4.1.7 - - name: Install CircleCI CLI - run: curl -fLSs https://raw.githubusercontent.com/CircleCI-Public/circleci-cli/main/install.sh | bash - - - name: Validate Orb + - name: Start mockServer with expectation initializer run: | - circleci orb pack src > orb.yml - circleci orb validate orb.yml + docker compose up -d + sleep 1 + docker compose logs - - name: Test Orb script + - name: Test Orb upload script + id: gigid run: | + export FAKE_VALID_TOKEN=fake-valid-token bash src/scripts/upload.sh env: - REPO_URL: https://github.com/$GITHUB_REPOSITORY - TOKEN: fake-valid-token + REPO_URL: ${{ github.server_url }}/${{ github.repository }} + TOKEN: FAKE_VALID_TOKEN CIRCLE_JOB: test CIRCLE_SHA1: 948da8c01b17ac2164039f3150221d5cfcae7ecc - FILES: junit_example.xml + 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" + + - name: Mockserver logs + if: always() + run: docker compose logs + + - name: Install CircleCI CLI + run: curl -fLSs https://raw.githubusercontent.com/CircleCI-Public/circleci-cli/main/install.sh | bash + + - name: Validate Orb + run: | + circleci orb pack src > orb.yml + circleci orb validate orb.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..9e562ee --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +services: + mockServer: + image: mockserver/mockserver:5.15.0 + ports: + - 1080:1080 + environment: + MOCKSERVER_LOG_LEVEL: DEBUG + MOCKSERVER_INITIALIZATION_JSON_PATH: /config/expectationInitializer.json + volumes: + - ./zfixtures:/config diff --git a/orb_old.yml b/orb_old.yml deleted file mode 100644 index 0dea420..0000000 --- a/orb_old.yml +++ /dev/null @@ -1,85 +0,0 @@ -version: 2.1 -description: Upload JUnit XML report to Mergify CI Issues - -commands: - upload: - description: Upload the 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 - report_paths: - description: Paths of the XML files to upload - type: string - mergify_api_server: - description: URL of the Mergify API - type: string - default: https://api.mergify.com/v1 - steps: - - run: - name: Uploading the reports to Mergify CI Issues - environment: - TOKEN: <> - REPO_URL: <> - FILES: <> - MERGIFY_API_SERVER: <> - when: always - command: | - set -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 - - # 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 \ - - echo "Display result" - cat result.json - - GIGID=$(cat result.json | jq -r .gigid) - echo "::notice title=CI Issues report::CI_ISSUE_GIGID=$GIGID" - - # echo "CI_ISSUE_GIGID=$GIGID" >> "$GITHUB_OUTPUT" - -examples: - # TODO: finish the example - example: - description: Sample example description. - usage: - version: 2.1 - orbs: - ci-issues: mergifyio/ci-issues@0.0.1 - jobs: - ci-job: - docker: - - image: cimg/ubuntu:current - steps: - - checkout - - python/install-packages: - pkg-manager: poetry - - run: pytest -v -s --junitxml=reports/junit.xml - - ci-issues/upload: - token: MERGIFY_SECRET_TOKEN - repository_url: <> - report_paths: reports/junit.xml - workflows: - continuous_integration: - jobs: - - ci-job: - context: - - test_context diff --git a/src/scripts/upload.sh b/src/scripts/upload.sh index f6ce455..1c92c55 100644 --- a/src/scripts/upload.sh +++ b/src/scripts/upload.sh @@ -1,13 +1,7 @@ #!/bin/bash -# This example uses envsubst to support variable substitution in the string parameter type. -# https://circleci.com/docs/orbs-best-practices/#accepting-parameters-as-strings-or-environment-variables - -#TO=$(circleci env subst "${PARAM_TO}") -# If for any reason the TO variable is not set, default to "World" -#echo "Hello ${TO:-World}!" - set -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 @@ -25,10 +19,6 @@ curl -X POST \ -o result.json \ ${MERGIFY_API_SERVER}/repos/${REPO_FULL_NAME}/ci_issues_upload \ -echo "Display result" -cat result.json - GIGID=$(cat result.json | jq -r .gigid) echo "::notice title=CI Issues report::CI_ISSUE_GIGID=$GIGID" - -# echo "CI_ISSUE_GIGID=$GIGID" >> "$GITHUB_OUTPUT" +echo "CI_ISSUE_GIGID=$GIGID" >> "$GITHUB_OUTPUT" diff --git a/.github/workflows/fixtures/expectationInitializer.json b/zfixtures/expectationInitializer.json similarity index 50% rename from .github/workflows/fixtures/expectationInitializer.json rename to zfixtures/expectationInitializer.json index 4c5655e..e656cf5 100644 --- a/.github/workflows/fixtures/expectationInitializer.json +++ b/zfixtures/expectationInitializer.json @@ -8,7 +8,7 @@ }, "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\ncircleci\r\n.*Content-Disposition: form-data; name=\"head_sha\"\r\n\r\n948da8c01b17ac2164039f3150221d5cfcae7ecc\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=\\\"name\\\"\\r\\n\\r\\ntest\\r\\n.*\\r\\nContent-Disposition: form-data; name=\\\"provider\\\"\\r\\n\\r\\ncircleci\\r\\n.*\\r\\nContent-Disposition: form-data; name=\\\"head_sha\\\"\\r\\n\\r\\n948da8c01b17ac2164039f3150221d5cfcae7ecc\\r\\n.*\\r\\nContent-Disposition: form-data; name=\\\"files\\\"; filename=\\\"junit_example.xml\\\"\\r\\nContent-Type: application/xml\\r\\n\\r\\n.*" } }, "httpResponse": { diff --git a/.github/workflows/fixtures/junit_example.xml b/zfixtures/junit_example.xml similarity index 100% rename from .github/workflows/fixtures/junit_example.xml rename to zfixtures/junit_example.xml