2020-12-16 13:31:39 -05:00
|
|
|
name: Build
|
|
|
|
|
|
|
|
on:
|
|
|
|
push:
|
2021-08-28 11:29:13 -04:00
|
|
|
paths:
|
|
|
|
- ".github/workflows/build.yml"
|
|
|
|
- "src/**"
|
|
|
|
- "migrations/**"
|
|
|
|
- "Cargo.*"
|
|
|
|
- "build.rs"
|
2023-08-28 10:48:42 -04:00
|
|
|
- "rust-toolchain.toml"
|
2023-03-04 13:18:38 -05:00
|
|
|
- "rustfmt.toml"
|
|
|
|
- "diesel.toml"
|
2023-08-28 10:48:42 -04:00
|
|
|
- "docker/Dockerfile.j2"
|
2021-03-27 11:21:00 -04:00
|
|
|
pull_request:
|
2021-08-28 11:29:13 -04:00
|
|
|
paths:
|
|
|
|
- ".github/workflows/build.yml"
|
|
|
|
- "src/**"
|
|
|
|
- "migrations/**"
|
|
|
|
- "Cargo.*"
|
|
|
|
- "build.rs"
|
2023-08-28 10:48:42 -04:00
|
|
|
- "rust-toolchain.toml"
|
2023-03-04 13:18:38 -05:00
|
|
|
- "rustfmt.toml"
|
|
|
|
- "diesel.toml"
|
2023-08-28 10:48:42 -04:00
|
|
|
- "docker/Dockerfile.j2"
|
2020-12-16 13:31:39 -05:00
|
|
|
|
|
|
|
jobs:
|
|
|
|
build:
|
2023-06-11 12:11:09 -04:00
|
|
|
runs-on: ubuntu-22.04
|
2022-12-15 11:15:48 -05:00
|
|
|
timeout-minutes: 120
|
2021-05-08 10:48:48 -04:00
|
|
|
# Make warnings errors, this is to prevent warnings slipping through.
|
|
|
|
# This is done globally to prevent rebuilds when the RUSTFLAGS env variable changes.
|
|
|
|
env:
|
|
|
|
RUSTFLAGS: "-D warnings"
|
2023-06-21 16:01:05 -04:00
|
|
|
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
|
2020-12-16 13:31:39 -05:00
|
|
|
strategy:
|
|
|
|
fail-fast: false
|
|
|
|
matrix:
|
|
|
|
channel:
|
2022-07-19 13:13:54 -04:00
|
|
|
- "rust-toolchain" # The version defined in rust-toolchain
|
2022-09-15 10:51:52 -04:00
|
|
|
- "msrv" # The supported MSRV
|
2022-07-19 13:13:54 -04:00
|
|
|
|
|
|
|
name: Build and Test ${{ matrix.channel }}
|
|
|
|
|
2020-12-16 13:31:39 -05:00
|
|
|
steps:
|
|
|
|
# Checkout the repo
|
2022-07-19 13:13:54 -04:00
|
|
|
- name: "Checkout"
|
2023-09-22 14:27:03 -04:00
|
|
|
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
|
2020-12-16 13:31:39 -05:00
|
|
|
# End Checkout the repo
|
|
|
|
|
2023-03-04 13:18:38 -05:00
|
|
|
|
2020-12-16 13:31:39 -05:00
|
|
|
# Install dependencies
|
2022-07-19 13:13:54 -04:00
|
|
|
- name: "Install dependencies Ubuntu"
|
2023-06-11 12:11:09 -04:00
|
|
|
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends openssl build-essential libmariadb-dev-compat libpq-dev libssl-dev pkg-config
|
2020-12-16 13:31:39 -05:00
|
|
|
# End Install dependencies
|
|
|
|
|
2023-03-04 13:18:38 -05:00
|
|
|
|
2022-11-04 07:56:02 -04:00
|
|
|
# Determine rust-toolchain version
|
|
|
|
- name: Init Variables
|
|
|
|
id: toolchain
|
|
|
|
shell: bash
|
|
|
|
run: |
|
2023-03-04 13:18:38 -05:00
|
|
|
if [[ "${{ matrix.channel }}" == 'rust-toolchain' ]]; then
|
2023-08-28 10:48:42 -04:00
|
|
|
RUST_TOOLCHAIN="$(grep -oP 'channel.*"(\K.*?)(?=")' rust-toolchain.toml)"
|
2023-03-04 13:18:38 -05:00
|
|
|
elif [[ "${{ matrix.channel }}" == 'msrv' ]]; then
|
|
|
|
RUST_TOOLCHAIN="$(grep -oP 'rust-version.*"(\K.*?)(?=")' Cargo.toml)"
|
|
|
|
else
|
|
|
|
RUST_TOOLCHAIN="${{ matrix.channel }}"
|
|
|
|
fi
|
2022-11-04 07:56:02 -04:00
|
|
|
echo "RUST_TOOLCHAIN=${RUST_TOOLCHAIN}" | tee -a "${GITHUB_OUTPUT}"
|
|
|
|
# End Determine rust-toolchain version
|
2020-12-16 13:31:39 -05:00
|
|
|
|
2023-03-04 13:18:38 -05:00
|
|
|
|
|
|
|
# Only install the clippy and rustfmt components on the default rust-toolchain
|
2022-07-19 13:13:54 -04:00
|
|
|
- name: "Install rust-toolchain version"
|
2023-09-22 14:27:03 -04:00
|
|
|
uses: dtolnay/rust-toolchain@439cf607258077187679211f12aa6f19af4a0af7 # master @ 2023-09-19 - 05:31 PM GMT+2
|
2022-07-19 13:13:54 -04:00
|
|
|
if: ${{ matrix.channel == 'rust-toolchain' }}
|
2020-12-16 13:31:39 -05:00
|
|
|
with:
|
2022-11-04 07:56:02 -04:00
|
|
|
toolchain: "${{steps.toolchain.outputs.RUST_TOOLCHAIN}}"
|
2021-03-28 11:48:45 -04:00
|
|
|
components: clippy, rustfmt
|
2020-12-16 13:31:39 -05:00
|
|
|
# End Uses the rust-toolchain file to determine version
|
|
|
|
|
|
|
|
|
2023-03-04 13:18:38 -05:00
|
|
|
# Install the any other channel to be used for which we do not execute clippy and rustfmt
|
2022-07-19 13:13:54 -04:00
|
|
|
- name: "Install MSRV version"
|
2023-09-22 14:27:03 -04:00
|
|
|
uses: dtolnay/rust-toolchain@439cf607258077187679211f12aa6f19af4a0af7 # master @ 2023-09-19 - 05:31 PM GMT+2
|
2022-07-19 13:13:54 -04:00
|
|
|
if: ${{ matrix.channel != 'rust-toolchain' }}
|
|
|
|
with:
|
2023-03-04 13:18:38 -05:00
|
|
|
toolchain: "${{steps.toolchain.outputs.RUST_TOOLCHAIN}}"
|
2022-07-19 13:13:54 -04:00
|
|
|
# End Install the MSRV channel to be used
|
|
|
|
|
2023-09-22 14:27:03 -04:00
|
|
|
# Set the current matrix toolchain version as default
|
|
|
|
- name: "Set toolchain ${{steps.toolchain.outputs.RUST_TOOLCHAIN}} as default"
|
|
|
|
run: |
|
|
|
|
# Remove the rust-toolchain.toml
|
|
|
|
rm rust-toolchain.toml
|
|
|
|
# Set the default
|
|
|
|
rustup default ${{steps.toolchain.outputs.RUST_TOOLCHAIN}}
|
2022-07-19 13:13:54 -04:00
|
|
|
|
|
|
|
# Show environment
|
|
|
|
- name: "Show environment"
|
|
|
|
run: |
|
|
|
|
rustc -vV
|
|
|
|
cargo -vV
|
|
|
|
# End Show environment
|
|
|
|
|
2023-09-22 14:27:03 -04:00
|
|
|
# Enable Rust Caching
|
|
|
|
- uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 # v2.7.0
|
|
|
|
with:
|
|
|
|
# Use a custom prefix-key to force a fresh start. This is sometimes needed with bigger changes.
|
|
|
|
# Like changing the build host from Ubuntu 20.04 to 22.04 for example.
|
|
|
|
# Only update when really needed! Use a <year>.<month>[.<inc>] format.
|
|
|
|
prefix-key: "v2023.07-rust"
|
|
|
|
# End Enable Rust Caching
|
2022-07-19 13:13:54 -04:00
|
|
|
|
2021-03-27 11:10:00 -04:00
|
|
|
# Run cargo tests (In release mode to speed up future builds)
|
2021-05-08 10:48:48 -04:00
|
|
|
# First test all features together, afterwards test them separately.
|
2022-07-19 13:13:54 -04:00
|
|
|
- name: "test features: sqlite,mysql,postgresql,enable_mimalloc"
|
|
|
|
id: test_sqlite_mysql_postgresql_mimalloc
|
|
|
|
if: $${{ always() }}
|
2022-11-04 07:56:02 -04:00
|
|
|
run: |
|
|
|
|
cargo test --release --features sqlite,mysql,postgresql,enable_mimalloc
|
2022-07-19 13:13:54 -04:00
|
|
|
|
|
|
|
- name: "test features: sqlite,mysql,postgresql"
|
|
|
|
id: test_sqlite_mysql_postgresql
|
|
|
|
if: $${{ always() }}
|
2022-11-04 07:56:02 -04:00
|
|
|
run: |
|
|
|
|
cargo test --release --features sqlite,mysql,postgresql
|
2022-07-19 13:13:54 -04:00
|
|
|
|
|
|
|
- name: "test features: sqlite"
|
|
|
|
id: test_sqlite
|
|
|
|
if: $${{ always() }}
|
2022-11-04 07:56:02 -04:00
|
|
|
run: |
|
|
|
|
cargo test --release --features sqlite
|
2022-07-19 13:13:54 -04:00
|
|
|
|
|
|
|
- name: "test features: mysql"
|
|
|
|
id: test_mysql
|
|
|
|
if: $${{ always() }}
|
2022-11-04 07:56:02 -04:00
|
|
|
run: |
|
|
|
|
cargo test --release --features mysql
|
2022-07-19 13:13:54 -04:00
|
|
|
|
|
|
|
- name: "test features: postgresql"
|
|
|
|
id: test_postgresql
|
|
|
|
if: $${{ always() }}
|
2022-11-04 07:56:02 -04:00
|
|
|
run: |
|
|
|
|
cargo test --release --features postgresql
|
2020-12-16 13:31:39 -05:00
|
|
|
# End Run cargo tests
|
|
|
|
|
|
|
|
|
2021-05-08 10:48:48 -04:00
|
|
|
# Run cargo clippy, and fail on warnings (In release mode to speed up future builds)
|
2022-07-19 13:13:54 -04:00
|
|
|
- name: "clippy features: sqlite,mysql,postgresql,enable_mimalloc"
|
|
|
|
id: clippy
|
|
|
|
if: ${{ always() && matrix.channel == 'rust-toolchain' }}
|
2022-11-04 07:56:02 -04:00
|
|
|
run: |
|
|
|
|
cargo clippy --release --features sqlite,mysql,postgresql,enable_mimalloc -- -D warnings
|
2021-03-27 11:10:00 -04:00
|
|
|
# End Run cargo clippy
|
|
|
|
|
|
|
|
|
2022-07-19 13:13:54 -04:00
|
|
|
# Run cargo fmt (Only run on rust-toolchain defined version)
|
|
|
|
- name: "check formatting"
|
|
|
|
id: formatting
|
|
|
|
if: ${{ always() && matrix.channel == 'rust-toolchain' }}
|
2022-11-04 07:56:02 -04:00
|
|
|
run: |
|
|
|
|
cargo fmt --all -- --check
|
2021-03-28 11:48:45 -04:00
|
|
|
# End Run cargo fmt
|
|
|
|
|
|
|
|
|
2022-07-19 13:13:54 -04:00
|
|
|
# Check for any previous failures, if there are stop, else continue.
|
|
|
|
# This is useful so all test/clippy/fmt actions are done, and they can all be addressed
|
|
|
|
- name: "Some checks failed"
|
|
|
|
if: ${{ failure() }}
|
|
|
|
run: |
|
|
|
|
echo "### :x: Checks Failed!" >> $GITHUB_STEP_SUMMARY
|
|
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
|
|
echo "|Job|Status|" >> $GITHUB_STEP_SUMMARY
|
|
|
|
echo "|---|------|" >> $GITHUB_STEP_SUMMARY
|
|
|
|
echo "|test (sqlite,mysql,postgresql,enable_mimalloc)|${{ steps.test_sqlite_mysql_postgresql_mimalloc.outcome }}|" >> $GITHUB_STEP_SUMMARY
|
|
|
|
echo "|test (sqlite,mysql,postgresql)|${{ steps.test_sqlite_mysql_postgresql.outcome }}|" >> $GITHUB_STEP_SUMMARY
|
|
|
|
echo "|test (sqlite)|${{ steps.test_sqlite.outcome }}|" >> $GITHUB_STEP_SUMMARY
|
|
|
|
echo "|test (mysql)|${{ steps.test_mysql.outcome }}|" >> $GITHUB_STEP_SUMMARY
|
|
|
|
echo "|test (postgresql)|${{ steps.test_postgresql.outcome }}|" >> $GITHUB_STEP_SUMMARY
|
|
|
|
echo "|clippy (sqlite,mysql,postgresql,enable_mimalloc)|${{ steps.clippy.outcome }}|" >> $GITHUB_STEP_SUMMARY
|
|
|
|
echo "|fmt|${{ steps.formatting.outcome }}|" >> $GITHUB_STEP_SUMMARY
|
|
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
|
|
echo "Please check the failed jobs and fix where needed." >> $GITHUB_STEP_SUMMARY
|
|
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
|
|
exit 1
|
|
|
|
|
|
|
|
|
|
|
|
# Check for any previous failures, if there are stop, else continue.
|
|
|
|
# This is useful so all test/clippy/fmt actions are done, and they can all be addressed
|
|
|
|
- name: "All checks passed"
|
|
|
|
if: ${{ success() }}
|
|
|
|
run: |
|
|
|
|
echo "### :tada: Checks Passed!" >> $GITHUB_STEP_SUMMARY
|
|
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
|
|
|
|
|
|
|
|
|
|
# Build the binary to upload to the artifacts
|
|
|
|
- name: "build features: sqlite,mysql,postgresql"
|
|
|
|
if: ${{ matrix.channel == 'rust-toolchain' }}
|
2022-11-04 07:56:02 -04:00
|
|
|
run: |
|
|
|
|
cargo build --release --features sqlite,mysql,postgresql
|
2020-12-16 13:31:39 -05:00
|
|
|
# End Build the binary
|
|
|
|
|
|
|
|
|
|
|
|
# Upload artifact to Github Actions
|
2022-07-19 13:13:54 -04:00
|
|
|
- name: "Upload artifact"
|
2023-09-22 14:27:03 -04:00
|
|
|
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
|
2022-07-19 13:13:54 -04:00
|
|
|
if: ${{ matrix.channel == 'rust-toolchain' }}
|
2020-12-16 13:31:39 -05:00
|
|
|
with:
|
2022-07-19 13:13:54 -04:00
|
|
|
name: vaultwarden
|
2022-09-15 10:51:52 -04:00
|
|
|
path: target/release/vaultwarden
|
2020-12-16 13:31:39 -05:00
|
|
|
# End Upload artifact to Github Actions
|