From 9c334edc0581b43fd5969ca8643ae6bd12d02714 Mon Sep 17 00:00:00 2001 From: Greaka Date: Wed, 2 Aug 2023 16:08:29 +0200 Subject: [PATCH 1/2] feat: support nightly rust in rust tests and build on demand --- .github/workflows/build_rust_test_images.yaml | 15 ++++--- .github/workflows/rust-build.yml | 31 +++++++++----- .github/workflows/rust-test.yml | 12 +++++- .github/workflows/setup_rust_test_images.yaml | 40 +++++++++++++++++++ docker/rust-tests/Dockerfile | 23 +++++++++-- 5 files changed, 101 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/setup_rust_test_images.yaml diff --git a/.github/workflows/build_rust_test_images.yaml b/.github/workflows/build_rust_test_images.yaml index 9873468..4a493e0 100644 --- a/.github/workflows/build_rust_test_images.yaml +++ b/.github/workflows/build_rust_test_images.yaml @@ -5,7 +5,7 @@ on: inputs: rust_version: description: "Rust version to install" - default: "1.69" + default: "1.70" type: string additional_tag: description: "Additional tag for docker building" @@ -15,14 +15,15 @@ on: inputs: rust_version: description: "Rust version to install" - default: "1.69" + default: "1.70" type: string jobs: build-rust-test-image: runs-on: ubuntu-latest + if: ${{ inputs.rust_version != 'none' }} steps: - - name: 'Checkout' + - name: "Checkout" uses: actions/checkout@v3 - name: Login to ACR uses: docker/login-action@v2 @@ -36,9 +37,11 @@ jobs: - name: Build & Push uses: docker/build-push-action@v3 with: - context: docker/rust-tests + context: https://github.com/ForesightMiningSoftwareCorporation/github.git#v1.2.0:docker/rust-tests push: true - build-args: RUST_VERSION=${{ inputs.rust_version }} + build-args: | + RUST_VERSION=${{ inputs.rust_version }} + ADDITIONAL_CMD=${{ contains(inputs.rust_version, 'nightly') && 'rustup component add miri' || '' }} tags: | ghcr.io/foresightminingsoftwarecorporation/rust-test:${{ inputs.rust_version }} - ghcr.io/foresightminingsoftwarecorporation/rust-test:${{ inputs.additional_tag }} + ${{ inputs.additional_tag && format('ghcr.io/foresightminingsoftwarecorporation/rust-test:{0}', inputs.additional_tag) || '' }} diff --git a/.github/workflows/rust-build.yml b/.github/workflows/rust-build.yml index 9b92639..16f08f5 100644 --- a/.github/workflows/rust-build.yml +++ b/.github/workflows/rust-build.yml @@ -3,36 +3,40 @@ on: inputs: skip-test: type: string - default: 'false' + default: "false" description: "Should the tests be ran" skip-test-publish: type: string - default: 'false' + default: "false" description: "Should the publis dry-run test be ran" publish: type: string - default: 'false' + default: "false" description: "Should the crate be published" publish_private_registry: type: string - default: 'false' + default: "false" description: "Should the crate be published to the private registry" publish_public_registry: type: string - default: 'false' + default: "false" description: "Should the crate be published to the public registry" publish_docker: type: string - default: 'false' + default: "false" description: "Should the docker image be built and published" publish_binary: type: string - default: 'false' + default: "false" description: "Should the binary be built and published" toolchain: type: string default: "1.69" description: Rust toolchain to install + miri_toolchain: + type: string + default: "nightly-2023-08-02" + description: Rust toolchain to use for Miri release_channel: type: string default: "" @@ -75,7 +79,7 @@ on: default: Dockerfile docker_image: type: string - default: '' + default: "" description: "Docker image name" docker_registry: type: string @@ -83,7 +87,7 @@ on: description: "Docker registry" matrix_file: type: string - default: '.github/workflows/matrix.json' + default: ".github/workflows/matrix.json" description: "Matrix file to load" post_build_additional_script: type: string @@ -91,9 +95,16 @@ on: description: Post Build Additional script to run after the additional packages jobs: + build_rust_ci_images: + uses: ForesightMiningSoftwareCorporation/github/.github/workflows/setup_rust_test_images.yaml@v1.2.0 + with: + rust_versions: "${{ inputs.toolchain }} ${{ inputs.miri_toolchain }}" + secrets: inherit test: - uses: ForesightMiningSoftwareCorporation/github/.github/workflows/rust-test.yml@v1.1.0 + uses: ForesightMiningSoftwareCorporation/github/.github/workflows/rust-test.yml@v1.2.0 if: ${{ inputs.skip-test != 'true' }} + needs: + - build_rust_ci_images with: toolchain: ${{ inputs.toolchain }} additional_cache_path: ${{ inputs.additional_cache_path }} diff --git a/.github/workflows/rust-test.yml b/.github/workflows/rust-test.yml index f79e20d..71bf395 100644 --- a/.github/workflows/rust-test.yml +++ b/.github/workflows/rust-test.yml @@ -47,7 +47,7 @@ on: description: Should we skip cargo test (useful in there are no tests define) skip-test-publish: type: string - default: 'false' + default: "false" description: "Should the publis dry-run test be ran" login_private_registry: type: string @@ -65,6 +65,16 @@ jobs: runs-on: ubuntu-latest env: CARGO_HTTP_USER_AGENT: "shipyard ${{ secrets.CARGO_PRIVATE_REGISTRY_TOKEN }}" + strategy: + matrix: + include: + - toolchain: ${{ inputs.toolchain }} + type: check + - toolchain: ${{ inputs.toolchain }} + type: test + - toolchain: ${{ inputs.nightly_toolchain }} + type: miri + fail-fast: ${{ inputs.fail-fast == 'true' }} container: image: ghcr.io/foresightminingsoftwarecorporation/rust-test:${{ inputs.toolchain }} options: --user root diff --git a/.github/workflows/setup_rust_test_images.yaml b/.github/workflows/setup_rust_test_images.yaml new file mode 100644 index 0000000..e385056 --- /dev/null +++ b/.github/workflows/setup_rust_test_images.yaml @@ -0,0 +1,40 @@ +on: + workflow_call: + inputs: + rust_versions: + type: string + default: "1.69" + description: Rust rust_versions to install, whitespace separated + +jobs: + check-existing-rust-versions: + runs-on: ubuntu-latest + steps: + - name: Login to ACR + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Check for existing images + id: check + run: | + requested_versions=(${{ inputs.rust_versions }}) + required_versions='' + for version in "${requested_versions[@]}"; do + docker manifest inspect ghcr.io/foresightminingsoftwarecorporation/rust-test:$version > /dev/null || \ + required_versions+=",\"$version\"" + done + echo "matrix=[\"none\"${required_versions}]" >> $GITHUB_OUTPUT + outputs: + matrix: ${{ steps.check.outputs.matrix }} + + build-rust-test-images: + uses: ForesightMiningSoftwareCorporation/github/.github/workflows/build_rust_test_images.yaml@v1.2.0 + needs: check-existing-rust-versions + strategy: + matrix: + version: ${{ fromJson(needs.check-existing-rust-versions.outputs.matrix) }} + with: + rust_version: ${{ matrix.version }} + secrets: inherit diff --git a/docker/rust-tests/Dockerfile b/docker/rust-tests/Dockerfile index 8cf4a26..c57d5e5 100644 --- a/docker/rust-tests/Dockerfile +++ b/docker/rust-tests/Dockerfile @@ -1,7 +1,21 @@ -ARG RUST_VERSION=1.69 -FROM rust:$RUST_VERSION +FROM debian:11 +ARG RUST_VERSION=1.70 -RUN apt-get update && apt-get install -y software-properties-common +RUN apt-get update && apt-get install -y software-properties-common build-essential curl make gcc + +ENV RUSTUP_HOME=/usr/local/rustup \ + CARGO_HOME=/usr/local/cargo \ + PATH=/usr/local/cargo/bin:$PATH \ + RUST_VERSION=$RUST_VERSION + +RUN curl --proto '=https' --tlsv1.2 -sSf https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init > rustup-init && \ + curl --proto '=https' --tlsv1.2 -sSf https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init.sha256 > rustup-init.sha256 && \ + sed -i "s|target/x86_64-unknown-linux-gnu/release/||g" rustup-init.sha256 && \ + sha256sum -c rustup-init.sha256 && \ + rm rustup-init.sha256 && \ + chmod u+x rustup-init && \ + ./rustup-init -y --default-toolchain $RUST_VERSION && \ + rm rustup-init RUN apt-add-repository non-free && apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ moreutils \ @@ -24,6 +38,9 @@ RUN cargo install --locked cargo-deny RUN cargo install cargo-machete RUN cargo install tomlq +ARG ADDITIONAL_CMD +RUN $ADDITIONAL_CMD + RUN mkdir -p /test-dir WORKDIR /test-dir From 58b0c543f6c1e96ea74d14099572e73cf17d34fe Mon Sep 17 00:00:00 2001 From: Greaka Date: Mon, 7 Aug 2023 15:29:47 +0200 Subject: [PATCH 2/2] feat: run miri tests in ci --- .github/actions/shell-with-output/action.yaml | 23 +- .github/workflows/rust-build.yml | 10 +- .github/workflows/rust-test.yml | 261 ++++++++++-------- 3 files changed, 167 insertions(+), 127 deletions(-) diff --git a/.github/actions/shell-with-output/action.yaml b/.github/actions/shell-with-output/action.yaml index f480a77..5d57be7 100644 --- a/.github/actions/shell-with-output/action.yaml +++ b/.github/actions/shell-with-output/action.yaml @@ -5,24 +5,21 @@ inputs: command: required: true description: "The command" - id: - required: true - description: "The id for the step artifacts" working-directory: required: true description: "The working directory" loki_url: required: true - description: 'URL to contact loki' + description: "URL to contact loki" loki_org_id: required: true - description: 'Loki Org Id' + description: "Loki Org Id" loki_username: required: true - description: 'Username to talk to loki' + description: "Username to talk to loki" loki_password: required: true - description: 'Password to talk to loki' + description: "Password to talk to loki" outputs: stdout: description: "Command STDOUT" @@ -48,11 +45,11 @@ runs: rc=$? fi echo "exitcode=$rc" >> $GITHUB_OUTPUT -# - name: Upload to artifacts -# uses: actions/upload-artifact@v2 -# with: -# name: ${{ github.action }}-stdout -# path: ${{ inputs.working-directory }}/output.txt + # - name: Upload to artifacts + # uses: actions/upload-artifact@v2 + # with: + # name: ${{ github.action }}-stdout + # path: ${{ inputs.working-directory }}/output.txt - name: Upload stdout uses: ForesightMiningSoftwareCorporation/upload-log-to-loki@releases/v1 with: @@ -61,7 +58,7 @@ runs: loki_username: ${{ inputs.loki_username }} loki_password: ${{ inputs.loki_password }} loki_org_id: ${{ inputs.loki_org_id }} - loki_labels: 'job=${{ github.job }},workflow=${{ github.workflow }},action=${{ github.action }},id=${{ github.run_id }},repo=${{ github.repository }}' + loki_labels: "job=${{ github.job }},workflow=${{ github.workflow }},action=${{ github.action }},id=${{ github.run_id }},repo=${{ github.repository }}" - name: Check exit code shell: bash run: | diff --git a/.github/workflows/rust-build.yml b/.github/workflows/rust-build.yml index 16f08f5..f573000 100644 --- a/.github/workflows/rust-build.yml +++ b/.github/workflows/rust-build.yml @@ -4,11 +4,15 @@ on: skip-test: type: string default: "false" - description: "Should the tests be ran" + description: "Should the tests be run" + skip-miri-test: + type: string + default: "true" + description: "Should miri tests be run" skip-test-publish: type: string default: "false" - description: "Should the publis dry-run test be ran" + description: "Should the public dry-run test be run" publish: type: string default: "false" @@ -117,6 +121,8 @@ jobs: custom_cargo_commands: ${{ inputs.custom_cargo_commands }} login_private_registry: ${{ inputs.publish_public_registry != 'true' }} skip-test-publish: ${{ inputs.skip-test-publish }} + skip-miri-test: ${{ inputs.skip-miri-test }} + nightly_toolchain: ${{ inputs.miri_toolchain }} secrets: inherit publish_private_registry: uses: ForesightMiningSoftwareCorporation/github/.github/workflows/rust_private_registry_publish.yml@v1.1.0 diff --git a/.github/workflows/rust-test.yml b/.github/workflows/rust-test.yml index 71bf395..75895f5 100644 --- a/.github/workflows/rust-test.yml +++ b/.github/workflows/rust-test.yml @@ -9,6 +9,10 @@ on: type: string default: "1.69" description: Rust toolchain to install + nightly_toolchain: + type: string + default: "nightly-2023-08-02" + description: Rust toolchain to install additional_args: type: string default: "" @@ -44,7 +48,11 @@ on: skip-cargo-test: type: string default: "false" - description: Should we skip cargo test (useful in there are no tests define) + description: Should we skip cargo test (useful when there are no tests defined) + skip-miri-test: + type: string + default: "false" + description: Should we skip miri test (useful when tests are incompatible) skip-test-publish: type: string default: "false" @@ -60,8 +68,8 @@ env: CARGO_HTTP_USER_AGENT: "shipyard ${{ secrets.CARGO_PRIVATE_REGISTRY_TOKEN }}" jobs: - test: - name: Rust Test + check: + name: Rust ${{ matrix.type }} runs-on: ubuntu-latest env: CARGO_HTTP_USER_AGENT: "shipyard ${{ secrets.CARGO_PRIVATE_REGISTRY_TOKEN }}" @@ -76,7 +84,7 @@ jobs: type: miri fail-fast: ${{ inputs.fail-fast == 'true' }} container: - image: ghcr.io/foresightminingsoftwarecorporation/rust-test:${{ inputs.toolchain }} + image: ghcr.io/foresightminingsoftwarecorporation/rust-test:${{ matrix.toolchain }} options: --user root steps: - name: Configure Git to use global ignore file @@ -127,6 +135,8 @@ jobs: - name: Cache Dependencies uses: Swatinem/rust-cache@v2 + with: + shared-key: "${{ github.job }}-${{ matrix.type }}" - name: Get crate name id: name @@ -141,7 +151,7 @@ jobs: run: echo "value=$(date +'%s')000" >> $GITHUB_OUTPUT - name: Run Cargo Custom command - uses: ForesightMiningSoftwareCorporation/github/.github/actions/shell-with-output@v1.1.0 + uses: ForesightMiningSoftwareCorporation/github/.github/actions/shell-with-output@v1.2.0 id: custom if: inputs.custom_cargo_commands != '' continue-on-error: true @@ -154,10 +164,10 @@ jobs: loki_org_id: 1 - name: fmt - uses: ForesightMiningSoftwareCorporation/github/.github/actions/shell-with-output@v1.1.0 + uses: ForesightMiningSoftwareCorporation/github/.github/actions/shell-with-output@v1.2.0 id: fmt continue-on-error: true - if: inputs.fail-fast == 'false' || inputs.custom_cargo_commands == '' || steps.custom.outcome == 'success' + if: matrix.type == 'check' && (inputs.fail-fast == 'false' || inputs.custom_cargo_commands == '' || steps.custom.outcome == 'success') with: command: "cargo fmt --verbose --all -- --check" working-directory: ${{ inputs.working-directory }} @@ -167,10 +177,9 @@ jobs: loki_org_id: 1 - name: check - uses: ForesightMiningSoftwareCorporation/github/.github/actions/shell-with-output@v1.1.0 + uses: ForesightMiningSoftwareCorporation/github/.github/actions/shell-with-output@v1.2.0 id: check - continue-on-error: true - if: inputs.fail-fast == 'false' || steps.fmt.outcome == 'success' + if: matrix.type == 'check' && (inputs.fail-fast == 'false' || steps.fmt.outcome == 'success') with: command: "cargo check ${{ inputs.additional_args }}" working-directory: ${{ inputs.working-directory }} @@ -180,10 +189,9 @@ jobs: loki_org_id: 1 - name: run clippy - uses: ForesightMiningSoftwareCorporation/github/.github/actions/shell-with-output@v1.1.0 + uses: ForesightMiningSoftwareCorporation/github/.github/actions/shell-with-output@v1.2.0 id: clippy - continue-on-error: true - if: inputs.fail-fast == 'false' || steps.check.outcome == 'success' + if: matrix.type == 'check' && (inputs.fail-fast == 'false' || steps.check.outcome == 'success' && !cancelled()) with: command: "cargo clippy ${{ inputs.additional_args }} -- -D warnings" working-directory: ${{ inputs.working-directory }} @@ -195,17 +203,17 @@ jobs: - name: Copy Default deny if not exists shell: bash working-directory: ${{ inputs.working-directory }} - if: inputs.fail-fast == 'false' || steps.clippy.outcome == 'success' + if: matrix.type == 'check' && (inputs.fail-fast == 'false' || steps.clippy.outcome == 'success' && !cancelled()) run: | if [ ! -f deny.yml ]; then wget https://raw.githubusercontent.com/ForesightMiningSoftwareCorporation/github/main/deny.toml fi - name: check license - uses: ForesightMiningSoftwareCorporation/github/.github/actions/shell-with-output@v1.1.0 + uses: ForesightMiningSoftwareCorporation/github/.github/actions/shell-with-output@v1.2.0 id: deny-license continue-on-error: true - if: inputs.fail-fast == 'false' || steps.clippy.outcome == 'success' + if: matrix.type == 'check' && (inputs.fail-fast == 'false' || steps.clippy.outcome == 'success' && !cancelled()) with: command: "cargo deny check licenses" working-directory: ${{ inputs.working-directory }} @@ -215,10 +223,10 @@ jobs: loki_org_id: 1 - name: check bans - uses: ForesightMiningSoftwareCorporation/github/.github/actions/shell-with-output@v1.1.0 + uses: ForesightMiningSoftwareCorporation/github/.github/actions/shell-with-output@v1.2.0 id: deny-bans continue-on-error: true - if: inputs.fail-fast == 'false' || steps.clippy.outcome == 'success' + if: matrix.type == 'check' && (inputs.fail-fast == 'false' || steps.clippy.outcome == 'success' && !cancelled()) with: command: "cargo deny check bans" working-directory: ${{ inputs.working-directory }} @@ -228,10 +236,10 @@ jobs: loki_org_id: 1 - name: check advisories - uses: ForesightMiningSoftwareCorporation/github/.github/actions/shell-with-output@v1.1.0 + uses: ForesightMiningSoftwareCorporation/github/.github/actions/shell-with-output@v1.2.0 id: deny-advisories continue-on-error: true - if: inputs.fail-fast == 'false' || steps.clippy.outcome == 'success' + if: matrix.type == 'check' && (inputs.fail-fast == 'false' || steps.clippy.outcome == 'success' && !cancelled()) with: command: "cargo deny check advisories" working-directory: ${{ inputs.working-directory }} @@ -241,10 +249,10 @@ jobs: loki_org_id: 1 - name: check sources - uses: ForesightMiningSoftwareCorporation/github/.github/actions/shell-with-output@v1.1.0 + uses: ForesightMiningSoftwareCorporation/github/.github/actions/shell-with-output@v1.2.0 id: deny-sources continue-on-error: true - if: inputs.fail-fast == 'false' || steps.clippy.outcome == 'success' + if: matrix.type == 'check' && (inputs.fail-fast == 'false' || steps.clippy.outcome == 'success' && !cancelled()) with: command: "cargo deny check sources" working-directory: ${{ inputs.working-directory }} @@ -254,10 +262,10 @@ jobs: loki_org_id: 1 - name: unused dependencies - uses: ForesightMiningSoftwareCorporation/github/.github/actions/shell-with-output@v1.1.0 + uses: ForesightMiningSoftwareCorporation/github/.github/actions/shell-with-output@v1.2.0 id: dependencies continue-on-error: true - if: inputs.fail-fast == 'false' || steps.clippy.outcome == 'success' + if: matrix.type == 'check' && (inputs.fail-fast == 'false' || steps.clippy.outcome == 'success' && !cancelled()) with: command: "cargo machete" working-directory: ${{ inputs.working-directory }} @@ -266,131 +274,160 @@ jobs: loki_password: ${{ secrets.LOKI_GITHUB_PASSWORD }} loki_org_id: 1 + - name: Publishing DryRun + uses: ForesightMiningSoftwareCorporation/github/.github/actions/shell-with-output@v1.2.0 + id: publish-dryrun + continue-on-error: true + if: matrix.type == 'check' && inputs.skip-test-publish != 'true' + with: + command: "cargo package ${{ inputs.additional_args }}" + working-directory: ${{ inputs.working-directory }} + loki_url: ${{ vars.LOKI_URL }} + loki_username: ${{ secrets.LOKI_GITHUB_USERNAME }} + loki_password: ${{ secrets.LOKI_GITHUB_PASSWORD }} + loki_org_id: 1 + - name: Tests - uses: ForesightMiningSoftwareCorporation/github/.github/actions/shell-with-output@v1.1.0 + uses: ForesightMiningSoftwareCorporation/github/.github/actions/shell-with-output@v1.2.0 id: tests - continue-on-error: true - if: inputs.skip-cargo-test == 'false' && (inputs.fail-fast == 'false' || steps.clippy.outcome == 'success') + if: matrix.type == 'test' && inputs.skip-cargo-test == 'false' && (inputs.fail-fast == 'false' || !cancelled()) with: - command: "cargo test ${{ inputs.additional_args }}" + command: "cargo test ${{ inputs.fail-fast == 'false' && '--keep-going' || '' }} ${{ inputs.additional_args }}" working-directory: ${{ inputs.working-directory }} loki_url: ${{ vars.LOKI_URL }} loki_username: ${{ secrets.LOKI_GITHUB_USERNAME }} loki_password: ${{ secrets.LOKI_GITHUB_PASSWORD }} loki_org_id: 1 - - name: Publishing DryRun - uses: ForesightMiningSoftwareCorporation/github/.github/actions/shell-with-output@v1.1.0 - id: publish-dryrun + - name: Miri + uses: ForesightMiningSoftwareCorporation/github/.github/actions/shell-with-output@v1.2.0 + id: miri continue-on-error: true - if: inputs.skip-test-publish != 'true' && (inputs.fail-fast == 'false' || steps.tests.outcome == 'success') + if: matrix.type == 'miri' && inputs.skip-cargo-test == 'false' && inputs.skip-miri-test == 'false' && (inputs.fail-fast == 'false' || !cancelled()) with: - command: "cargo package ${{ inputs.additional_args }}" + command: "cargo miri test ${{ inputs.fail-fast == 'false' && '--keep-going' || '' }} ${{ inputs.additional_args }}" working-directory: ${{ inputs.working-directory }} loki_url: ${{ vars.LOKI_URL }} loki_username: ${{ secrets.LOKI_GITHUB_USERNAME }} loki_password: ${{ secrets.LOKI_GITHUB_PASSWORD }} loki_org_id: 1 + - uses: cloudposse/github-action-matrix-outputs-write@0.4.2 + id: out + if: always() && github.event_name == 'pull_request' || github.event_name == 'pull_request_target' + with: + matrix-step-name: ${{ github.job }} + matrix-key: ${{ matrix.type }} + outputs: |- + check_outcome: ${{ steps.check.outcome }} + clippy_outcome: ${{ steps.clippy.outcome }} + custom_outcome: ${{ steps.custom.outcome }} + deny-advisories_outcome: ${{ steps.deny-advisories.outcome }} + deny-bans_outcome: ${{ steps.deny-bans.outcome }} + deny-license_outcome: ${{ steps.deny-license.outcome }} + deny-sources_outcome: ${{ steps.deny-sources.outcome }} + dependencies_outcome: ${{ steps.dependencies.outcome }} + fmt_outcome: ${{ steps.fmt.outcome }} + miri_outcome: ${{ steps.miri.outcome }} + name: ${{ steps.name.outputs.value }} + publish-dryrun_outcome: ${{ steps.publish-dryrun.outcome }} + start: ${{ steps.start_time.outputs.value }} + tests_outcome: ${{ steps.tests.outcome }} + + results: + name: Rust Test Results + runs-on: ubuntu-latest + env: + CARGO_HTTP_USER_AGENT: "shipyard ${{ secrets.CARGO_PRIVATE_REGISTRY_TOKEN }}" + container: + image: ghcr.io/foresightminingsoftwarecorporation/rust-test:${{ inputs.toolchain }} + options: --user root + needs: check + if: always() + steps: - name: Set end time as env variable id: end_time - if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target' + if: always() && github.event_name == 'pull_request' || github.event_name == 'pull_request_target' run: echo "value=$(date +'%s')000" >> $GITHUB_OUTPUT + - uses: cloudposse/github-action-matrix-outputs-read@0.1.1 + id: read + if: always() && github.event_name == 'pull_request' || github.event_name == 'pull_request_target' + with: + matrix-step-name: check + - uses: int128/hide-comment-action@v1 - if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target' + if: always() && github.event_name == 'pull_request' || github.event_name == 'pull_request_target' with: authors: | github-actions - uses: actions/github-script@v6 name: Report status on PR - if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target' + if: always() && github.event_name == 'pull_request' || github.event_name == 'pull_request_target' with: script: | - const output =` -
-

