From d339be85119cc52ab2170bcd6b3ed24cf0c6c4d9 Mon Sep 17 00:00:00 2001 From: Gowtham Suresh Kumar Date: Thu, 22 Feb 2024 14:12:19 +0000 Subject: [PATCH] CI: Split jobs This patch adds a ci_script GitHub action and splits the jobs to run specific tests. Signed-off-by: Gowtham Suresh Kumar --- .github/actions/ci_script/action.yml | 23 ++++++++ .github/workflows/ci.yml | 21 ++++--- ci.sh | 85 +++++++++++++++++++++------- 3 files changed, 103 insertions(+), 26 deletions(-) create mode 100644 .github/actions/ci_script/action.yml diff --git a/.github/actions/ci_script/action.yml b/.github/actions/ci_script/action.yml new file mode 100644 index 00000000..c5042ca0 --- /dev/null +++ b/.github/actions/ci_script/action.yml @@ -0,0 +1,23 @@ +name: "Run CI Tests" +description: "Run the ci.sh script with the specified flags" +inputs: + ci-flags: + required: true + description: "Flags with which to run the ci.sh tests" + rs-version: + required: true + default: "stable" + description: "Rust version with which to run the tests" + +runs: + using: "composite" + steps: + - name: Load Docker + uses: ./.github/actions/load_docker + if: ${{ env.TEST_DOCKER_IMAGE == 'parsec-openssl-provider-test' }} + with: + image-name: "${{ env.TEST_DOCKER_IMAGE }}" + image-path: "/tmp" + - name: Run the container to execute the test script + run: docker run -v $(pwd):/tmp/parsec-openssl-provider -w /tmp/parsec-openssl-provider --env RUST_TOOLCHAIN_VERSION=${{ inputs.rs-version }} -t ${{ env.TEST_DOCKER_IMAGE }} /tmp/parsec-openssl-provider/ci.sh --${{ inputs.ci-flags }} + shell: bash diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2ceedce8..21bb7bd2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,12 +37,19 @@ jobs: needs: [build-and-export-test-docker] steps: - uses: actions/checkout@v3 - - name: Load Docker - uses: ./.github/actions/load_docker - if: ${{ env.TEST_DOCKER_IMAGE == 'parsec-openssl-provider-test' }} + - name: Run the container to execute the test script + uses: ./.github/actions/ci_script with: - image-name: "${{ env.TEST_DOCKER_IMAGE }}" - image-path: "/tmp" + ci-flags: "build-test" + + static-checks: + name: Run static checks + runs-on: ubuntu-latest + if: ${{ always() }} + needs: [build-and-export-test-docker] + steps: + - uses: actions/checkout@v3 - name: Run the container to execute the test script - run: - docker run -v $(pwd):/tmp/parsec-openssl-provider -w /tmp/parsec-openssl-provider -t ${{ env.TEST_DOCKER_IMAGE }} ./ci.sh + uses: ./.github/actions/ci_script + with: + ci-flags: "static-checks" diff --git a/ci.sh b/ci.sh index 18c470b0..69c5392a 100755 --- a/ci.sh +++ b/ci.sh @@ -5,34 +5,81 @@ set -ex -echo "OpenSSL version being used:" -openssl version +usage () { + printf " +Continuous Integration test script -# Build parsec provider shared library -pushd parsec-openssl-provider-shared/ && -cargo build -popd +Usage: ./ci.sh --TEST +where TEST can be one of: + --build-test + --static-checks +" +} -# Try loading the build parsec provider -provider_load_result=$(openssl list -providers -provider-path ./target/debug/ -provider libparsec_openssl_provider_shared) -echo $provider_load_result +error_msg () { + echo "Error: $1" + usage + exit 1 +} -test_string='Providers: +# Change rust toolchain version +if [[ ! -z ${RUST_TOOLCHAIN_VERSION:+x} ]]; then + rustup override set ${RUST_TOOLCHAIN_VERSION} +fi + +rustup update + +BUILD_AND_TEST= +STATIC_CHECKS= + +while [ "$#" -gt 0 ]; do + case "$1" in + --build-test ) + BUILD_AND_TEST="True" + ;; + --static-checks ) + STATIC_CHECKS="True" + ;; + *) + error_msg "Unknown argument: $1" + ;; + esac + shift +done + +if [ "$BUILD_AND_TEST" ]; then + echo "OpenSSL version being used:" + openssl version + + # Build parsec provider shared library + pushd parsec-openssl-provider-shared/ && + cargo build + popd + + # Try loading the build parsec provider + PROVIDER_LOAD_RESULT=$(openssl list -providers -provider-path ./target/debug/ -provider libparsec_openssl_provider_shared) + echo $PROVIDER_LOAD_RESULT + + TEST_STRING='Providers: libparsec_openssl_provider_shared name: Parsec OpenSSL Provider version: 0.1.0 status: active' -if [[ $test_string != $provider_load_result ]]; then - echo "Loaded Provider has unexpected parameters!!!!" + if [[ $TEST_STRING != $PROVIDER_LOAD_RESULT ]]; then + echo "Loaded Provider has unexpected parameters!!!!" + exit 1 + fi + + echo "Parsec OpenSSL Provider loaded successfully!!!!" fi -echo "Parsec OpenSSL Provider loaded successfully!!!!" +if [ "$STATIC_CHECKS" ]; then + if cargo fmt --version; then + cargo fmt --all -- --check + fi -if cargo fmt --version; then - cargo fmt --all -- --check + if cargo clippy --version; then + cargo clippy --all-targets -- -D clippy::all -D clippy::cargo + fi fi - -if cargo clippy --version; then - cargo clippy --all-targets -- -D clippy::all -D clippy::cargo -fi \ No newline at end of file