From 11bf5bbba6253f3e7d1c52c393f84236fb8ee95f Mon Sep 17 00:00:00 2001 From: xieyuschen Date: Tue, 1 Oct 2024 14:36:45 +0800 Subject: [PATCH] [#60] integrate miri in ci with an allow list --- .github/workflows/miri-check.yml | 26 ++++++++++++++++++++++++++ .miri_allowlist | 8 ++++++++ internal/scripts/ci_run_miri.sh | 31 +++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 .github/workflows/miri-check.yml create mode 100644 .miri_allowlist create mode 100755 internal/scripts/ci_run_miri.sh diff --git a/.github/workflows/miri-check.yml b/.github/workflows/miri-check.yml new file mode 100644 index 000000000..0ddc4de9a --- /dev/null +++ b/.github/workflows/miri-check.yml @@ -0,0 +1,26 @@ +name: Miri + +on: + push: + branches: [ main ] + pull_request: + branches: [ main, release* ] + +jobs: + miri: + name: "Miri" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Miri + run: | + rustup toolchain install nightly --component miri + rustup override set nightly + cargo miri setup + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v45 + - name: List all changed files + env: + ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} + run: ./internal/scripts/ci_run_miri.sh \ No newline at end of file diff --git a/.miri_allowlist b/.miri_allowlist new file mode 100644 index 000000000..b71235ecb --- /dev/null +++ b/.miri_allowlist @@ -0,0 +1,8 @@ +# .miri_allowlist use hash character to lead a comment +# each line will be treated as a valid relative path to enter and run 'cargo miri test', +# if it contains some changed files(added, copied and modified, deletion is excluded) in the PR. +# +# note that each line should end up with a newline character, +# otherwise the ci shell will skip the last line +iceoryx2-bb/testing +# this line is put here to ensure each file path contains a newline char, don't remove it \ No newline at end of file diff --git a/internal/scripts/ci_run_miri.sh b/internal/scripts/ci_run_miri.sh new file mode 100755 index 000000000..f72bcb7d0 --- /dev/null +++ b/internal/scripts/ci_run_miri.sh @@ -0,0 +1,31 @@ +# Copyright (c) 2024 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache Software License 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0, or the MIT license +# which is available at https://opensource.org/licenses/MIT. +# +# SPDX-License-Identifier: Apache-2.0 OR MIT + +filename=".miri_allowlist" +while IFS= read -r line; do +if [[ "$line" == \#* ]]; then + continue +fi + +if echo "$ALL_CHANGED_FILES" | grep -q "$line"; then + cd "$line" || { echo "Failed to change directory to $line"; exit 1; } + echo "Run cargo miri test under: $(pwd)" + cargo miri test + if [ $? -ne 0 ]; then + echo "Error: cargo miri test failed." + exit 1 + fi + cd - +else + echo "skip $line because the PR doesn't touch its files" +fi +done < "$filename" \ No newline at end of file