From 1b600de3f2e541c8b506677f485f26d172cc3c63 Mon Sep 17 00:00:00 2001 From: Xithrius Date: Sun, 5 Jun 2022 17:16:03 -0700 Subject: [PATCH] Artifacts and comments --- .github/workflows/ci.yml | 72 ++++++++++++++++++++++++------ .github/workflows/status_embed.yml | 22 ++++++--- 2 files changed, 76 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index da64ca0..b34271d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,8 +2,7 @@ name: CI on: push: - branches: - - main + branches: [ main ] pull_request: env: @@ -15,25 +14,49 @@ jobs: fail-fast: false matrix: - os: - - { prettyname: Windows, fullname: windows-latest } - - { prettyname: macOS, fullname: macos-latest } - - { prettyname: Linux, fullname: ubuntu-latest } + include: + - os: windows-latest + target: x86_64-pc-windows-msvc - threadingMode: [ 'SingleThread', 'MultiThreaded' ] + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu - timeout-minutes: 60 + - os: macos-latest + target: x86_64-apple-darwin - runs-on: ${{matrix.os.fullname}} + name: Build & Test (${{ matrix.target }}) + runs-on: ${{ matrix.os }} + + env: + RA_TARGET: ${{ matrix.target }} steps: - - uses: actions/checkout@v2 + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + target: ${{ matrix.target }} + profile: minimal + override: true + + - name: Install Rust library source + if: matrix.target == 'x86_64-unknown-linux-gnu' + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + target: ${{ matrix.target }} + profile: minimal + override: true + components: rust-src - name: Build - run: cargo build --verbose + run: cargo build --verbose --target ${{ matrix.target }} - name: Run tests - run: cargo test --verbose + run: cargo test --verbose --target ${{ matrix.target }} lint: name: Formatter @@ -43,7 +66,8 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - name: Checkout repository + uses: actions/checkout@v3 - name: Install Rust run: | @@ -57,3 +81,25 @@ jobs: - name: Check code for possible improvements run: cargo clippy -- -D warnings + + # 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 diff --git a/.github/workflows/status_embed.yml b/.github/workflows/status_embed.yml index cf77988..169775e 100644 --- a/.github/workflows/status_embed.yml +++ b/.github/workflows/status_embed.yml @@ -9,11 +9,25 @@ on: jobs: status_embed: + # We send the embed in the following situations: + # - Always after the `CI` workflow, as it runs at the + # end of our workflow sequence regardless of status. + # - Always for the `pull_request` event, as it only + # runs one workflow. + # - Always run for non-success workflows, as they + # terminate the workflow sequence. + if: >- + (github.event.workflow_run.name == 'CI' && 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' name: Send Status Embed to Discord runs-on: ubuntu-latest steps: - # Process the artifact uploaded in the `pull_request`-triggered workflow: + # 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' @@ -38,12 +52,11 @@ jobs: - name: GitHub Actions Status Embed for Discord uses: SebastiaanZ/github-status-embed-for-discord@main with: - # Webhook token + # Our GitHub Actions webhook webhook_id: ${{ secrets.DISCORD_WEBHOOK_ID }} webhook_token: ${{ secrets.DISCORD_WEBHOOK_TOKEN }} - # We need to provide the information of the workflow that - # triggered this workflow instead of this workflow. + # Workflow information workflow_name: ${{ github.event.workflow_run.name }} run_id: ${{ github.event.workflow_run.id }} run_number: ${{ github.event.workflow_run.run_number }} @@ -53,7 +66,6 @@ jobs: ref: ${{ github.ref }} sha: ${{ github.event.workflow_run.head_sha }} - # Now we can use the information extracted in the previous step: 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 }}