From 2556f7f46b626139547d515898aa521369561bd3 Mon Sep 17 00:00:00 2001 From: Hippolyte HENRY Date: Tue, 1 Jun 2021 13:33:08 +0200 Subject: [PATCH 1/4] Add step to get token --- .github/workflows/test_integration.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/test_integration.yml b/.github/workflows/test_integration.yml index 4012299304b..b6f79fa493c 100644 --- a/.github/workflows/test_integration.yml +++ b/.github/workflows/test_integration.yml @@ -32,6 +32,13 @@ jobs: DD_HOSTNAME: "none" DD_INSIDE_CI: "true" steps: + - name: Get GitHub App token + id: get_token + uses: tibdex/github-app-token@v1.0.2 + with: + app_id: ${{ secrets.PIPELINE_GITHUB_APP_ID }} + private_key: ${{ secrets.PIPELINE_GITHUB_APP_SECRET }} + repository: DataDog/datadog-api-spec - name: Install Go uses: actions/setup-go@v2 with: From 1535b93d224a385149916c9de4dd6c2e1b9769d8 Mon Sep 17 00:00:00 2001 From: Hippolyte HENRY Date: Tue, 1 Jun 2021 13:52:18 +0200 Subject: [PATCH 2/4] Send status checks back to spec PR --- .github/workflows/scripts/test_integration.js | 23 +++++++++ .github/workflows/test_integration.yml | 49 ++++++++++++++----- 2 files changed, 59 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/scripts/test_integration.js diff --git a/.github/workflows/scripts/test_integration.js b/.github/workflows/scripts/test_integration.js new file mode 100644 index 00000000000..d1555b8e89b --- /dev/null +++ b/.github/workflows/scripts/test_integration.js @@ -0,0 +1,23 @@ +module.exports.post_status_check = async (github, context, status) => { + const pr_num = context.payload.pull_request.head.ref.split("/")[2] + const {data: pr} = await github.pulls.get({ + owner: context.repo.owner, + repo: "datadog-api-spec", + pull_number: pr_num, + }); + const { data: jobs } = await github.actions.listJobsForWorkflowRun({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: context.runId + }); + await github.repos.createCommitStatus({ + owner: context.repo.owner, + repo: "datadog-api-spec", + sha: pr.head.sha, + state: status, + target_url: `https://github.com/DataDog/datadog-api-client-go/pull/973/checks?check_run_id=${jobs.jobs[0].id}`, + description: `${context.repo.repo} integration tests`, + context: `${context.repo.repo}_integration_tests` + }); + +} diff --git a/.github/workflows/test_integration.yml b/.github/workflows/test_integration.yml index b6f79fa493c..10b8ce5a44a 100644 --- a/.github/workflows/test_integration.yml +++ b/.github/workflows/test_integration.yml @@ -22,29 +22,36 @@ jobs: !contains(github.event.pull_request.head.ref, 'datadog-api-spec/test/') && contains(github.event.pull_request.labels.*.name, 'ci/integrations')) || github.event_name == 'schedule' - services: - datadog-agent: - image: datadog/agent:latest - ports: - - 8126:8126 - env: - DD_API_KEY: ${{ secrets.DD_API_KEY }} - DD_HOSTNAME: "none" - DD_INSIDE_CI: "true" +# services: +# datadog-agent: +# image: datadog/agent:latest +# ports: +# - 8126:8126 +# env: +# DD_API_KEY: ${{ secrets.DD_API_KEY }} +# DD_HOSTNAME: "none" +# DD_INSIDE_CI: "true" steps: - name: Get GitHub App token id: get_token - uses: tibdex/github-app-token@v1.0.2 + uses: tibdex/github-app-token@v1.3.0 with: app_id: ${{ secrets.PIPELINE_GITHUB_APP_ID }} - private_key: ${{ secrets.PIPELINE_GITHUB_APP_SECRET }} + private_key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }} repository: DataDog/datadog-api-spec + - name: Checkout code + uses: actions/checkout@v2 + - name: Post pending status check + uses: actions/github-script@v4.0.2 + with: + github-token: ${{ steps.get_token.outputs.token }} + script: | + const script = require('.github/workflows/scripts/test_integration.js') + await script.post_status_check(github, context, "pending") - name: Install Go uses: actions/setup-go@v2 with: go-version: 1.16.x - - name: Checkout code - uses: actions/checkout@v2 - name: Run integration tests shell: bash run: ./run-tests.sh @@ -57,3 +64,19 @@ jobs: DD_TEST_CLIENT_API_KEY: ${{ secrets.DD_CLIENT_API_KEY }} DD_TEST_CLIENT_APP_KEY: ${{ secrets.DD_CLIENT_APP_KEY }} RECORD: "none" + - name: Post failure status check + if: failure() + uses: actions/github-script@v4.0.2 + with: + github-token: ${{ steps.get_token.outputs.token }} + script: | + const script = require('./.github/workflows/scripts/test_integration.js') + await script.post_status_check(github, context, "failure") + - name: Post success status check + if: "!failure()" + uses: actions/github-script@v4.0.2 + with: + github-token: ${{ steps.get_token.outputs.token }} + script: | + const script = require('./.github/workflows/scripts/test_integration.js') + await script.post_status_check(github, context, "success") From df07d341d4de4dac9d7dbe71dcdb9b2c3850b783 Mon Sep 17 00:00:00 2001 From: Hippolyte HENRY Date: Wed, 2 Jun 2021 09:10:18 +0200 Subject: [PATCH 3/4] Remove comments, details --- .github/workflows/scripts/test_integration.js | 9 +++---- .github/workflows/test_integration.yml | 24 ++++++++++--------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/.github/workflows/scripts/test_integration.js b/.github/workflows/scripts/test_integration.js index d1555b8e89b..8b6542bb4d3 100644 --- a/.github/workflows/scripts/test_integration.js +++ b/.github/workflows/scripts/test_integration.js @@ -1,8 +1,10 @@ +const SPEC_REPO = "datadog-api-spec" + module.exports.post_status_check = async (github, context, status) => { const pr_num = context.payload.pull_request.head.ref.split("/")[2] const {data: pr} = await github.pulls.get({ owner: context.repo.owner, - repo: "datadog-api-spec", + repo: SPEC_REPO, pull_number: pr_num, }); const { data: jobs } = await github.actions.listJobsForWorkflowRun({ @@ -12,12 +14,11 @@ module.exports.post_status_check = async (github, context, status) => { }); await github.repos.createCommitStatus({ owner: context.repo.owner, - repo: "datadog-api-spec", + repo: SPEC_REPO, sha: pr.head.sha, state: status, - target_url: `https://github.com/DataDog/datadog-api-client-go/pull/973/checks?check_run_id=${jobs.jobs[0].id}`, + target_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/pull/${context.payload.pull_request.number}/checks?check_run_id=${jobs.jobs[0].id}`, description: `${context.repo.repo} integration tests`, context: `${context.repo.repo}_integration_tests` }); - } diff --git a/.github/workflows/test_integration.yml b/.github/workflows/test_integration.yml index 10b8ce5a44a..ade1795dc7d 100644 --- a/.github/workflows/test_integration.yml +++ b/.github/workflows/test_integration.yml @@ -22,17 +22,18 @@ jobs: !contains(github.event.pull_request.head.ref, 'datadog-api-spec/test/') && contains(github.event.pull_request.labels.*.name, 'ci/integrations')) || github.event_name == 'schedule' -# services: -# datadog-agent: -# image: datadog/agent:latest -# ports: -# - 8126:8126 -# env: -# DD_API_KEY: ${{ secrets.DD_API_KEY }} -# DD_HOSTNAME: "none" -# DD_INSIDE_CI: "true" + services: + datadog-agent: + image: datadog/agent:latest + ports: + - 8126:8126 + env: + DD_API_KEY: ${{ secrets.DD_API_KEY }} + DD_HOSTNAME: "none" + DD_INSIDE_CI: "true" steps: - name: Get GitHub App token + if: github.event_name == 'pull_request' id: get_token uses: tibdex/github-app-token@v1.3.0 with: @@ -42,6 +43,7 @@ jobs: - name: Checkout code uses: actions/checkout@v2 - name: Post pending status check + if: github.event_name == 'pull_request' uses: actions/github-script@v4.0.2 with: github-token: ${{ steps.get_token.outputs.token }} @@ -65,7 +67,7 @@ jobs: DD_TEST_CLIENT_APP_KEY: ${{ secrets.DD_CLIENT_APP_KEY }} RECORD: "none" - name: Post failure status check - if: failure() + if: failure() && github.event_name == 'pull_request' uses: actions/github-script@v4.0.2 with: github-token: ${{ steps.get_token.outputs.token }} @@ -73,7 +75,7 @@ jobs: const script = require('./.github/workflows/scripts/test_integration.js') await script.post_status_check(github, context, "failure") - name: Post success status check - if: "!failure()" + if: "!failure() && github.event_name == 'pull_request'" uses: actions/github-script@v4.0.2 with: github-token: ${{ steps.get_token.outputs.token }} From aad372fb09995f7afdd3dc03a212bb2940bea654 Mon Sep 17 00:00:00 2001 From: "ci.datadog-api-spec" Date: Thu, 3 Jun 2021 12:21:47 +0000 Subject: [PATCH 4/4] Regenerate client from commit 379360f of spec repo --- .apigentools-info | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.apigentools-info b/.apigentools-info index 9f1df561c84..f7f0fa9d666 100644 --- a/.apigentools-info +++ b/.apigentools-info @@ -4,13 +4,13 @@ "spec_versions": { "v1": { "apigentools_version": "1.4.1.dev8", - "regenerated": "2021-06-03 07:59:24.677012", - "spec_repo_commit": "6c05087" + "regenerated": "2021-06-03 12:21:12.869496", + "spec_repo_commit": "379360f" }, "v2": { "apigentools_version": "1.4.1.dev8", - "regenerated": "2021-06-03 07:59:57.715981", - "spec_repo_commit": "6c05087" + "regenerated": "2021-06-03 12:21:46.073810", + "spec_repo_commit": "379360f" } } } \ No newline at end of file