Skip to content

Running workflow for smart contracts #2469

Running workflow for smart contracts

Running workflow for smart contracts #2469

name: "<Callable> Run checks & build"
run-name: "Running workflow for smart contracts"
on:
workflow_dispatch:
inputs:
upload-artifacts:
description: "Upload optimized builds as artifacts."
required: true
default: false
type: "boolean"
push:
branches:
- "main"
tags:
- "*"
paths-ignore:
- "**.md"
- "./scripts/common/**"
- "./scripts/deploy-*.sh"
- "./scripts/export-*.sh"
pull_request:
branches:
- "main"
paths-ignore:
- "**.md"
- "./scripts/common/**"
- "./scripts/deploy-*.sh"
- "./scripts/export-*.sh"
concurrency:
cancel-in-progress: true
group: |-
${{ format('{0}-{1}-{2}', github.ref_name, github.ref_type, github.event_name, inputs.upload-artifacts) }}
defaults:
run:
shell: "sh"
env:
CARGO_TERM_COLOR: "always"
RELEASE_VERSION: "ci"
UPLOAD_ARTIFACTS: |-
${{ toJSON(github.ref_type == 'tag' || (github.event_name == 'workflow_dispatch' && inputs.upload-artifacts)) }}
jobs:
checks:
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v4"
- run: |-
"docker" \
"buildx" \
"build" \
--file "check.Containerfile" \
--tag "run-checks" \
"."
- run: |-
"mv" \
"./.github/test-data" \
"./build-configuration"
- run: |-
"docker" \
"run" \
--interactive \
--rm \
--tty \
--volume "./:/code/:ro,z" \
"run-checks"
# install_crates-io_tooling:
# runs-on: "ubuntu-latest"
# strategy:
# fail-fast: true
# matrix:
# tool:
# # Add necessary tooling
# - "cargo-audit"
# - "cargo-nextest"
# - "cargo-udeps"
# - "cosmwasm-check"
# name: |-
# Install tool [${{ matrix.tool }}; crates.io]
# steps:
# - uses: "actions/checkout@v4"
# - uses: "./.github/actions/install-tool"
# with:
# no-fetching: "true"
# fail-on-cache-miss: "false"
# tool: |-
# ${{ matrix.tool }}
# local: "false"
# cache_stable_rust_toolchain:
# runs-on: "ubuntu-latest"
# needs:
# - "configuration"
# name: "Cache stable Rust toolchain"
# steps:
# - uses: "actions/checkout@v4"
# - id: "restore-cache"
# uses: "./.github/actions/cache-rust"
# with:
# cache-cargo: "false"
# cache-rust-stable: "true"
# rust-stable: |-
# ${{ needs.configuration.outputs.stable-rust-version }}
# cache-rust-nightly: "false"
# no-fetching: "true"
# fail-on-cache-miss: "false"
# cache_nightly_rust_toolchain:
# runs-on: "ubuntu-latest"
# needs:
# - "configuration"
# name: "Cache nightly Rust toolchains"
# steps:
# - uses: "actions/checkout@v4"
# - id: "restore-cache"
# uses: "./.github/actions/cache-rust"
# with:
# cache-cargo: "false"
# cache-rust-stable: "false"
# cache-rust-nightly: "true"
# rust-nightly: |-
# ${{ needs.configuration.outputs.nightly-rust-version }}
# no-fetching: "true"
# fail-on-cache-miss: "false"
# cache_cargo_and_vendor_deps:
# runs-on: "ubuntu-latest"
# needs:
# - "configuration"
# - "cache_stable_rust_toolchain"
# strategy:
# fail-fast: true
# matrix:
# working-directory:
# - "platform"
# - "protocol"
# - "tests"
# - "tools"
# name: |-
# Cache Cargo and vendor dependencies [${{ matrix.working-directory }}]
# steps:
# - uses: "actions/checkout@v4"
# - id: "restore-cache"
# uses: "./.github/actions/cache-rust"
# with:
# cache-cargo: "true"
# working-directory: |-
# ${{ matrix.working-directory }}
# cache-rust-stable: "true"
# rust-stable: |-
# ${{ needs.configuration.outputs.stable-rust-version }}
# cache-rust-nightly: "false"
# no-fetching: "true"
# fail-on-cache-miss: "false"
# check_deps_versions:
# runs-on: "ubuntu-latest"
# needs:
# - "configuration"
# - "cache_stable_rust_toolchain"
# strategy:
# fail-fast: true
# matrix:
# working-directory:
# - "platform"
# - "protocol"
# - "tests"
# - "tools"
# name: |-
# Check dependencies' versions [${{ matrix.working-directory }}]
# steps:
# - if: |-
# env.UPLOAD_ARTIFACTS == 'true'
# uses: "actions/checkout@v4"
# - uses: "./.github/actions/cache-rust"
# if: |-
# env.UPLOAD_ARTIFACTS == 'true'
# with:
# cache-cargo: "false"
# cache-rust-stable: "true"
# rust-stable: |-
# ${{ needs.configuration.outputs.stable-rust-version }}
# cache-rust-nightly: "false"
# no-fetching: "false"
# fail-on-cache-miss: "true"
# - if: |-
# env.UPLOAD_ARTIFACTS == 'true'
# env:
# stable_rust_version: |-
# ${{ needs.configuration.outputs.stable-rust-version }}
# run: |-
# set -e
#
# "cargo" \
# "+${stable_rust_version:?}" \
# "update" \
# --locked
# working-directory: |-
# ${{ matrix.working-directory }}
# audit_dependencies:
# runs-on: "ubuntu-latest"
# needs:
# - "configuration"
# - "cache_stable_rust_toolchain"
# - "check_deps_versions"
# - "install_crates-io_tooling"
# strategy:
# fail-fast: true
# matrix:
# working-directory:
# - "platform"
# - "protocol"
# - "tests"
# - "tools"
# name: |-
# Audit dependencies [${{ matrix.working-directory }}]
# steps:
# - uses: "actions/checkout@v4"
# - uses: "./.github/actions/cache-rust"
# with:
# cache-cargo: "false"
# cache-rust-stable: "true"
# rust-stable: |-
# ${{ needs.configuration.outputs.stable-rust-version }}
# cache-rust-nightly: "false"
# no-fetching: "false"
# fail-on-cache-miss: "true"
# - uses: "./.github/actions/install-tool"
# with:
# no-fetching: "false"
# fail-on-cache-miss: "true"
# tool: "cargo-audit"
# local: "false"
# - env:
# working_directory: |-
# ${{ matrix.working-directory }}
# run: |-
# set -eu
#
# if "[" "-f" "./.cargo/audit.toml" "]"
# then
# if ! "[" "-d" "${working_directory}/.cargo" "]"
# then
# "mkdir" "${working_directory:?}/.cargo"
# fi
#
# "cp" \
# "./.cargo/audit.toml" \
# "${working_directory:?}/.cargo/audit.toml"
# fi
# - env:
# stable_rust_version: |-
# ${{ needs.configuration.outputs.stable-rust-version }}
# run: |-
# set -e
#
# "cargo" \
# "+${stable_rust_version:?}" \
# "audit"
# working-directory: |-
# ${{ matrix.working-directory }}
# check_formatting:
# runs-on: "ubuntu-latest"
# needs:
# - "configuration"
# - "cache_stable_rust_toolchain"
# strategy:
# fail-fast: true
# ### GitHub Actions escaped string
# matrix: "${{ fromJSON(needs.configuration.outputs.formatting-matrix-json) }}"
# name: |-
# Check formatting [${{ matrix.working-directory }}; ${{ matrix.network }}; ${{ matrix.protocol }}]
# steps:
# - uses: "actions/checkout@v4"
# - uses: "./.github/actions/cache-rust"
# with:
# cache-cargo: "false"
# cache-rust-stable: "true"
# rust-stable: |-
# ${{ needs.configuration.outputs.stable-rust-version }}
# cache-rust-nightly: "false"
# no-fetching: "false"
# fail-on-cache-miss: "true"
# - env:
# stable_rust_version: |-
# ${{ needs.configuration.outputs.stable-rust-version }}
# if: |-
# matrix.working-directory != 'protocol' || (
# matrix.network != '@agnostic' && matrix.protocol != '@agnostic'
# )
# run: |-
# set -e
#
# "cargo" \
# "+${stable_rust_version:?}" \
# "fmt" \
# --check
# working-directory: |-
# ${{ matrix.working-directory }}
# install_local_tooling:
# runs-on: "ubuntu-latest"
# needs:
# - "configuration"
# - "cache_stable_rust_toolchain"
# - "cache_cargo_and_vendor_deps"
# - "check_deps_versions"
# - "check_formatting"
# strategy:
# fail-fast: true
# matrix:
# tool:
# # Add necessary tooling
# - "cargo-each"
# name: |-
# Install tool [${{ matrix.tool }}; local]
# steps:
# - uses: "actions/checkout@v4"
# - uses: "./.github/actions/cache-rust"
# with:
# cache-cargo: "true"
# working-directory: "tools"
# cache-rust-stable: "true"
# rust-stable: |-
# ${{ needs.configuration.outputs.stable-rust-version }}
# cache-rust-nightly: "false"
# no-fetching: "false"
# fail-on-cache-miss: "false"
# - uses: "./.github/actions/install-tool"
# with:
# no-fetching: "true"
# fail-on-cache-miss: "false"
# tool: |-
# ${{ matrix.tool }}
# local: "true"
# rust-version: |-
# ${{ needs.configuration.outputs.stable-rust-version }}
# tools-deps-restored: "true"
# linting:
# runs-on: 'ubuntu-latest'
# needs:
# - "configuration"
# - "cache_stable_rust_toolchain"
# - "cache_cargo_and_vendor_deps"
# - "install_crates-io_tooling"
# - "audit_dependencies"
# - "check_formatting"
# - "install_local_tooling"
# strategy:
# fail-fast: true
# ### GitHub Actions escaped string
# matrix: "${{ fromJSON(needs.configuration.outputs.linting-matrix-json) }}"
# name: |-
# Linting [${{ matrix.working-directory }}; ${{ matrix.network }}; ${{ matrix.protocol }}; ${{ matrix.profile }}]
# steps:
# - uses: "actions/checkout@v4"
# - uses: "./.github/actions/linting"
# with:
# rust-version: |-
# ${{ needs.configuration.outputs.stable-rust-version }}
# working-directory: |-
# ${{ matrix.working-directory }}
# network: |-
# ${{ matrix.network }}
# protocol: |-
# ${{ matrix.protocol }}
# profile: |-
# ${{ matrix.profile }}
# unused_deps:
# runs-on: 'ubuntu-latest'
# needs:
# - "configuration"
# - "cache_stable_rust_toolchain"
# - "cache_nightly_rust_toolchain"
# - "cache_cargo_and_vendor_deps"
# - "install_crates-io_tooling"
# - "audit_dependencies"
# - "check_formatting"
# - "install_local_tooling"
# strategy:
# fail-fast: false
# ### GitHub Actions escaped string
# matrix: "${{ fromJSON(needs.configuration.outputs.unused-deps-matrix-json) }}"
# name: |-
# Check for unused dependencies [${{ matrix.working-directory }}; ${{ matrix.network }}; ${{ matrix.protocol }}]
# steps:
# - uses: "actions/checkout@v4"
# - uses: "./.github/actions/unused-deps"
# with:
# stable-rust-version: |-
# ${{ needs.configuration.outputs.stable-rust-version }}
# nightly-rust-version: |-
# ${{ needs.configuration.outputs.nightly-rust-version }}
# working-directory: |-
# ${{ matrix.working-directory }}
# network: |-
# ${{ matrix.network }}
# protocol: |-
# ${{ matrix.protocol }}
# packages_tests:
# runs-on: "ubuntu-latest"
# needs:
# - "configuration"
# - "cache_stable_rust_toolchain"
# - "cache_cargo_and_vendor_deps"
# - "install_crates-io_tooling"
# - "audit_dependencies"
# - "check_formatting"
# - "install_local_tooling"
# strategy:
# fail-fast: false
# ### GitHub Actions escaped string
# matrix: "${{ fromJSON(needs.configuration.outputs.packages-tests-matrix-json) }}"
# name: |-
# Run packages' tests [${{ matrix.working-directory }}; ${{ matrix.network }}; ${{ matrix.protocol }}]
# steps:
# - uses: "actions/checkout@v4"
# - uses: "./.github/actions/run-tests"
# with:
# rust-version: |-
# ${{ needs.configuration.outputs.stable-rust-version }}
# working-directory: |-
# ${{ matrix.working-directory }}
# network: |-
# ${{ matrix.network }}
# protocol: |-
# ${{ matrix.protocol }}
# profile: |-
# ${{ needs.configuration.outputs.dev-profile-with-debug-assertions }}
# build_optimizer_image:
# runs-on: "ubuntu-latest"
# needs:
# - "configuration"
# - "cache_cargo_and_vendor_deps"
# - "check_deps_versions"
# - "audit_dependencies"
# - "check_formatting"
# name: "Build optimizer image"
# outputs:
# container-cache-id: |-
# ${{ steps.container-cache-id.outputs.id }}
# steps:
# - uses: "actions/checkout@v4"
# - id: "container-cache-id"
# env:
# file_hashes: |-
# ${{ hashFiles(
# './Containerfile',
# './scripts/build-and-optimize.sh',
# './tools/cargo-each/**',
# './tools/Cargo.lock'
# ) }}
# stable_rust_version: |-
# ${{ needs.configuration.outputs.stable-rust-version }}
# run: |-
# set -eu
#
# digest="$(
# "sha256sum" \
# --tag \
# <<EOF
# ${file_hashes:?}; ${stable_rust_version:?}; ${UPLOAD_ARTIFACTS:?}
# EOF
# )"
#
# "sed" \
# "s/SHA256 (-) = /id=container-/g" \
# >>"${GITHUB_OUTPUT:?}" \
# <<EOF
# ${digest:?}
# EOF
# - id: "cache-container"
# uses: "actions/cache/restore@v4"
# with:
# key: |-
# ${{ steps.container-cache-id.outputs.id }}
# path: |-
# platform-builder-image.tar
# protocol-builder-image.tar
# lookup-only: "true"
# - if: |-
# steps.cache-container.outputs.cache-hit != 'true'
# env:
# stable_rust_version: |-
# ${{ needs.configuration.outputs.stable-rust-version }}
# run: |-
# set -eu
#
# for stage in \
# "platform-builder" \
# "protocol-builder"
# do
# "docker" \
# "build" \
# --build-arg "check_dependencies_updated=${UPLOAD_ARTIFACTS:?}" \
# --build-arg "rust_ver=latest" \
# --file "./Containerfile" \
# --tag "localhost/nolus-containers/${stage:?}" \
# --target "${stage:?}" \
# "."
#
# "docker" \
# "image" \
# "save" \
# --output "${stage}-image.tar" \
# "localhost/nolus-containers/${stage:?}"
# done
# - if: |-
# steps.cache-container.outputs.cache-hit != 'true'
# uses: "actions/cache/save@v4"
# with:
# key: |-
# ${{ steps.container-cache-id.outputs.id }}
# path: |-
# platform-builder-image.tar
# protocol-builder-image.tar
# build_and_check_optimized_protocol:
# runs-on: "ubuntu-latest"
# needs:
# - "configuration"
# - "cache_cargo_and_vendor_deps"
# - "install_crates-io_tooling"
# - "check_formatting"
# - "build_optimizer_image"
# strategy:
# fail-fast: false
# ### GitHub Actions escaped string
# matrix: "${{ fromJSON(needs.configuration.outputs.build-optimized-matrix-json) }}"
# name: |-
# Building contracts [${{ matrix.working-directory }}; ${{ matrix.network }}; ${{ matrix.protocol }}; ${{ matrix.profile }}]
# steps:
# - uses: "actions/checkout@v4"
# - uses: "./.github/actions/build-and-check-optimized"
# with:
# rust-version: |-
# ${{ needs.configuration.outputs.stable-rust-version }}
# container-cache-id: |-
# ${{ needs.build_optimizer_image.outputs.container-cache-id }}
# generated-release-version: |-
# ${{ needs.generate_release_version.outputs.release-version }}
# working-directory: |-
# ${{ matrix.working-directory }}
# network: |-
# ${{ matrix.network }}
# protocol: |-
# ${{ matrix.protocol }}
# profile: |-
# ${{ matrix.profile }}
# max-wasm-file-size: |-
# ${{ matrix.max-wasm-file-size }}
# available-wasm-capabilities: |-
# ${{ needs.configuration.outputs.available-wasm-capabilities }}
# upload-artifacts: |-
# ${{ env.UPLOAD_ARTIFACTS }}
# draft_release:
# runs-on: ubuntu-latest
# if: |-
# github.ref_type == 'tag'
# needs:
# - "configuration"
# - "check_deps_versions"
# - "audit_dependencies"
# - "check_formatting"
# - "linting"
# - "unused_deps"
# - "packages_tests"
# - "build_and_check_optimized_protocol"
# permissions:
# contents: "write"
# steps:
# - name: "Install git-cliff"
# run: |-
# set -eu
#
# "cargo" \
# "+stable" \
# "install" \
# "git-cliff"
# - uses: "actions/checkout@v4"
# with:
# fetch-depth: 0
# - name: "Download artifacts"
# uses: "actions/download-artifact@v4"
# with:
# path: "./artifacts/"
# - name: "Create ZIP files with binaries"
# env:
# networks_and_protocols_json: |-
# ${{ needs.configuration.outputs.networks-and-protocols-json }}
# run: |-
# set -eu
#
# common_prefix="optimized-binaries"
# readonly platform_dir_prefixed="${common_prefix}-platform"
# readonly protocol_dir_prefixed="${common_prefix}-protocol"
# unset -v "common_prefix"
#
# readonly networks_and_protocols_json="$(
# echo "${networks_and_protocols_json}" \
# | jq -c ".[] | to_entries[]"
# )"
#
# echo "${networks_and_protocols_json}" \
# | while read -r "network_and_protocols"
# do \
# network_and_protocols="$(
# echo "${network_and_protocols}" \
# | jq -c ".key, .value"
# )"; \
# echo "${network_and_protocols}" \
# | while read -r "network"
# do \
# network="$(
# echo "${network}" \
# | sed -e "s/^\"\([^\"]\{1,\}\)\"$/\1/"
# )"; \
# network_prefixed="${protocol_dir_prefixed}-${network}"; \
# mkdir "./${network_prefixed}/"; \
# read -r "protocols"; \
# protocols="$(echo "${protocols}" | jq -c ".[]")"; \
# protocols="$(
# echo "${protocols}" \
# | sed -e "s/^\"\([^\"]\{1,\}\)\"$/\1/"
# )"; \
# echo "${protocols}" \
# | while read -r "protocol"
# do \
# mv "./${network_prefixed}-${protocol}/" \
# "./${network_prefixed}/${protocol}"; \
# done; \
# cd "./${network_prefixed}/"; \
# zip -r "${network_prefixed}.zip" .; \
# mv "./${network_prefixed}.zip" "../"; \
# cd "../"; \
# done; \
# done
#
# platform_dirs="$(find -type d -name "${platform_dir_prefixed}-*")"
# platform_dirs="$(echo "${platform_dirs}" | grep "^\./[^\/]\{1,\}$")"
# readonly platform_dirs="$(echo "${platform_dirs}" | sed -e "s/^\.\/$//")"
#
# echo "${platform_dirs}" \
# | while read -r "platform_profile"
# do \
# cd "./${platform_profile}/"; \
# zip -r "${platform_profile}.zip" .; \
# mv "./${platform_profile}.zip" "../"; \
# cd "../"; \
# done
# working-directory: "./artifacts/"
# - name: "Generate changelog"
# run: |-
# git \
# cliff \
# --current \
# >"./changelog"
# - name: "Create draft release"
# uses: "softprops/action-gh-release@v2"
# with:
# name: |-
# ${{ github.ref_name }}
# draft: true
# body_path: "./changelog"
# generate_release_notes: false
# files: |
# ./artifacts/*.zip