${{ steps.name.value }} - ${{ (steps.fmt.outcome == 'failure' || steps.check.outcome == 'failure' || steps.clippy.outcome == 'failure' || steps.tests.outcome == 'failure') && '❌' || '✅' }} ${{ steps.name.outputs.value }}

(click for details)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + function outcomeEmoji(outcome) { + switch (outcome) { + case 'success': + return '✅'; + case 'skipped': + return '⏭'; + case 'cancelled': + return '⛔'; + case 'failure': + return '❌'; + default: + return '❔'; + } + } + + const header = ` +
+

${{ fromJson(steps.read.outputs.result).name.check }} - ${{ (fromJson(steps.read.outputs.result).fmt_outcome.check == 'failure' || fromJson(steps.read.outputs.result).check_outcome.check == 'failure' || fromJson(steps.read.outputs.result).clippy_outcome.check == 'failure' || fromJson(steps.read.outputs.result).tests_outcome.test == 'failure') && '❌' || '✅' }} ${{ fromJson(steps.read.outputs.result).name.check }}

(click for details)
+
requiredstepresultdetails
Custom: \`${{ inputs.cargo_custom_commands }}\`\`${{ steps.custom.outcome == 'success' && '✅' || (steps.custom.outcome == 'skipped' && '⏭' || '❌') }}\`Logs
\`cargo fmt --verbose --all -- --check\`\`${{ steps.fmt.outcome == 'success' && '✅' || (steps.fmt.outcome == 'skipped' && '⏭' || '❌') }}\`Logs
\`cargo check ${{ inputs.additional_args }}\`\`${{ steps.check.outcome == 'success' && '✅' || (steps.check.outcome == 'skipped' && '⏭' || '❌') }}\`Logs
\`cargo clippy ${{ inputs.additional_args }} -- -D warnings\`\`${{ steps.clippy.outcome == 'success' && '✅' || (steps.clippy.outcome == 'skipped' && '⏭' || '❌') }}\`Logs
\`cargo deny check licenses\`\`${{ steps.deny-license.outcome == 'success' && '✅' || (steps.deny-license.outcome == 'skipped' && '⏭' || '❌') }}\`Logs
\`cargo deny check bans\`\`${{ steps.deny-bans.outcome == 'success' && '✅' || (steps.deny-bans.outcome == 'skipped' && '⏭' || '❌') }}\`Logs
\`cargo deny check advisories\`\`${{ steps.deny-advisories.outcome == 'success' && '✅' || (steps.deny-advisories.outcome == 'skipped' && '⏭' || '❌') }}\`Logs
\`cargo deny check sources\`\`${{ steps.deny-sources.outcome == 'success' && '✅' || (steps.deny-sources.outcome == 'skipped' && '⏭' || '❌') }}\`Logs
\`cargo machete\`\`${{ steps.dependencies.outcome == 'success' && '✅' || (steps.dependencies.outcome == 'skipped' && '⏭' || '❌') }}\`Logs
\`cargo test ${{ inputs.additional_args }}\`\`${{ steps.tests.outcome == 'success' && '✅' || (steps.tests.outcome == 'skipped' && '⏭' || '❌') }}\`Logs
+ + `; + + const entry = (name, outcome, required, logId) => ` - - - - + + + + -
requiredstepresultdetails
\`cargo publish --dry-run ${{ inputs.additional_args }}\`\`${{ steps.publish-dryrun.outcome == 'success' && '✅' || (steps.publish-dryrun.outcome == 'skipped' && '⏭' || '❌') }}\`Logs${ required ? '✓' : '' }${ name }${ outcomeEmoji(outcome) }Logs
+ `; + const custom = entry('Custom: ${{ inputs.custom_cargo_commands }}', '${{ fromJson(steps.read.outputs.result).custom_outcome.check }}', true, 'custom'); + const fmt = entry('cargo fmt --verbose --all -- --check', '${{ fromJson(steps.read.outputs.result).fmt_outcome.check }}', true, 'fmt'); + const check = entry('cargo check ${{ inputs.additional_args }}', '${{ fromJson(steps.read.outputs.result).check_outcome.check }}', true, 'check'); + const clippy = entry('cargo clippy ${{ inputs.additional_args }} -- -D warnings', '${{ fromJson(steps.read.outputs.result).clippy_outcome.check }}', true, 'clippy'); + const licenses = entry('cargo deny check licenses', '${{ fromJson(steps.read.outputs.result).deny-license_outcome.check }}', false, 'deny-license'); + const bans = entry('cargo deny check bans', '${{ fromJson(steps.read.outputs.result).deny-bans_outcome.check }}', false, 'deny-bans'); + const advisories = entry('cargo deny check advisories', '${{ fromJson(steps.read.outputs.result).deny-advisories_outcome.check }}', false, 'deny-advisories'); + const sources = entry('cargo deny check sources', '${{ fromJson(steps.read.outputs.result).deny-sources_outcome.check }}', false, 'deny-sources'); + const machete = entry('cargo machete', '${{ fromJson(steps.read.outputs.result).dependencies_outcome.check }}', false, 'dependencies'); + const test = entry('cargo test ${{ inputs.additional_args }}', '${{ fromJson(steps.read.outputs.result).tests_outcome.test }}', true, 'tests'); + const miri = entry('cargo miri test ${{ inputs.additional_args }}', '${{ fromJson(steps.read.outputs.result).miri_outcome.miri }}', false, 'miri'); + const publish = entry('cargo publish --dry-run ${{ inputs.additional_args }}', '${{ fromJson(steps.read.outputs.result).publish-dryrun_outcome.check }}', false, 'publish-dryrun'); + + const footer = ` + + + Pushed by: @${{ github.actor }}, Action: ${{ github.event_name }}; + Run: ${{ github.run_id }} + Logs: Logs +
+ `; + + const output = header + custom + fmt + check + clippy + licenses + bans + advisories + sources + machete + test + miri + publish + footer; - Pushed by: \`@${{ github.actor }}\`, Action: \`${{ github.event_name }}\`; - Run: ${{ github.run_id }} - Logs: Logs - ` github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body: output - }) + }); + - name: Rust Test status - if: steps.custom.outcome == 'failure' || steps.fmt.outcome == 'failure' || steps.check.outcome == 'failure' || steps.clippy.outcome == 'failure' || steps.tests.outcome == 'failure' + if: fromJson(steps.read.outputs.result).custom_outcome.check == 'failure' || fromJson(steps.read.outputs.result).fmt_outcome.check == 'failure' || fromJson(steps.read.outputs.result).check_outcome.check == 'failure' || fromJson(steps.read.outputs.result).clippy_outcome.check == 'failure' || fromJson(steps.read.outputs.result).tests_outcome.test == 'failure' run: exit 1