diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 3b64dcf36..636694a46 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -12,23 +12,41 @@ jobs: runs-on: [compile-gke] container: image: mangatasolutions/node-builder:multi-nightly-2023-05-22 + env: + JOB_CACHE_PREFIX: node-docs-cache-1 + CACHE_ARCHIVE_NAME: cache_archive.tar.zst steps: - uses: actions/checkout@v4 - uses: google-github-actions/auth@v2 + id: auth with: - workload_identity_provider: '${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}' - service_account: '${{ secrets.GCP_SERVICE_ACCOUNT }}' - - name: Cache the Cargo dependencies - uses: mansagroup/gcs-cache-action@v1.0.3 - with: - bucket: mangata-node-ci-cache - path: | - ${{ github.workspace }}/target - /usr/local/cargo/git - /usr/local/cargo/registry - ~/.cache/sccache - key: node-docs-cache-1-${{ hashFiles('Cargo.lock') }} + workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }} + service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }} + - uses: google-github-actions/setup-gcloud@v2 + + - name: Download cargo build cache + id: cache + run: | + set -x + CACHE_KEY="${{ env.JOB_CACHE_PREFIX }}-${{ hashFiles('**/Cargo.lock') }}" + ARCHIVE_NAME="${{ env.CACHE_ARCHIVE_NAME }}" + CACHE_FOUND=false + + if gcloud storage cp "gs://mangata-node-ci-cache/$CACHE_KEY/$ARCHIVE_NAME" - | zstd -d | tar -xf - -C / ; then + CACHE_FOUND=true + fi + + echo "cache_found=$CACHE_FOUND" >> $GITHUB_OUTPUT + echo "cache_key=$CACHE_KEY" >> $GITHUB_OUTPUT + + - uses: mozilla-actions/sccache-action@v0.0.5 + - run: | + echo "SCCACHE_GCS_BUCKET=mangata-node-ci-cache" >> $GITHUB_ENV + echo "SCCACHE_GCS_RW_MODE=READ_WRITE" >> $GITHUB_ENV + echo "SCCACHE_GCS_KEY_PREFIX=${{ env.JOB_CACHE_PREFIX }}" >> $GITHUB_ENV + echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV + echo "CARGO_INCREMENTAL=0" >> $GITHUB_ENV - name: Build docs run: cargo doc @@ -40,4 +58,24 @@ jobs: destination: mangata-docs-node parent: false concurrency: 50 - process_gcloudignore: false \ No newline at end of file + process_gcloudignore: false + + - name: Upload cargo build cache + shell: bash + run: | + set -x + CACHE_KEY="${{ steps.cache.outputs.cache_key }}" + ARCHIVE_NAME="${{ env.CACHE_ARCHIVE_NAME }}" + CACHE_PATHS=( + "./target" + "/usr/local/cargo/bin/" + "/usr/local/cargo/registry/index/" + "/usr/local/cargo/registry/cache/" + "/usr/local/cargo/git/db/" + ) + + SECONDS=0; tar -cf - "${CACHE_PATHS[@]}" | zstd -T0 -5 > "$ARCHIVE_NAME" + echo "Compression completed in $SECONDS seconds" && echo "Archive size: $(du -h "$ARCHIVE_NAME" | cut -f1)" + + SECONDS=0; gcloud storage cp "$ARCHIVE_NAME" "gs://mangata-node-ci-cache/$CACHE_KEY/$ARCHIVE_NAME" + echo "Upload completed in $SECONDS seconds" \ No newline at end of file diff --git a/.github/workflows/reusable-build-and-test.yml b/.github/workflows/reusable-build-and-test.yml index 891f2a039..720d5b5a3 100644 --- a/.github/workflows/reusable-build-and-test.yml +++ b/.github/workflows/reusable-build-and-test.yml @@ -22,6 +22,11 @@ on: description: Cache version variable to be used to invalidate cache when needed required: false type: number + cache-enabled: + default: true + description: Enable cargo build cache + required: false + type: boolean permissions: contents: read @@ -37,24 +42,45 @@ jobs: DOCKER_HOST: "unix:///run/docker/docker.sock" volumes: - /run/docker:/run/docker + env: + JOB_CACHE_PREFIX: mangata-node-image-build-job-cache-${{ inputs.cache-version }} + CACHE_ARCHIVE_NAME: cache_archive.tar.zst steps: - - uses: actions/checkout@v3 - - name: Authenticate to Google Cloud - uses: google-github-actions/auth@v1 + - uses: actions/checkout@v4 + - uses: google-github-actions/auth@v2 + id: auth with: - workload_identity_provider: "${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}" - service_account: "${{ secrets.GCP_SERVICE_ACCOUNT }}" + workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }} + service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }} + - uses: google-github-actions/setup-gcloud@v2 - - name: Cache the Cargo dependencies - uses: mansagroup/gcs-cache-action@v1.0.3 - with: - bucket: mangata-node-ci-cache - path: | - ${{ github.workspace }}/target - /usr/local/cargo/git - /usr/local/cargo/registry - ~/.cache/sccache - key: node-cache-${{ inputs.cache_version }}-${{ hashFiles('Cargo.lock') }} + - name: Download cargo build cache + if: inputs.cache-enabled + id: cache + run: | + set -x + CACHE_KEY="${{ env.JOB_CACHE_PREFIX }}-${{ hashFiles('**/Cargo.lock') }}" + ARCHIVE_NAME="${{ env.CACHE_ARCHIVE_NAME }}" + CACHE_FOUND=false + + if gcloud storage cp "gs://mangata-node-ci-cache/$CACHE_KEY/$ARCHIVE_NAME" - | zstd -d | tar -xf - -C / ; then + CACHE_FOUND=true + fi + + echo "cache_found=$CACHE_FOUND" >> $GITHUB_OUTPUT + echo "cache_key=$CACHE_KEY" >> $GITHUB_OUTPUT + + - name: Install sccache-cache only on non-release runs + if: github.event_name != 'release' && github.event_name != 'workflow_dispatch' + uses: mozilla-actions/sccache-action@v0.0.5 + - name: Set Rust caching env vars only on non-release run + if: github.event_name != 'release' && github.event_name != 'workflow_dispatch' + run: | + echo "SCCACHE_GCS_BUCKET=mangata-node-ci-cache" >> $GITHUB_ENV + echo "SCCACHE_GCS_RW_MODE=READ_WRITE" >> $GITHUB_ENV + echo "SCCACHE_GCS_KEY_PREFIX=${{ env.JOB_CACHE_PREFIX }}" >> $GITHUB_ENV + echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV + echo "CARGO_INCREMENTAL=0" >> $GITHUB_ENV - name: Compile mangata-node code run: cargo build --locked --release --no-default-features --features=mangata-rococo,mangata-kusama @@ -110,9 +136,26 @@ jobs: ./mangata_kusama_runtime-${{ inputs.version }}-fast.compact.compressed.wasm ./mangata_rococo_runtime-${{ inputs.version }}-fast.compact.compressed.wasm - - name: Fix permissions on self-hosted runner - if: always() - run: chown -R 1100:1100 $GITHUB_WORKSPACE + - name: Upload cargo build cache + if: inputs.cache-enabled && steps.cache.outputs.cache_found == 'false' + shell: bash + run: | + set -x + CACHE_KEY="${{ steps.cache.outputs.cache_key }}" + ARCHIVE_NAME="${{ env.CACHE_ARCHIVE_NAME }}" + CACHE_PATHS=( + "./target" + "/usr/local/cargo/bin/" + "/usr/local/cargo/registry/index/" + "/usr/local/cargo/registry/cache/" + "/usr/local/cargo/git/db/" + ) + + SECONDS=0; tar -cf - "${CACHE_PATHS[@]}" | zstd -T0 -5 > "$ARCHIVE_NAME" + echo "Compression completed in $SECONDS seconds" && echo "Archive size: $(du -h "$ARCHIVE_NAME" | cut -f1)" + + SECONDS=0; gcloud storage cp "$ARCHIVE_NAME" "gs://mangata-node-ci-cache/$CACHE_KEY/$ARCHIVE_NAME" + echo "Upload completed in $SECONDS seconds" rustfmt-check: name: Formatting check @@ -129,49 +172,138 @@ jobs: runs-on: ubuntu-latest container: image: ${{ inputs.builder_image }} + env: + JOB_CACHE_PREFIX: mangata-node-clippy-job-cache-${{ inputs.cache-version }} + CACHE_ARCHIVE_NAME: cache_archive.tar.zst steps: - - uses: actions/checkout@v3 - - name: Authenticate to Google Cloud - uses: google-github-actions/auth@v1 - with: - workload_identity_provider: "${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}" - service_account: "${{ secrets.GCP_SERVICE_ACCOUNT }}" - - name: Cache the Cargo dependencies - uses: mansagroup/gcs-cache-action@v1.0.3 + - uses: actions/checkout@v4 + - uses: google-github-actions/auth@v2 + id: auth with: - bucket: mangata-node-ci-cache - path: | - ${{ github.workspace }}/target - /usr/local/cargo/git - /usr/local/cargo/registry - key: cargo-clippy-cache-${{ inputs.cache_version }}-${{ hashFiles('Cargo.lock') }} + workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }} + service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }} + - uses: google-github-actions/setup-gcloud@v2 + + - name: Download cargo build cache + if: inputs.cache-enabled + id: cache + run: | + set -x + CACHE_KEY="${{ env.JOB_CACHE_PREFIX }}-${{ hashFiles('**/Cargo.lock') }}" + ARCHIVE_NAME="${{ env.CACHE_ARCHIVE_NAME }}" + CACHE_FOUND=false + + if gcloud storage cp "gs://mangata-node-ci-cache/$CACHE_KEY/$ARCHIVE_NAME" - | zstd -d | tar -xf - -C / ; then + CACHE_FOUND=true + fi + + echo "cache_found=$CACHE_FOUND" >> $GITHUB_OUTPUT + echo "cache_key=$CACHE_KEY" >> $GITHUB_OUTPUT + + - name: Install sccache-cache only on non-release runs + if: github.event_name != 'release' && github.event_name != 'workflow_dispatch' + uses: mozilla-actions/sccache-action@v0.0.5 + - name: Set Rust caching env vars only on non-release run + if: github.event_name != 'release' && github.event_name != 'workflow_dispatch' + run: | + echo "SCCACHE_GCS_BUCKET=mangata-node-ci-cache" >> $GITHUB_ENV + echo "SCCACHE_GCS_RW_MODE=READ_WRITE" >> $GITHUB_ENV + echo "SCCACHE_GCS_KEY_PREFIX=${{ env.JOB_CACHE_PREFIX }}" >> $GITHUB_ENV + echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV + echo "CARGO_INCREMENTAL=0" >> $GITHUB_ENV - name: Run clippy run: cargo clippy -p pallet-xyk + - name: Upload cargo build cache + if: inputs.cache-enabled && steps.cache.outputs.cache_found == 'false' + shell: bash + run: | + set -x + CACHE_KEY="${{ steps.cache.outputs.cache_key }}" + ARCHIVE_NAME="${{ env.CACHE_ARCHIVE_NAME }}" + CACHE_PATHS=( + "./target" + "/usr/local/cargo/bin/" + "/usr/local/cargo/registry/index/" + "/usr/local/cargo/registry/cache/" + "/usr/local/cargo/git/db/" + ) + + SECONDS=0; tar -cf - "${CACHE_PATHS[@]}" | zstd -T0 -5 > "$ARCHIVE_NAME" + echo "Compression completed in $SECONDS seconds" && echo "Archive size: $(du -h "$ARCHIVE_NAME" | cut -f1)" + + SECONDS=0; gcloud storage cp "$ARCHIVE_NAME" "gs://mangata-node-ci-cache/$CACHE_KEY/$ARCHIVE_NAME" + echo "Upload completed in $SECONDS seconds" + unit-test: name: Unit tests runs-on: [compile-gke] container: image: ${{ inputs.builder_image }} + env: + JOB_CACHE_PREFIX: mangata-node-unit-tests-cache-${{ inputs.cache-version }} + CACHE_ARCHIVE_NAME: cache_archive.tar.zst steps: - - uses: actions/checkout@v3 - - name: Authenticate to Google Cloud - uses: google-github-actions/auth@v1 + - uses: actions/checkout@v4 + - uses: google-github-actions/auth@v2 + id: auth with: - workload_identity_provider: "${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}" - service_account: "${{ secrets.GCP_SERVICE_ACCOUNT }}" - - name: Cache the Cargo dependencies - uses: mansagroup/gcs-cache-action@v1.0.3 - with: - bucket: mangata-node-ci-cache - path: | - ${{ github.workspace }}/target - /usr/local/cargo/git - /usr/local/cargo/registry - key: cargo-unit-cache-${{ inputs.cache_version }}-${{ hashFiles('Cargo.lock') }} + workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }} + service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }} + - uses: google-github-actions/setup-gcloud@v2 + + - name: Download cargo build cache + if: inputs.cache-enabled + id: cache + run: | + set -x + CACHE_KEY="${{ env.JOB_CACHE_PREFIX }}-${{ hashFiles('**/Cargo.lock') }}" + ARCHIVE_NAME="${{ env.CACHE_ARCHIVE_NAME }}" + CACHE_FOUND=false + + if gcloud storage cp "gs://mangata-node-ci-cache/$CACHE_KEY/$ARCHIVE_NAME" - | zstd -d | tar -xf - -C / ; then + CACHE_FOUND=true + fi + + echo "cache_found=$CACHE_FOUND" >> $GITHUB_OUTPUT + echo "cache_key=$CACHE_KEY" >> $GITHUB_OUTPUT + + - name: Install sccache-cache only on non-release runs + if: github.event_name != 'release' && github.event_name != 'workflow_dispatch' + uses: mozilla-actions/sccache-action@v0.0.5 + - name: Set Rust caching env vars only on non-release run + if: github.event_name != 'release' && github.event_name != 'workflow_dispatch' + run: | + echo "SCCACHE_GCS_BUCKET=mangata-node-ci-cache" >> $GITHUB_ENV + echo "SCCACHE_GCS_RW_MODE=READ_WRITE" >> $GITHUB_ENV + echo "SCCACHE_GCS_KEY_PREFIX=${{ env.JOB_CACHE_PREFIX }}" >> $GITHUB_ENV + echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV + echo "CARGO_INCREMENTAL=0" >> $GITHUB_ENV + - name: Run unit tests run: cargo test -j2 + - name: Upload cargo build cache + if: inputs.cache-enabled && steps.cache.outputs.cache_found == 'false' + shell: bash + run: | + set -x + CACHE_KEY="${{ steps.cache.outputs.cache_key }}" + ARCHIVE_NAME="${{ env.CACHE_ARCHIVE_NAME }}" + CACHE_PATHS=( + "./target" + "/usr/local/cargo/bin/" + "/usr/local/cargo/registry/index/" + "/usr/local/cargo/registry/cache/" + "/usr/local/cargo/git/db/" + ) + + SECONDS=0; tar -cf - "${CACHE_PATHS[@]}" | zstd -T0 -5 > "$ARCHIVE_NAME" + echo "Compression completed in $SECONDS seconds" && echo "Archive size: $(du -h "$ARCHIVE_NAME" | cut -f1)" + + SECONDS=0; gcloud storage cp "$ARCHIVE_NAME" "gs://mangata-node-ci-cache/$CACHE_KEY/$ARCHIVE_NAME" + echo "Upload completed in $SECONDS seconds" + - name: Fix permissions on self-hosted runner if: always() run: chown -R 1100:1100 $GITHUB_WORKSPACE @@ -182,24 +314,48 @@ jobs: container: image: ${{ inputs.builder_image }} options: --security-opt seccomp=unconfined + env: + JOB_CACHE_PREFIX: mangata-node-coverage-job-cache-${{ inputs.cache-version }} + CACHE_ARCHIVE_NAME: cache_archive.tar.zst steps: - - uses: actions/checkout@v3 - - name: Authenticate to Google Cloud - uses: google-github-actions/auth@v1 + - uses: actions/checkout@v4 + - uses: google-github-actions/auth@v2 + id: auth with: - workload_identity_provider: "${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}" - service_account: "${{ secrets.GCP_SERVICE_ACCOUNT }}" - - name: Cache the Cargo dependencies - uses: mansagroup/gcs-cache-action@v1.0.3 - with: - bucket: mangata-node-ci-cache - path: | - ${{ github.workspace }}/target - /usr/local/cargo/git - /usr/local/cargo/registry - key: cargo-coverage-cache-${{ inputs.cache_version }}-${{ hashFiles('Cargo.lock') }} + workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }} + service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }} + - uses: google-github-actions/setup-gcloud@v2 + + - name: Download cargo build cache + if: inputs.cache-enabled + id: cache + run: | + set -x + CACHE_KEY="${{ env.JOB_CACHE_PREFIX }}-${{ hashFiles('**/Cargo.lock') }}" + ARCHIVE_NAME="${{ env.CACHE_ARCHIVE_NAME }}" + CACHE_FOUND=false + + if gcloud storage cp "gs://mangata-node-ci-cache/$CACHE_KEY/$ARCHIVE_NAME" - | zstd -d | tar -xf - -C / ; then + CACHE_FOUND=true + fi + + echo "cache_found=$CACHE_FOUND" >> $GITHUB_OUTPUT + echo "cache_key=$CACHE_KEY" >> $GITHUB_OUTPUT + + - name: Install sccache-cache only on non-release runs + if: github.event_name != 'release' && github.event_name != 'workflow_dispatch' + uses: mozilla-actions/sccache-action@v0.0.5 + - name: Set Rust caching env vars only on non-release run + if: github.event_name != 'release' && github.event_name != 'workflow_dispatch' + run: | + echo "SCCACHE_GCS_BUCKET=mangata-node-ci-cache" >> $GITHUB_ENV + echo "SCCACHE_GCS_RW_MODE=READ_WRITE" >> $GITHUB_ENV + echo "SCCACHE_GCS_KEY_PREFIX=${{ env.JOB_CACHE_PREFIX }}" >> $GITHUB_ENV + echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV + echo "CARGO_INCREMENTAL=0" >> $GITHUB_ENV + - name: Install cargo-tarpaulin - run: cargo install cargo-tarpaulin@0.26.1 + run: which cargo-tarpaulin || cargo install cargo-tarpaulin@0.26.1 --locked - name: Generate coverage report with cargo-tarpaulin run: cargo tarpaulin --timeout 120 --workspace -e runtime-integration-test mangata-node common-runtime mangata-kusama-runtime mangata-rococo-runtime --exclude-files **/mock.rs **/weights.rs **/weights/* --out Xml - name: Upload to codecov.io @@ -208,6 +364,27 @@ jobs: token: ${{ secrets.ORG_CODECOV_TOKEN }} fail_ci_if_error: true + - name: Upload cargo build cache + if: inputs.cache-enabled && steps.cache.outputs.cache_found == 'false' + shell: bash + run: | + set -x + CACHE_KEY="${{ steps.cache.outputs.cache_key }}" + ARCHIVE_NAME="${{ env.CACHE_ARCHIVE_NAME }}" + CACHE_PATHS=( + "./target" + "/usr/local/cargo/bin/" + "/usr/local/cargo/registry/index/" + "/usr/local/cargo/registry/cache/" + "/usr/local/cargo/git/db/" + ) + + SECONDS=0; tar -cf - "${CACHE_PATHS[@]}" | zstd -T0 -5 > "$ARCHIVE_NAME" + echo "Compression completed in $SECONDS seconds" && echo "Archive size: $(du -h "$ARCHIVE_NAME" | cut -f1)" + + SECONDS=0; gcloud storage cp "$ARCHIVE_NAME" "gs://mangata-node-ci-cache/$CACHE_KEY/$ARCHIVE_NAME" + echo "Upload completed in $SECONDS seconds" + - name: Fix permissions on self-hosted runner if: always() run: chown -R 1100:1100 $GITHUB_WORKSPACE @@ -217,22 +394,45 @@ jobs: runs-on: ubuntu-latest container: image: ${{ inputs.builder_image }} + env: + JOB_CACHE_PREFIX: mangata-node-becnhmark-tests-job-cache-${{ inputs.cache-version }} + CACHE_ARCHIVE_NAME: cache_archive.tar.zst steps: - - uses: actions/checkout@v3 - - name: Authenticate to Google Cloud - uses: google-github-actions/auth@v1 + - uses: actions/checkout@v4 + - uses: google-github-actions/auth@v2 + id: auth with: - workload_identity_provider: "${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}" - service_account: "${{ secrets.GCP_SERVICE_ACCOUNT }}" - - name: Cache the Cargo dependencies - uses: mansagroup/gcs-cache-action@v1.0.3 - with: - bucket: mangata-node-ci-cache - path: | - ${{ github.workspace }}/target - /usr/local/cargo/git - /usr/local/cargo/registry - key: cargo-benchmark-cache-${{ inputs.cache_version }}-${{ hashFiles('Cargo.lock') }} + workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }} + service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }} + - uses: google-github-actions/setup-gcloud@v2 + + - name: Download cargo build cache + if: inputs.cache-enabled + id: cache + run: | + set -x + CACHE_KEY="${{ env.JOB_CACHE_PREFIX }}-${{ hashFiles('**/Cargo.lock') }}" + ARCHIVE_NAME="${{ env.CACHE_ARCHIVE_NAME }}" + CACHE_FOUND=false + + if gcloud storage cp "gs://mangata-node-ci-cache/$CACHE_KEY/$ARCHIVE_NAME" - | zstd -d | tar -xf - -C / ; then + CACHE_FOUND=true + fi + + echo "cache_found=$CACHE_FOUND" >> $GITHUB_OUTPUT + echo "cache_key=$CACHE_KEY" >> $GITHUB_OUTPUT + + - name: Install sccache-cache only on non-release runs + if: github.event_name != 'release' && github.event_name != 'workflow_dispatch' + uses: mozilla-actions/sccache-action@v0.0.5 + - name: Set Rust caching env vars only on non-release run + if: github.event_name != 'release' && github.event_name != 'workflow_dispatch' + run: | + echo "SCCACHE_GCS_BUCKET=mangata-node-ci-cache" >> $GITHUB_ENV + echo "SCCACHE_GCS_RW_MODE=READ_WRITE" >> $GITHUB_ENV + echo "SCCACHE_GCS_KEY_PREFIX=${{ env.JOB_CACHE_PREFIX }}" >> $GITHUB_ENV + echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV + echo "CARGO_INCREMENTAL=0" >> $GITHUB_ENV - name: Run benchmarks tests run: cargo test --release -j8 --features=runtime-benchmarks -p pallet-xyk -p pallet-issuance -p pallet-multipurpose-liquidity -p pallet-fee-lock - name: Run benchmarks tests @@ -240,29 +440,72 @@ jobs: # NOTE: MGX-742 - name: Run benchmarks tests run: cargo test --release -j8 --features=runtime-benchmarks -p pallet-proof-of-stake + + - name: Upload cargo build cache + if: inputs.cache-enabled && steps.cache.outputs.cache_found == 'false' + shell: bash + run: | + set -x + CACHE_KEY="${{ steps.cache.outputs.cache_key }}" + ARCHIVE_NAME="${{ env.CACHE_ARCHIVE_NAME }}" + CACHE_PATHS=( + "./target" + "/usr/local/cargo/bin/" + "/usr/local/cargo/registry/index/" + "/usr/local/cargo/registry/cache/" + "/usr/local/cargo/git/db/" + ) + + SECONDS=0; tar -cf - "${CACHE_PATHS[@]}" | zstd -T0 -5 > "$ARCHIVE_NAME" + echo "Compression completed in $SECONDS seconds" && echo "Archive size: $(du -h "$ARCHIVE_NAME" | cut -f1)" + + SECONDS=0; gcloud storage cp "$ARCHIVE_NAME" "gs://mangata-node-ci-cache/$CACHE_KEY/$ARCHIVE_NAME" + echo "Upload completed in $SECONDS seconds" build-and-run-try-runtime: name: Run try-runtime checks runs-on: [compile-gke] container: image: ${{ inputs.builder_image }} + env: + JOB_CACHE_PREFIX: mangata-node-try-runtime-job-cache-${{ inputs.cache-version }} + CACHE_ARCHIVE_NAME: cache_archive.tar.zst steps: - - uses: actions/checkout@v3 - - name: Authenticate to Google Cloud - uses: google-github-actions/auth@v1 - with: - workload_identity_provider: "${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}" - service_account: "${{ secrets.GCP_SERVICE_ACCOUNT }}" - - name: Cache the Cargo dependencies - uses: mansagroup/gcs-cache-action@v1.0.3 + - uses: actions/checkout@v4 + - uses: google-github-actions/auth@v2 + id: auth with: - bucket: mangata-node-ci-cache - path: | - ${{ github.workspace }}/target - /usr/local/cargo/git - /usr/local/cargo/registry - ~/.cache/sccache - key: cargo-try-runtime-${{ inputs.cache_version }}-${{ hashFiles('Cargo.lock') }} + workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }} + service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }} + - uses: google-github-actions/setup-gcloud@v2 + + - name: Download cargo build cache + if: inputs.cache-enabled + id: cache + run: | + set -x + CACHE_KEY="${{ env.JOB_CACHE_PREFIX }}-${{ hashFiles('**/Cargo.lock') }}" + ARCHIVE_NAME="${{ env.CACHE_ARCHIVE_NAME }}" + CACHE_FOUND=false + + if gcloud storage cp "gs://mangata-node-ci-cache/$CACHE_KEY/$ARCHIVE_NAME" - | zstd -d | tar -xf - -C / ; then + CACHE_FOUND=true + fi + + echo "cache_found=$CACHE_FOUND" >> $GITHUB_OUTPUT + echo "cache_key=$CACHE_KEY" >> $GITHUB_OUTPUT + + - name: Install sccache-cache only on non-release runs + if: github.event_name != 'release' && github.event_name != 'workflow_dispatch' + uses: mozilla-actions/sccache-action@v0.0.5 + - name: Set Rust caching env vars only on non-release run + if: github.event_name != 'release' && github.event_name != 'workflow_dispatch' + run: | + echo "SCCACHE_GCS_BUCKET=mangata-node-ci-cache" >> $GITHUB_ENV + echo "SCCACHE_GCS_RW_MODE=READ_WRITE" >> $GITHUB_ENV + echo "SCCACHE_GCS_KEY_PREFIX=${{ env.JOB_CACHE_PREFIX }}" >> $GITHUB_ENV + echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV + echo "CARGO_INCREMENTAL=0" >> $GITHUB_ENV - name: Build try-runtime Rococo & Kusama node run: cargo build --release --features=try-runtime,mangata-rococo,mangata-kusama @@ -273,6 +516,27 @@ jobs: - name: Run try-runtime Kusama Mainnet run: try-runtime --runtime=target/release/wbuild/mangata-kusama-runtime/mangata_kusama_runtime.wasm on-runtime-upgrade live --uri wss://kusama-rpc.mangata.online:443 + - name: Upload cargo build cache + if: inputs.cache-enabled && steps.cache.outputs.cache_found == 'false' + shell: bash + run: | + set -x + CACHE_KEY="${{ steps.cache.outputs.cache_key }}" + ARCHIVE_NAME="${{ env.CACHE_ARCHIVE_NAME }}" + CACHE_PATHS=( + "./target" + "/usr/local/cargo/bin/" + "/usr/local/cargo/registry/index/" + "/usr/local/cargo/registry/cache/" + "/usr/local/cargo/git/db/" + ) + + SECONDS=0; tar -cf - "${CACHE_PATHS[@]}" | zstd -T0 -5 > "$ARCHIVE_NAME" + echo "Compression completed in $SECONDS seconds" && echo "Archive size: $(du -h "$ARCHIVE_NAME" | cut -f1)" + + SECONDS=0; gcloud storage cp "$ARCHIVE_NAME" "gs://mangata-node-ci-cache/$CACHE_KEY/$ARCHIVE_NAME" + echo "Upload completed in $SECONDS seconds" + - name: Fix permissions on self-hosted runner if: always() run: chown -R 1100:1100 $GITHUB_WORKSPACE @@ -281,29 +545,49 @@ jobs: name: Run runtime benchmarks # `performance` self-hosted runners have 8 cores and 16GB of RAM runs-on: [performance-gke] + container: + image: ${{ inputs.builder_image }} env: STEPS: 2 REPEATS: 1 - container: - image: ${{ inputs.builder_image }} + JOB_CACHE_PREFIX: mangata-node-run-benchmarks-job-cache-${{ inputs.cache-version }} + CACHE_ARCHIVE_NAME: cache_archive.tar.zst steps: - - uses: actions/checkout@v3 - - name: Authenticate to Google Cloud - uses: google-github-actions/auth@v1 + - uses: actions/checkout@v4 + - uses: google-github-actions/auth@v2 + id: auth with: - workload_identity_provider: "${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}" - service_account: "${{ secrets.GCP_SERVICE_ACCOUNT }}" + workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }} + service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }} + - uses: google-github-actions/setup-gcloud@v2 - - name: Cache the Cargo dependencies - uses: mansagroup/gcs-cache-action@v1.0.3 - with: - bucket: mangata-node-ci-cache - path: | - ${{ github.workspace }}/target - /usr/local/cargo/git - /usr/local/cargo/registry - ~/.cache/sccache - key: runtime-benchmark-cache-${{ inputs.cache_version }}-${{ hashFiles('Cargo.lock') }} + - name: Download cargo build cache + if: inputs.cache-enabled + id: cache + run: | + set -x + CACHE_KEY="${{ env.JOB_CACHE_PREFIX }}-${{ hashFiles('**/Cargo.lock') }}" + ARCHIVE_NAME="${{ env.CACHE_ARCHIVE_NAME }}" + CACHE_FOUND=false + + if gcloud storage cp "gs://mangata-node-ci-cache/$CACHE_KEY/$ARCHIVE_NAME" - | zstd -d | tar -xf - -C / ; then + CACHE_FOUND=true + fi + + echo "cache_found=$CACHE_FOUND" >> $GITHUB_OUTPUT + echo "cache_key=$CACHE_KEY" >> $GITHUB_OUTPUT + + - name: Install sccache-cache only on non-release runs + if: github.event_name != 'release' && github.event_name != 'workflow_dispatch' + uses: mozilla-actions/sccache-action@v0.0.5 + - name: Set Rust caching env vars only on non-release run + if: github.event_name != 'release' && github.event_name != 'workflow_dispatch' + run: | + echo "SCCACHE_GCS_BUCKET=mangata-node-ci-cache" >> $GITHUB_ENV + echo "SCCACHE_GCS_RW_MODE=READ_WRITE" >> $GITHUB_ENV + echo "SCCACHE_GCS_KEY_PREFIX=${{ env.JOB_CACHE_PREFIX }}" >> $GITHUB_ENV + echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV + echo "CARGO_INCREMENTAL=0" >> $GITHUB_ENV - name: Compile mangata-node code run: cargo build --release --no-default-features --features=mangata-rococo,mangata-kusama,runtime-benchmarks @@ -340,6 +624,27 @@ jobs: name: benchmarks path: ./benchmarks + - name: Upload cargo build cache + if: inputs.cache-enabled && steps.cache.outputs.cache_found == 'false' + shell: bash + run: | + set -x + CACHE_KEY="${{ steps.cache.outputs.cache_key }}" + ARCHIVE_NAME="${{ env.CACHE_ARCHIVE_NAME }}" + CACHE_PATHS=( + "./target" + "/usr/local/cargo/bin/" + "/usr/local/cargo/registry/index/" + "/usr/local/cargo/registry/cache/" + "/usr/local/cargo/git/db/" + ) + + SECONDS=0; tar -cf - "${CACHE_PATHS[@]}" | zstd -T0 -5 > "$ARCHIVE_NAME" + echo "Compression completed in $SECONDS seconds" && echo "Archive size: $(du -h "$ARCHIVE_NAME" | cut -f1)" + + SECONDS=0; gcloud storage cp "$ARCHIVE_NAME" "gs://mangata-node-ci-cache/$CACHE_KEY/$ARCHIVE_NAME" + echo "Upload completed in $SECONDS seconds" + - name: Fix permissions on self-hosted runner if: always() run: chown -R 1100:1100 $GITHUB_WORKSPACE @@ -347,29 +652,49 @@ jobs: build-wasms: name: Export wasm artifacts runs-on: [compile-gke] + container: + image: ${{ inputs.builder_image }} env: STEPS: 2 REPEATS: 1 - container: - image: ${{ inputs.builder_image }} + JOB_CACHE_PREFIX: mangata-node-build-wasms-job-cache-${{ inputs.cache-version }} + CACHE_ARCHIVE_NAME: cache_archive.tar.zst steps: - - uses: actions/checkout@v3 - - name: Authenticate to Google Cloud - uses: google-github-actions/auth@v1 + - uses: actions/checkout@v4 + - uses: google-github-actions/auth@v2 + id: auth with: - workload_identity_provider: "${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}" - service_account: "${{ secrets.GCP_SERVICE_ACCOUNT }}" + workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }} + service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }} + - uses: google-github-actions/setup-gcloud@v2 - - name: Cache the Cargo dependencies - uses: mansagroup/gcs-cache-action@v1.0.3 - with: - bucket: mangata-node-ci-cache - path: | - ${{ github.workspace }}/target - /usr/local/cargo/git - /usr/local/cargo/registry - ~/.cache/sccache - key: build-wasms-cache-${{ inputs.cache_version }}-${{ hashFiles('Cargo.lock') }} + - name: Download cargo build cache + if: inputs.cache-enabled + id: cache + run: | + set -x + CACHE_KEY="${{ env.JOB_CACHE_PREFIX }}-${{ hashFiles('**/Cargo.lock') }}" + ARCHIVE_NAME="${{ env.CACHE_ARCHIVE_NAME }}" + CACHE_FOUND=false + + if gcloud storage cp "gs://mangata-node-ci-cache/$CACHE_KEY/$ARCHIVE_NAME" - | zstd -d | tar -xf - -C / ; then + CACHE_FOUND=true + fi + + echo "cache_found=$CACHE_FOUND" >> $GITHUB_OUTPUT + echo "cache_key=$CACHE_KEY" >> $GITHUB_OUTPUT + + - name: Install sccache-cache only on non-release runs + if: github.event_name != 'release' && github.event_name != 'workflow_dispatch' + uses: mozilla-actions/sccache-action@v0.0.5 + - name: Set Rust caching env vars only on non-release run + if: github.event_name != 'release' && github.event_name != 'workflow_dispatch' + run: | + echo "SCCACHE_GCS_BUCKET=mangata-node-ci-cache" >> $GITHUB_ENV + echo "SCCACHE_GCS_RW_MODE=READ_WRITE" >> $GITHUB_ENV + echo "SCCACHE_GCS_KEY_PREFIX=${{ env.JOB_CACHE_PREFIX }}" >> $GITHUB_ENV + echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV + echo "CARGO_INCREMENTAL=0" >> $GITHUB_ENV - name: Compile mangata-node code run: cargo build --release --no-default-features --features=mangata-rococo,mangata-kusama,runtime-benchmarks @@ -385,6 +710,27 @@ jobs: /bin/bash -c 'target/release/mangata-node export-genesis-state --chain=mangata-rococo-local -l=info,xyk=error > /dev/null' /bin/bash -c 'target/release/mangata-node export-genesis-wasm --chain=mangata-rococo-local -l=info,xyk=error > /dev/null' + - name: Upload cargo build cache + if: inputs.cache-enabled && steps.cache.outputs.cache_found == 'false' + shell: bash + run: | + set -x + CACHE_KEY="${{ steps.cache.outputs.cache_key }}" + ARCHIVE_NAME="${{ env.CACHE_ARCHIVE_NAME }}" + CACHE_PATHS=( + "./target" + "/usr/local/cargo/bin/" + "/usr/local/cargo/registry/index/" + "/usr/local/cargo/registry/cache/" + "/usr/local/cargo/git/db/" + ) + + SECONDS=0; tar -cf - "${CACHE_PATHS[@]}" | zstd -T0 -5 > "$ARCHIVE_NAME" + echo "Compression completed in $SECONDS seconds" && echo "Archive size: $(du -h "$ARCHIVE_NAME" | cut -f1)" + + SECONDS=0; gcloud storage cp "$ARCHIVE_NAME" "gs://mangata-node-ci-cache/$CACHE_KEY/$ARCHIVE_NAME" + echo "Upload completed in $SECONDS seconds" + - name: Fix permissions on self-hosted runner if: always() run: chown -R 1100:1100 $GITHUB_WORKSPACE