Skip to content

Commit

Permalink
Add GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
uklotzde committed Oct 22, 2021
1 parent aed82ee commit 56e93df
Show file tree
Hide file tree
Showing 5 changed files with 261 additions and 1 deletion.
77 changes: 77 additions & 0 deletions .github/workflows/continuous-integration.yaml
Original file line number Diff line number Diff line change
@@ -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
56 changes: 56 additions & 0 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
if: github.event_name == 'push'

- name: Detect code style issues (pull_request)
uses: pre-commit/[email protected]
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 }}
106 changes: 106 additions & 0 deletions .github/workflows/pre-release.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
19 changes: 19 additions & 0 deletions .github/workflows/security-audit.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 56e93df

Please sign in to comment.