diff --git a/.github/workflows/continuous-integration.yaml b/.github/workflows/continuous-integration.yaml new file mode 100644 index 0000000..b9a084f --- /dev/null +++ b/.github/workflows/continuous-integration.yaml @@ -0,0 +1,77 @@ +name: Continuous integration + +on: + pull_request: + push: + branches: + - main + +env: + CARGO_INCREMENTAL: 0 + CARGO_TERM_COLOR: always + +jobs: + continuous-integration: + name: Building project and running tests + runs-on: ubuntu-latest + + steps: + - name: Check out repository + uses: actions/checkout@v2 + + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + + - name: Cache Rust toolchain and build artifacts + uses: Swatinem/rust-cache@v1 + + - name: Check crates/msr-core + uses: actions-rs/cargo@v1 + with: + command: check + args: --manifest-path crates/msr-core/Cargo.toml + + - name: Check crates/msr-plugin + uses: actions-rs/cargo@v1 + with: + command: check + args: --manifest-path crates/msr-plugin/Cargo.toml + + - name: Check crates/msr-legacy + uses: actions-rs/cargo@v1 + with: + command: check + args: --manifest-path crates/msr-legacy/Cargo.toml + + - name: Check plugins/csv-event-journal-msr-plugin + uses: actions-rs/cargo@v1 + with: + command: check + args: --manifest-path plugins/csv-event-journal-msr-plugin/Cargo.toml + + - name: Check plugins/csv-register-recorder-msr-plugin + uses: actions-rs/cargo@v1 + with: + command: check + args: --manifest-path plugins/csv-register-recorder-msr-plugin/Cargo.toml + + - name: Build tests with all features enabled + uses: actions-rs/cargo@v1 + with: + command: test + args: --workspace --all-features --no-run + + - name: Run tests with all features enabled + uses: actions-rs/cargo@v1 + with: + command: test + args: --workspace --all-features --locked -- --nocapture --quiet + + - name: Build release with default features + uses: actions-rs/cargo@v1 + with: + command: build + args: --release --locked diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml new file mode 100644 index 0000000..6359efe --- /dev/null +++ b/.github/workflows/pre-commit.yaml @@ -0,0 +1,56 @@ +name: pre-commit + +on: + pull_request: + push: + branches: + - '*' + +env: + CARGO_TERM_COLOR: always + +jobs: + pre-commit: + name: Detecting code style issues + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v2 + + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + components: rustfmt, clippy + + - name: Cache Rust toolchain and build artifacts + uses: Swatinem/rust-cache@v1 + + - name: Setup Python + uses: actions/setup-python@v2 + + - name: Detect code style issues (push) + uses: pre-commit/action@v2.0.3 + if: github.event_name == 'push' + + - name: Detect code style issues (pull_request) + uses: pre-commit/action@v2.0.3 + if: github.event_name == 'pull_request' + env: + SKIP: no-commit-to-branch + + - name: Generate patch file + if: failure() + run: | + git diff-index -p HEAD > "${PATCH_FILE}" + [ -s "${PATCH_FILE}" ] && echo "UPLOAD_PATCH_FILE=${PATCH_FILE}" >> "${GITHUB_ENV}" + env: + PATCH_FILE: pre-commit.patch + + - name: Upload patch artifact + if: failure() && env.UPLOAD_PATCH_FILE != null + uses: actions/upload-artifact@v2 + with: + name: ${{ env.UPLOAD_PATCH_FILE }} + path: ${{ env.UPLOAD_PATCH_FILE }} diff --git a/.github/workflows/pre-release.yaml b/.github/workflows/pre-release.yaml new file mode 100644 index 0000000..2a6a520 --- /dev/null +++ b/.github/workflows/pre-release.yaml @@ -0,0 +1,106 @@ +name: pre-release + +on: + push: + tags: + - 'v[0-9]+*' + workflow_dispatch: + +env: + CARGO_TERM_COLOR: always + +jobs: + build-and-upload-artifacts: + name: Building and uploading artifacts + runs-on: ${{ matrix.runner_os }} + strategy: + matrix: + target: + - x86_64-unknown-linux-musl + - x86_64-apple-darwin + - x86_64-pc-windows-msvc + include: + - target: x86_64-unknown-linux-musl + runner_os: ubuntu-latest + artifact_suffix: .tar.xz + - target: x86_64-apple-darwin + runner_os: macos-latest + artifact_suffix: .tar.xz + - target: x86_64-pc-windows-msvc + runner_os: windows-latest + artifact_suffix: .7z + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install musl-tools on Linux + if: matrix.target == 'x86_64-unknown-linux-musl' + run: | + sudo apt -y install musl-tools + + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + target: ${{ matrix.target }} + toolchain: stable + profile: minimal + + - name: Cache Rust toolchain and build artifacts + uses: Swatinem/rust-cache@v1 + + - name: Build artifact + uses: actions-rs/cargo@v1 + with: + command: build + args: --release --locked --target ${{ matrix.target }} + + - name: Prepare artifact on Linux/macOS + if: runner.os == 'Linux' || runner.os == 'macOS' + run: | + cd target/${{ matrix.target }}/release + strip aoide + tar cJvf ../../../aoide-${{ matrix.target }}${{ matrix.artifact_suffix }} aoide + cd - + - name: Prepare artifact on Windows + if: runner.os == 'Windows' + run: | + cd target/${{ matrix.target }}/release + strip aoide.exe + 7z a ../../../aoide-${{ matrix.target }}${{ matrix.artifact_suffix }} aoide.exe + cd - + + - name: Upload artifact + uses: actions/upload-artifact@v2 + with: + name: aoide-${{ matrix.target }}${{ matrix.artifact_suffix }} + path: aoide-${{ matrix.target }}${{ matrix.artifact_suffix }} + + create-release-draft: + name: Creating release draft + needs: build-and-upload-artifacts + if: startsWith(github.ref, 'refs/tags/v') + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Download artifacts + uses: actions/download-artifact@v2 + + - name: Generate artifact checksums + run: for file in aoide-*/aoide-*; do openssl dgst -sha256 -r "$file" | awk '{print $1}' > "${file}.sha256"; done + + - name: Extract release notes from changelog + run: cat CHANGELOG.md | tail -n +7 | head -n 25 > RELEASE_NOTES.md + + - name: Create release draft + uses: softprops/action-gh-release@v1 + with: + files: aoide-*/aoide-* + body_path: RELEASE_NOTES.md + draft: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/security-audit.yaml b/.github/workflows/security-audit.yaml new file mode 100644 index 0000000..1a26350 --- /dev/null +++ b/.github/workflows/security-audit.yaml @@ -0,0 +1,19 @@ +name: Security audit + +on: + push: + paths: + - '**/Cargo.toml' + - '**/Cargo.lock' + #schedule: + # - cron: '0 0 * * *' + workflow_dispatch: + +jobs: + security-audit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/audit-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index 1fd2272..a6b764b 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,9 @@ A [Rust](https://www.rust-lang.org) library for industrial automation. [![Crates.io version](https://img.shields.io/crates/v/msr.svg)](https://crates.io/crates/msr) -[![Docs](https://docs.rs/msr/badge.svg)](https://docs.rs/msr/) +[![Docs.rs](https://docs.rs/msr/badge.svg)](https://docs.rs/msr/) +[![Security audit](https://github.com/slowtec/msr/actions/workflows/security-audit.yaml/badge.svg)](https://github.com/slowtec/msr/actions/workflows/security-audit.yaml) +[![Continuous integration](https://github.com/slowtec/msr/actions/workflows/continuous-integration.yaml/badge.svg)](https://github.com/slowtec/msr/actions/workflows/continuous-integration.yaml) ## Installation