CI #1
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
# do not run workflow twice on PRs | |
on: [push] | |
jobs: | |
build: | |
if: github.event.pull_request.draft == false | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
- project: mithril-core | |
cargo_project_name: mithril | |
artifacts_pattern: libmithril | |
skip_tests: true | |
- project: mithril-common | |
artifacts_pattern: libmithril_common | |
- project: mithril-aggregator | |
- project: mithril-client | |
- project: mithril-signer | |
- project: mithril-test-lab/mithril-end-to-end | |
cargo_project_name: mithril-end-to-end | |
artifacts_base_name: mithril-end-to-end | |
artifacts_pattern: mithril-end-to-end | |
skip_doc: true | |
- project: demo/protocol-demo | |
cargo_project_name: mithrildemo | |
artifacts_base_name: mithrildemo | |
artifacts_pattern: mithrildemo | |
skip_doc: true | |
env: | |
CARGO_PROJECT_NAME: ${{ matrix.project }} | |
ARTIFACTS_BASE_NAME: ${{ matrix.project }} | |
ARTIFACTS_PATTERN: ${{ matrix.project }} | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@v2 | |
- name: Overriding default $CARGO_PROJECT_NAME with matrix value | |
if: ${{ matrix.cargo_project_name }} | |
run: echo "CARGO_PROJECT_NAME=${{ matrix.cargo_project_name }}" >> $GITHUB_ENV | |
- name: Overriding default $ARTIFACTS_BASE_NAME with matrix value | |
if: ${{ matrix.artifacts_base_name }} | |
run: echo "ARTIFACTS_BASE_NAME=${{ matrix.artifacts_base_name }}" >> $GITHUB_ENV | |
- name: Overriding default $ARTIFACTS_PATTERN with matrix value | |
if: ${{ matrix.artifacts_pattern }} | |
run: echo "ARTIFACTS_PATTERN=${{ matrix.artifacts_pattern }}" >> $GITHUB_ENV | |
- name: Install stable toolchain | |
uses: actions-rs/toolchain@v1 | |
with: | |
profile: minimal | |
toolchain: stable | |
components: clippy, rustfmt | |
override: true | |
- uses: actions/cache@v3 | |
name: Cache Cargo.lock | |
with: | |
path: | | |
~/.cargo/bin/ | |
~/.cargo/registry/ | |
~/.cargo/git/ | |
target/ | |
key: cargo-${{ runner.os }}-cache-v${{ secrets.CACHE_VERSION }}-${{ matrix.project }}-${{ hashFiles('Cargo.lock') }} | |
restore-keys: | | |
cargo-${{ runner.os }}-cache-v${{ secrets.CACHE_VERSION }}-${{ matrix.project }}- | |
cargo-${{ runner.os }}-cache-v${{ secrets.CACHE_VERSION }}- | |
- name: Install cargo tools | |
if: ${{ steps.cargo-cache.outputs.cache-hit == false }} | |
run: | | |
cargo install cargo2junit 2>/dev/null || true # Suppress the "binary `xyz` already exists in destination" error | |
cargo install cargo-sort 2>/dev/null || true | |
- name: Cargo build | |
uses: actions-rs/cargo@v1 | |
with: | |
command: build | |
args: --release --all-targets -p ${{ env.CARGO_PROJECT_NAME }} | |
- name: Cargo check | |
uses: actions-rs/cargo@v1 | |
with: | |
command: check | |
args: --release --all-targets -p ${{ env.CARGO_PROJECT_NAME }} | |
- name: Clippy Check | |
uses: actions-rs/clippy-check@v1 | |
with: | |
name: clippy-${{ matrix.project }} | |
token: ${{ secrets.GITHUB_TOKEN }} | |
args: --release --all-features -p ${{ env.CARGO_PROJECT_NAME }} | |
- name: Cargo fmt | |
uses: actions-rs/cargo@v1 | |
with: | |
command: fmt | |
args: --check -p ${{ env.CARGO_PROJECT_NAME }} | |
- name: Cargo sort | |
run: | | |
cargo sort -c ${{ matrix.project }}/Cargo.toml | |
- name: Run tests | |
if: ${{ matrix.skip_tests != true }} | |
shell: bash | |
run: | | |
set -o pipefail && \ | |
cargo test --release -p $CARGO_PROJECT_NAME --no-fail-fast \ | |
-- -Z unstable-options --format json --report-time \ | |
| tee >(cargo2junit > test-results-${{ env.ARTIFACTS_PATTERN }}.xml) | |
- name: Upload Tests Results | |
if: ${{ always() && matrix.skip_tests != true }} | |
uses: actions/upload-artifact@v3 | |
with: | |
name: test-results-${{ env.ARTIFACTS_BASE_NAME }} | |
path: | | |
./**/test-results-*.xml | |
- name: Generate ${{ matrix.project }} doc | |
if: ${{ matrix.skip_doc != true }} | |
uses: actions-rs/cargo@v1 | |
with: | |
command: doc | |
args: --no-deps --release -p ${{ env.CARGO_PROJECT_NAME }} | |
- name: Publish ${{ matrix.project }} | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.ARTIFACTS_BASE_NAME }} | |
path: | | |
target/release/${{ env.ARTIFACTS_PATTERN }}* | |
if-no-files-found: error | |
- name: Publish ${{ matrix.project }}-doc | |
if: ${{ matrix.skip_doc != true }} | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.ARTIFACTS_BASE_NAME }}-doc | |
if-no-files-found: error | |
path: | | |
target/doc/ | |
test-mithril-core: | |
runs-on: ubuntu-latest | |
if: ${{ github.event_name == 'push' }} | |
needs: [ build ] | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@v2 | |
- name: Install stable toolchain | |
uses: actions-rs/toolchain@v1 | |
with: | |
profile: minimal | |
toolchain: stable | |
components: clippy, rustfmt | |
override: true | |
# Get the matrix build cache for mithril-core | |
# Note: cargo tools will be included so there's no need to install them | |
- uses: actions/cache@v3 | |
name: Cache Cargo.lock | |
with: | |
path: | | |
~/.cargo/bin/ | |
~/.cargo/registry/ | |
~/.cargo/git/ | |
target/ | |
key: cargo-${{ runner.os }}-cache-v${{ secrets.CACHE_VERSION }}-mithril-core-${{ hashFiles('Cargo.lock') }} | |
restore-keys: | | |
cargo-${{ runner.os }}-cache-v${{ secrets.CACHE_VERSION }}-mithril-core | |
cargo-${{ runner.os }}-cache-v${{ secrets.CACHE_VERSION }}- | |
- name: Cargo build | |
uses: actions-rs/cargo@v1 | |
with: | |
command: build | |
args: --release --tests -p mithril | |
- name: Run tests | |
if: ${{ matrix.skip_test != true }} | |
shell: bash | |
run: | | |
set -o pipefail && \ | |
cargo test --release -p mithril --no-fail-fast \ | |
-- -Z unstable-options --format json --report-time \ | |
| tee >(cargo2junit > test-results-libmithril.xml) | |
- name: Upload Tests Results | |
if: ${{ always() && matrix.skip_test != true }} | |
uses: actions/upload-artifact@v3 | |
with: | |
name: test-results-mithril-core | |
path: | | |
./**/test-results-*.xml | |
run-test-lab: | |
runs-on: ubuntu-latest | |
needs: [ build ] | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@v2 | |
- name: Download aggregator | |
uses: actions/download-artifact@v3 | |
with: | |
name: mithril-aggregator | |
path: ./bin | |
- name: Download signer | |
uses: actions/download-artifact@v3 | |
with: | |
name: mithril-signer | |
path: ./bin | |
- name: Download client | |
uses: actions/download-artifact@v3 | |
with: | |
name: mithril-client | |
path: ./bin | |
- name: Download rust test runner | |
uses: actions/download-artifact@v3 | |
with: | |
name: mithril-end-to-end | |
path: ./ | |
- run: | | |
chmod +x ./bin/mithril-aggregator | |
chmod +x ./bin/mithril-client | |
chmod +x ./bin/mithril-signer | |
chmod +x ./mithril-end-to-end | |
mkdir artifacts | |
- name: Test | |
run: ./mithril-end-to-end --bin-directory ./bin --work-directory=./artifacts --devnet-scripts-directory=./mithril-test-lab/mithril-devnet | |
- name: Upload E2E Tests Artifacts | |
if: ${{ failure() }} | |
uses: actions/upload-artifact@v3 | |
with: | |
name: mithril-e2e-tests-artifacts-run_${{ github.run_number }}-attempt_${{ github.run_attempt }} | |
path: | | |
./artifacts/* | |
# including node.sock makes the upload fails so exclude them: | |
!./artifacts/**/node.sock | |
# exclude cardano tools, saving ~50mb of data: | |
!./artifacts/devnet/cardano-cli | |
!./artifacts/devnet/cardano-node | |
if-no-files-found: error | |
publish-tests-results: | |
if: github.event.pull_request.draft == false && ${{ always() }} | |
runs-on: ubuntu-latest | |
needs: [ test-mithril-core ] | |
steps: | |
- name: Download mithril-core Tests Results | |
if: always() | |
uses: actions/download-artifact@v3 | |
with: | |
name: test-results-mithril-core | |
- name: Download mithril-common Tests Results | |
if: always() | |
uses: actions/download-artifact@v3 | |
with: | |
name: test-results-mithril-common | |
- name: Download mithril-aggregator Tests Results | |
if: always() | |
uses: actions/download-artifact@v3 | |
with: | |
name: test-results-mithril-aggregator | |
- name: Download mithril-client Tests Results | |
if: always() | |
uses: actions/download-artifact@v3 | |
with: | |
name: test-results-mithril-client | |
- name: Download mithril-signer Tests Results | |
if: always() | |
uses: actions/download-artifact@v3 | |
with: | |
name: test-results-mithril-signer | |
- name: Download mithril-end-to-end Tests Results | |
if: always() | |
uses: actions/download-artifact@v3 | |
with: | |
name: test-results-mithril-end-to-end | |
- name: Download mithril-demo Tests Results | |
if: always() | |
uses: actions/download-artifact@v3 | |
with: | |
name: test-results-mithrildemo | |
- name: Publish Unit Test Results | |
if: always() | |
uses: EnricoMi/publish-unit-test-result-action@v1 | |
with: | |
files: ./**/test-results-*.xml | |
docker-mithril: | |
runs-on: ubuntu-latest | |
if: ${{ github.event_name == 'push' }} | |
needs: | |
- test-mithril-core | |
- run-test-lab | |
strategy: | |
fail-fast: false | |
matrix: | |
project: [ mithril-aggregator, mithril-client, mithril-signer ] | |
permissions: | |
contents: read | |
packages: write | |
env: | |
PUSH_PACKAGES: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository_owner }}/${{ matrix.project }} | |
DOCKER_FILE: ./${{ matrix.project }}/Dockerfile.ci | |
CONTEXT: . | |
GITHUB_REF: ${{ github.ref}} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Log in to the Container registry | |
uses: docker/login-action@v1 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v3 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: | | |
latest | |
type=raw,value={{branch}}-{{sha}} | |
- name: Download ${{ matrix.project }} executable | |
uses: actions/download-artifact@v3 | |
with: | |
name: ${{ matrix.project }} | |
path: ${{ matrix.project }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v2 | |
with: | |
context: ${{ env.CONTEXT }} | |
file: ${{ env.DOCKER_FILE }} | |
push: ${{ env.PUSH_PACKAGES }} | |
tags: ${{ steps.meta.outputs.tags }} | |
deploy-nightly: | |
if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
runs-on: ubuntu-latest | |
needs: | |
- test-mithril-core | |
- run-test-lab | |
steps: | |
- name: Download mithril-core lib | |
uses: actions/download-artifact@v3 | |
with: | |
name: mithril-core | |
path: ./build | |
- name: Download aggregator | |
uses: actions/download-artifact@v3 | |
with: | |
name: mithril-aggregator | |
path: ./build | |
- name: Download signer | |
uses: actions/download-artifact@v3 | |
with: | |
name: mithril-signer | |
path: ./build | |
- name: Download client | |
uses: actions/download-artifact@v3 | |
with: | |
name: mithril-client | |
path: ./build | |
- name: Update nightly release | |
uses: marvinpinto/action-automatic-releases@latest | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
automatic_release_tag: nightly | |
prerelease: true | |
title: Nightly Development Builds | |
files: build/* | |
generate-publish-docs: | |
if: github.event.pull_request.draft == false | |
runs-on: ubuntu-latest | |
needs: | |
- docker-mithril | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@v2 | |
- name: Download mithril-core-doc artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: mithril-core-doc | |
path: ./github-pages/mithril-core/doc | |
- name: Download mithril-common-doc artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: mithril-common-doc | |
path: ./github-pages/mithril-common/doc | |
- name: Download aggregator-doc artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: mithril-aggregator-doc | |
path: ./github-pages/mithril-aggregator/doc | |
- name: Download client-doc artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: mithril-client-doc | |
path: ./github-pages/mithril-client/doc | |
- name: Download signer-doc artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: mithril-signer-doc | |
path: ./github-pages/mithril-signer/doc | |
- name: Mithril Aggregator / Generate OpenAPI UI | |
uses: Legion2/swagger-ui-action@v1 | |
with: | |
output: ./github-pages/openapi-ui | |
spec-file: ./openapi.yaml | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 16 | |
cache: 'yarn' | |
cache-dependency-path: docs/yarn.lock | |
- name: Documentation (Docusaurus) | |
working-directory: docs | |
run: | | |
yarn && yarn build | |
mkdir -p ../github-pages/doc | |
mv build/* ../github-pages/doc | |
echo "mithril.network" > ../github-pages/CNAME | |
echo '<!DOCTYPE html><html><head><meta http-equiv="Refresh" content="0; URL=https://mithril.network/doc"></head></html>' > ../github-pages/index.html | |
- name: Explorer | |
working-directory: mithril-explorer | |
run: | | |
make build | |
mkdir -p ../github-pages/explorer | |
mv out/* ../github-pages/explorer | |
- name: Mithril / Publish Github Pages | |
uses: peaceiris/actions-gh-pages@v3 | |
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN || github.token }} | |
publish_dir: ./github-pages | |
terraform: | |
runs-on: ubuntu-latest | |
needs: | |
- docker-mithril | |
env: | |
# Contains a JSON-formatted service account key | |
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }} | |
# Contains a RSA private key | |
GCLOUD_PRIVATE_KEY: ${{ secrets.GCLOUD_PRIVATE_KEY }} | |
BRANCH_NAME: ${{ github.head_ref || github.ref_name }} | |
defaults: | |
run: | |
working-directory: mithril-infra | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@v2 | |
- name: Get short SHA | |
id: slug | |
run: echo "::set-output name=sha8::$(echo ${{ github.sha }} | cut -c1-7)" | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v1 | |
with: | |
terraform_wrapper: false | |
- name: Init Terraform | |
run: terraform init | |
- name: Check Terraform | |
run: terraform fmt -check | |
- name: Terraform Plan | |
run: | | |
terraform plan -var "image_id=${{ env.BRANCH_NAME }}-${{ steps.slug.outputs.sha8 }}" -var 'private_key=${{ env.GCLOUD_PRIVATE_KEY }}' -var 'google_application_credentials_json=${{ env.GOOGLE_CREDENTIALS }}' | |
- name: Update Pull Request | |
uses: actions/github-script@v6 | |
if: github.event_name == 'pull_request' | |
env: | |
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}" | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\` | |
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` | |
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\` | |
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\` | |
<details><summary>Show Plan</summary> | |
\`\`\`\n | |
${process.env.PLAN} | |
\`\`\` | |
</details> | |
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: output | |
}) | |
- name: Terraform Apply | |
if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
run: | | |
terraform apply -auto-approve -var "image_id=${{ env.BRANCH_NAME }}-${{ steps.slug.outputs.sha8 }}" -var 'private_key=${{ env.GCLOUD_PRIVATE_KEY }}' -var 'google_application_credentials_json=${{ env.GOOGLE_CREDENTIALS }}' |