From ce99390344e3388e3348854b0c1dab844be3ac1e Mon Sep 17 00:00:00 2001 From: Rajiv Shah Date: Wed, 12 Aug 2020 18:50:35 -0400 Subject: [PATCH] Add CI pipeline (#6) * feature(ci): Copy workflows from stronghold and adapt for identity.rs * fix(ci): Use main instead of master for branch trigger * feature(ci): Build and test on Windows as well * fix(ci): Remove toolchain from cache keys --- .github/workflows/audit.yml | 26 ++++++ .github/workflows/build-and-test.yml | 80 +++++++++++++++++++ .github/workflows/clippy.yml | 33 ++++++++ .../workflows/deploy_docs_to_github_pages.yml | 4 +- .github/workflows/format.yml | 32 ++++++++ 5 files changed, 173 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/audit.yml create mode 100644 .github/workflows/build-and-test.yml create mode 100644 .github/workflows/clippy.yml create mode 100644 .github/workflows/format.yml diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml new file mode 100644 index 0000000000..890ca1e418 --- /dev/null +++ b/.github/workflows/audit.yml @@ -0,0 +1,26 @@ +name: Audit + +on: + schedule: + - cron: '0 0 * * *' + push: + branches: + - main + paths: + - "**/Cargo.lock" + - "**/Cargo.toml" + pull_request: + branches: + - main + paths: + - "**/Cargo.lock" + - "**/Cargo.toml" + +jobs: + audit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/audit-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 0000000000..9582633f5e --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,80 @@ +name: Build and run tests + +on: + push: + branches: + - main + pull_request: + branches: + - main + - dev + paths-ignore: + - 'docs/**' + +jobs: + build-and-test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + project: [identity_account, identity_communication, identity_doc_manager, identity_integration, identity_resolver, identity_schema, identity_vc] + os: [ubuntu-latest, windows-latest] + + steps: + - uses: actions/checkout@v2 + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + - name: Get current date + if: matrix.os == 'ubuntu-latest' + run: echo "::set-env name=CURRENT_DATE::$(date +'%Y-%m-%d')" + + - name: Get current date + if: matrix.os == 'windows-latest' + run: echo "::set-env name=CURRENT_DATE::$(Get-Date -Format "yyyy-MM-dd")" + + - name: Cache cargo registry + uses: actions/cache@v2 + with: + path: ~/.cargo/registry + # Add date to the cache to keep it up to date + key: ${{ matrix.project }}-${{ matrix.os }}-cargo-registry-${{ hashFiles('**/Cargo.toml') }}-${{ env.CURRENT_DATE }} + # Restore from outdated cache for speed + restore-keys: | + ${{ matrix.project }}-${{ matrix.os }}-cargo-registry-${{ hashFiles('**/Cargo.toml') }} + + - name: Cache cargo index + uses: actions/cache@v2 + with: + path: ~/.cargo/git + # Add date to the cache to keep it up to date + key: ${{ matrix.project }}-${{ matrix.os }}-cargo-index-${{ hashFiles('**/Cargo.toml') }}-${{ env.CURRENT_DATE }} + # Restore from outdated cache for speed + restore-keys: | + ${{ matrix.project }}-${{ matrix.os }}-cargo-index-${{ hashFiles('**/Cargo.toml') }} + + - name: Cache cargo target + uses: actions/cache@v2 + with: + path: ${{ matrix.project}}/target + # Add date to the cache to keep it up to date + key: ${{ matrix.project }}-${{ matrix.os }}-cargo-build-target-${{ hashFiles('**/Cargo.toml') }}-${{ env.CURRENT_DATE }} + # Restore from outdated cache for speed + restore-keys: | + ${{ matrix.project }}-${{ matrix.os }}-cargo-build-target-${{ hashFiles('**/Cargo.toml') }} + + - name: Build ${{ matrix.project }} + uses: actions-rs/cargo@v1 + with: + command: build + args: --manifest-path=${{ matrix.project }}/Cargo.toml --all --release + + - name: Run tests for ${{ matrix.project }} + uses: actions-rs/cargo@v1 + with: + command: test + args: --manifest-path=${{ matrix.project }}/Cargo.toml --all --release diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml new file mode 100644 index 0000000000..18a3eb7423 --- /dev/null +++ b/.github/workflows/clippy.yml @@ -0,0 +1,33 @@ +name: Clippy + +on: + push: + branches: + - main + pull_request: + branches: + - main + - dev + +jobs: + clippy: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + project: [identity_account, identity_communication, identity_doc_manager, identity_integration, identity_resolver, identity_schema, identity_vc] + + steps: + - uses: actions/checkout@v2 + - name: Install clippy with stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + components: clippy + - uses: actions-rs/clippy-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + args: --manifest-path=${{ matrix.project }}/Cargo.toml --all-targets --all-features -- -D warnings + name: clippy-${{ matrix.project }} diff --git a/.github/workflows/deploy_docs_to_github_pages.yml b/.github/workflows/deploy_docs_to_github_pages.yml index a03c912cac..4366c314fe 100644 --- a/.github/workflows/deploy_docs_to_github_pages.yml +++ b/.github/workflows/deploy_docs_to_github_pages.yml @@ -3,7 +3,7 @@ name: deploy docs to github pages on: push: branches: - - master + - main jobs: deploy: @@ -23,4 +23,4 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_branch: gh-pages - publish_dir: ./book \ No newline at end of file + publish_dir: ./book diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 0000000000..1ba26a6750 --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,32 @@ +name: Format + +on: + push: + branches: + - main + pull_request: + branches: + - main + - dev + +jobs: + format: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + project: [identity_account, identity_communication, identity_doc_manager, identity_integration, identity_resolver, identity_schema, identity_vc] + + steps: + - uses: actions/checkout@v2 + - name: Install rustfmt with nightly toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + override: true + components: rustfmt + - uses: actions-rs/cargo@v1 + with: + command: fmt + args: --manifest-path=${{ matrix.project }}/Cargo.toml --all -- --check