diff options
author | 2023-02-14 21:38:04 +0530 | |
---|---|---|
committer | 2023-02-14 21:38:04 +0530 | |
commit | 861f5b25a145dea9bfa8a94c360b0c463d24d1d7 (patch) | |
tree | ff44711a480e50e73e4bbf785e65c91fc15a5831 | |
parent | Update tests for `/tag` as of migration to slash commands (diff) | |
parent | Merge PR #2400: Reusable status embed workflow (diff) |
Merge branch 'main' into migration/tag
-rw-r--r-- | .github/workflows/build.yml | 13 | ||||
-rw-r--r-- | .github/workflows/deploy.yml | 12 | ||||
-rw-r--r-- | .github/workflows/lint-test.yml | 32 | ||||
-rw-r--r-- | .github/workflows/status_embed.yaml | 65 |
4 files changed, 59 insertions, 63 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f8f2c8888..211116f14 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,6 +14,9 @@ concurrency: jobs: build: + outputs: + job_status: ${{ job.status }} + if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push' name: Build & Push runs-on: ubuntu-latest @@ -61,3 +64,13 @@ jobs: ghcr.io/python-discord/bot:${{ steps.sha_tag.outputs.tag }} build-args: | git_sha=${{ github.sha }} + + call_status_embed: + name: Trigger the status embed workflow + needs: build + if: always() + uses: ./.github/workflows/status_embed.yaml + with: + job_status: ${{ needs.build.outputs.job_status }} + secrets: + webhook_token: ${{ secrets.GHA_WEBHOOK_TOKEN }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 79eef8821..481311ef6 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -14,6 +14,8 @@ concurrency: jobs: build: + outputs: + job_status: ${{ job.status }} environment: production if: github.event.workflow_run.conclusion == 'success' name: Build & Push @@ -44,3 +46,13 @@ jobs: namespaces/default/bot/deployment.yaml images: 'ghcr.io/python-discord/bot:${{ steps.sha_tag.outputs.tag }}' kubectl-version: 'latest' + + call_status_embed: + name: Trigger the status embed workflow + needs: build + if: always() + uses: ./.github/workflows/status_embed.yaml + with: + job_status: ${{ needs.build.outputs.job_status }} + secrets: + webhook_token: ${{ secrets.GHA_WEBHOOK_TOKEN }} diff --git a/.github/workflows/lint-test.yml b/.github/workflows/lint-test.yml index a331659e6..3d4453be9 100644 --- a/.github/workflows/lint-test.yml +++ b/.github/workflows/lint-test.yml @@ -12,6 +12,8 @@ concurrency: jobs: lint-test: + outputs: + job_status: ${{ job.status }} runs-on: ubuntu-latest env: # List of licenses that are compatible with the MIT License and @@ -75,24 +77,12 @@ jobs: - name: Run tests and generate coverage report run: pytest -n auto --cov --disable-warnings -q - # Prepare the Pull Request Payload artifact. If this fails, we - # we fail silently using the `continue-on-error` option. It's - # nice if this succeeds, but if it fails for any reason, it - # does not mean that our lint-test checks failed. - - name: Prepare Pull Request Payload artifact - id: prepare-artifact - if: always() && github.event_name == 'pull_request' - continue-on-error: true - run: cat $GITHUB_EVENT_PATH | jq '.pull_request' > pull_request_payload.json - - # This only makes sense if the previous step succeeded. To - # get the original outcome of the previous step before the - # `continue-on-error` conclusion is applied, we use the - # `.outcome` value. This step also fails silently. - - name: Upload a Build Artifact - if: always() && steps.prepare-artifact.outcome == 'success' - continue-on-error: true - uses: actions/upload-artifact@v2 - with: - name: pull-request-payload - path: pull_request_payload.json + call_status_embed: + name: Trigger the status embed workflow + needs: lint-test + if: always() + uses: ./.github/workflows/status_embed.yaml + with: + job_status: ${{ needs.lint-test.outputs.job_status }} + secrets: + webhook_token: ${{ secrets.GHA_WEBHOOK_TOKEN }} diff --git a/.github/workflows/status_embed.yaml b/.github/workflows/status_embed.yaml index 4178c366d..e81875b3a 100644 --- a/.github/workflows/status_embed.yaml +++ b/.github/workflows/status_embed.yaml @@ -1,16 +1,17 @@ name: Status Embed on: - workflow_run: - workflows: - - Lint & Test - - Build - - Deploy - types: - - completed + workflow_call: + inputs: + job_status: + required: true + type: string + secrets: + webhook_token: + required: true concurrency: - group: ${{ github.workflow }}-${{ github.ref }} + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.sha }} cancel-in-progress: true jobs: @@ -27,34 +28,14 @@ jobs: # # 3. If any workflow ends in failure or was cancelled. if: >- - (github.event.workflow_run.name == 'Deploy' && github.event.workflow_run.conclusion != 'skipped') || - github.event.workflow_run.event == 'pull_request' || - github.event.workflow_run.conclusion == 'failure' || - github.event.workflow_run.conclusion == 'cancelled' + (github.workflow == 'Deploy' && ${{ inputs.job_status }} != 'skipped') || + github.event_name == 'pull_request' || + ${{ inputs.job_status }} == 'failure' || + ${{ inputs.job_status }} == 'cancelled' name: Send Status Embed to Discord runs-on: ubuntu-latest steps: - # A workflow_run event does not contain all the information - # we need for a PR embed. That's why we upload an artifact - # with that information in the Lint workflow. - - name: Get Pull Request Information - id: pr_info - if: github.event.workflow_run.event == 'pull_request' - run: | - curl -s -H "Authorization: token $GITHUB_TOKEN" ${{ github.event.workflow_run.artifacts_url }} > artifacts.json - DOWNLOAD_URL=$(cat artifacts.json | jq -r '.artifacts[] | select(.name == "pull-request-payload") | .archive_download_url') - [ -z "$DOWNLOAD_URL" ] && exit 1 - wget --quiet --header="Authorization: token $GITHUB_TOKEN" -O pull_request_payload.zip $DOWNLOAD_URL || exit 2 - unzip -p pull_request_payload.zip > pull_request_payload.json - [ -s pull_request_payload.json ] || exit 3 - echo "::set-output name=pr_author_login::$(jq -r '.user.login // empty' pull_request_payload.json)" - echo "::set-output name=pr_number::$(jq -r '.number // empty' pull_request_payload.json)" - echo "::set-output name=pr_title::$(jq -r '.title // empty' pull_request_payload.json)" - echo "::set-output name=pr_source::$(jq -r '.head.label // empty' pull_request_payload.json)" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # Send an informational status embed to Discord instead of the # standard embeds that Discord sends. This embed will contain # more information and we can fine tune when we actually want @@ -64,19 +45,19 @@ jobs: with: # Our GitHub Actions webhook webhook_id: '784184528997842985' - webhook_token: ${{ secrets.GHA_WEBHOOK_TOKEN }} + webhook_token: ${{ secrets.webhook_token }} # Workflow information - workflow_name: ${{ github.event.workflow_run.name }} - run_id: ${{ github.event.workflow_run.id }} - run_number: ${{ github.event.workflow_run.run_number }} - status: ${{ github.event.workflow_run.conclusion }} + workflow_name: ${{ github.workflow }} + run_id: ${{ github.run_id }} + run_number: ${{ github.run_number }} + status: ${{ inputs.job_status }} actor: ${{ github.actor }} repository: ${{ github.repository }} ref: ${{ github.ref }} - sha: ${{ github.event.workflow_run.head_sha }} + sha: ${{ github.sha }} - pr_author_login: ${{ steps.pr_info.outputs.pr_author_login }} - pr_number: ${{ steps.pr_info.outputs.pr_number }} - pr_title: ${{ steps.pr_info.outputs.pr_title }} - pr_source: ${{ steps.pr_info.outputs.pr_source }} + pr_author_login: ${{ github.event.pull_request.user.login}} + pr_number: ${{ github.event.pull_request.number }} + pr_title: ${{ github.event.pull_request.title }} + pr_source: ${{ github.event.pull_request.head.label }} |