From 1b6b0a71a575f3c8bf26cbfe73ea48f7fb29509c Mon Sep 17 00:00:00 2001 From: Charlie McBride <33269602+charliedmcb@users.noreply.github.com> Date: Thu, 9 Nov 2023 12:06:32 -0800 Subject: [PATCH] test(e2e): improving the E2E flow to make E2E references not get removed on approval (#18) * update trigger in mainline * update workflows * Revert "update trigger in mainline" This reverts commit e1e0d9c5eac86e5a8ed52b98a951d32a77fbebd8. * add download artifact action * switch back to test to make sure it aligns with old approval comment * add new lines --------- Co-authored-by: Charlie McBride --- .github/actions/commit-status/end/action.yaml | 36 +++++++++++++++++++ .../actions/commit-status/start/action.yaml | 24 +++++++++++++ .github/actions/download-artifact/action.yaml | 32 +++++++++++++++++ .github/workflows/approval-comment.yaml | 17 +++++++-- .github/workflows/e2e-matrix-trigger.yaml | 12 +++++-- .github/workflows/e2e-matrix.yaml | 5 ++- .github/workflows/e2e.yaml | 13 +++++++ .github/workflows/resolve-args.yaml | 23 ++++++++++++ 8 files changed, 155 insertions(+), 7 deletions(-) create mode 100644 .github/actions/commit-status/end/action.yaml create mode 100644 .github/actions/commit-status/start/action.yaml create mode 100644 .github/actions/download-artifact/action.yaml create mode 100644 .github/workflows/resolve-args.yaml diff --git a/.github/actions/commit-status/end/action.yaml b/.github/actions/commit-status/end/action.yaml new file mode 100644 index 000000000..5be44633a --- /dev/null +++ b/.github/actions/commit-status/end/action.yaml @@ -0,0 +1,36 @@ +name: CommitStatusEnd +description: 'Adds a commit status at the end of the test run based on success, failure, or cancelled' +inputs: + name: + description: "Name of the check" + required: true + git_ref: + description: "The git commit, tag, or branch to check out. Requires a corresponding Karpenter snapshot release" + required: true +runs: + using: "composite" + steps: + - uses: actions/github-script@v6 + if: job.status == 'success' + with: + script: | + github.rest.repos.createCommitStatus({ + owner: context.repo.owner, + repo: context.repo.repo, + context: "${{ inputs.name }}", + sha: "${{ inputs.git_ref }}", + state: "success", + target_url: "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}", + }); + - uses: actions/github-script@v6 + if: job.status == 'failure' || job.status == 'cancelled' + with: + script: | + github.rest.repos.createCommitStatus({ + owner: context.repo.owner, + repo: context.repo.repo, + context: "${{ inputs.name }}", + sha: "${{ inputs.git_ref }}", + state: "failure", + target_url: "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}", + }); diff --git a/.github/actions/commit-status/start/action.yaml b/.github/actions/commit-status/start/action.yaml new file mode 100644 index 000000000..1a4516917 --- /dev/null +++ b/.github/actions/commit-status/start/action.yaml @@ -0,0 +1,24 @@ +name: CommitStatusStart +description: 'Adds a commit status at the start of the test run to set the status to pending' +inputs: + name: + description: "Name of the check" + required: true + git_ref: + description: "The git commit, tag, or branch to check out" + required: true +runs: + using: "composite" + steps: + - uses: actions/github-script@v6 + if: always() + with: + script: | + github.rest.repos.createCommitStatus({ + owner: context.repo.owner, + repo: context.repo.repo, + context: "${{ inputs.name }}", + sha: "${{ inputs.git_ref }}", + state: "pending", + target_url: "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}", + }); diff --git a/.github/actions/download-artifact/action.yaml b/.github/actions/download-artifact/action.yaml new file mode 100644 index 000000000..bc7e29d5f --- /dev/null +++ b/.github/actions/download-artifact/action.yaml @@ -0,0 +1,32 @@ +name: DownloadArtifacts +description: 'Downloads and unarchives artifacts for a workflow that runs on workflow_run so that it can use its data' +runs: + using: "composite" + steps: + - uses: actions/github-script@v6 + with: + script: | + let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: context.payload.workflow_run.id, + }); + let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { + return artifact.name == "artifacts" + })[0]; + let download = await github.rest.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', + }); + let fs = require('fs'); + fs.writeFileSync(`/tmp/artifacts.zip`, Buffer.from(download.data)); + - run: | + mkdir -p /tmp/artifacts + unzip /tmp/artifacts.zip -d /tmp/artifacts + shell: bash + - run: | + echo "Downloaded artifacts:" + ls -ablh /tmp/artifacts + shell: bash diff --git a/.github/workflows/approval-comment.yaml b/.github/workflows/approval-comment.yaml index dd9aab2f8..d7129ab89 100644 --- a/.github/workflows/approval-comment.yaml +++ b/.github/workflows/approval-comment.yaml @@ -5,9 +5,20 @@ on: jobs: approval-comment: - if: startsWith(github.event.review.body, '/e2e') + if: startsWith(github.event.review.body, '/test') runs-on: ubuntu-latest steps: - - name: run e2e + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Save info about the review comment as an artifact for other workflows that run on workflow_run to download them + env: + REVIEW_BODY: ${{ github.event.review.body }} run: | - echo "run e2e" \ No newline at end of file + mkdir -p /tmp/artifacts + { echo ${{ github.event.pull_request.number }}; echo ${{ github.event.review.commit_id }}; } >> /tmp/artifacts/metadata.txt + cat /tmp/artifacts/metadata.txt + - uses: actions/upload-artifact@v3 + with: + name: artifacts + path: /tmp/artifacts diff --git a/.github/workflows/e2e-matrix-trigger.yaml b/.github/workflows/e2e-matrix-trigger.yaml index 36bc5d982..160f20523 100644 --- a/.github/workflows/e2e-matrix-trigger.yaml +++ b/.github/workflows/e2e-matrix-trigger.yaml @@ -3,15 +3,21 @@ on: workflow_dispatch: push: branches: [main] - pull_request_review: # TODO(charliedmcb): come back to this and factor out the E2E trigger like AWS and clean it up - types: [submitted] + workflow_run: + workflows: [ApprovalComment] + types: [completed] permissions: id-token: write # This is required for requesting the JWT contents: read # This is required for actions/checkout + statuses: write # ./.github/actions/commit-status/* jobs: + resolve: + uses: ./.github/workflows/resolve-args.yaml e2e-matrix: - if: github.event_name != 'pull_request_review' || startsWith(github.event.review.body ,'/test') + needs: [resolve] uses: ./.github/workflows/e2e-matrix.yaml + with: + git_ref: ${{ needs.resolve.outputs.GIT_REF }} secrets: E2E_CLIENT_ID: ${{ secrets.E2E_CLIENT_ID }} E2E_TENANT_ID: ${{ secrets.E2E_TENANT_ID }} diff --git a/.github/workflows/e2e-matrix.yaml b/.github/workflows/e2e-matrix.yaml index 51d111476..d0dfedeaa 100644 --- a/.github/workflows/e2e-matrix.yaml +++ b/.github/workflows/e2e-matrix.yaml @@ -1,7 +1,9 @@ name: E2EMatrix on: workflow_call: - # inputs: + inputs: + git_ref: + type: string # region: # type: string # default: "us-east-2" @@ -34,6 +36,7 @@ jobs: suite: [Nonbehavioral, Utilization, GPU, Drift, Integration] uses: ./.github/workflows/e2e.yaml with: + git_ref: ${{ inputs.git_ref }} suite: ${{ matrix.suite }} hash: ${{ needs.initialize-generative-params.outputs.E2E_HASH }} # region: ${{ inputs.region }} diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index d8c26a52a..08bd3ef66 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -5,6 +5,8 @@ on: # region: # type: string # default: "us-east-2" + git_ref: + type: string suite: type: string required: true @@ -24,6 +26,7 @@ on: permissions: id-token: write # This is required for requesting the JWT contents: read # This is required for actions/checkout + statuses: write # ./.github/actions/commit-status/* jobs: run-suite: name: suite-${{ inputs.suite }} @@ -32,6 +35,11 @@ jobs: AZURE_SUBSCRIPTION_ID: ${{ secrets.E2E_SUBSCRIPTION_ID }} steps: - uses: actions/checkout@v3 + - if: always() && github.event_name == 'workflow_run' + uses: ./.github/actions/commit-status/start + with: + name: ${{ github.workflow }} / e2e (${{ inputs.suite }}) + git_ref: ${{ inputs.git_ref }} - uses: ./.github/actions/install-deps - name: az login uses: azure/login@v1 @@ -120,3 +128,8 @@ jobs: resource_group: ${{ env.RG_NAME }} cluster_name: ${{ env.CLUSTER_NAME }} acr_name: ${{ env.ACR_NAME }} + - if: always() && github.event_name == 'workflow_run' + uses: ./.github/actions/commit-status/end + with: + name: ${{ github.workflow }} / e2e (${{ inputs.suite }}) + git_ref: ${{ inputs.git_ref }} diff --git a/.github/workflows/resolve-args.yaml b/.github/workflows/resolve-args.yaml new file mode 100644 index 000000000..1203b5082 --- /dev/null +++ b/.github/workflows/resolve-args.yaml @@ -0,0 +1,23 @@ +name: ResolveArgs +on: + workflow_call: + outputs: + GIT_REF: + value: ${{ jobs.resolve.outputs.GIT_REF }} +jobs: + resolve: + runs-on: ubuntu-latest + outputs: + GIT_REF: ${{ steps.resolve-step.outputs.GIT_REF }} + steps: + # Download the artifact and resolve the GIT_REF + - uses: actions/checkout@v4 + - if: github.event_name == 'workflow_run' + uses: ./.github/actions/download-artifact + - id: resolve-step + run: | + if [[ "${{ github.event_name }}" == "workflow_run" ]]; then + echo GIT_REF="$(tail -n 1 /tmp/artifacts/metadata.txt)" >> "$GITHUB_OUTPUT" + else + echo GIT_REF="" >> "$GITHUB_OUTPUT" + fi