diff --git a/.github/actions/build-and-check-optimized/action.yaml b/.github/actions/build-and-check-optimized/action.yaml deleted file mode 100644 index 0cc0c5f5e..000000000 --- a/.github/actions/build-and-check-optimized/action.yaml +++ /dev/null @@ -1,176 +0,0 @@ -name: "Build and check optimized binaries" -description: "Action for building optimized WebAssembly binaries and checking - them." -author: "The Dev Nolus Team " - -inputs: - rust-version: - description: "" - required: true - container-cache-id: - description: "" - required: true - generated-release-version: - description: "" - required: true - working-directory: - description: "" - required: true - network: - description: "" - required: true - protocol: - description: "" - required: true - profile: - description: "" - required: true - max-wasm-file-size: - description: "" - required: true - available-wasm-capabilities: - description: "" - required: true - upload-artifacts: - description: "" - required: true - -runs: - using: "composite" - steps: - - uses: "./.github/actions/cache-rust" - with: - cache-cargo: "true" - working-directory: "tests" - cache-rust-stable: "false" - rust-stable: |- - ${{ inputs.rust-version }} - cache-rust-nightly: "false" - no-fetching: "false" - fail-on-cache-miss: "true" - - uses: "actions/cache/restore@v4" - with: - key: |- - ${{ inputs.container-cache-id }} - path: "container.tar" - fail-on-cache-miss: "true" - - shell: "sh" - run: |- - docker image load --input "container.tar" - - uses: "./.github/actions/install-tool" - with: - no-fetching: "false" - fail-on-cache-miss: "true" - tool: "cosmwasm-check" - local: "false" - - name: "Build optimized versions of contracts" - shell: "sh" - env: - generated_release_version: |- - ${{ inputs.generated-release-version }} - working_directory: |- - ${{ inputs.working-directory }} - network: |- - ${{ inputs.network }} - protocol: |- - ${{ inputs.protocol }} - profile: |- - ${{ inputs.profile }} - upload_artifacts: |- - ${{ inputs.upload-artifacts }} - run: |- - mkdir "./artifacts/" - - echo "${generated_release_version}" >> "./artifacts/release_version" - - current_directory="$(pwd)" - - docker run --rm -v "${current_directory}/platform/:/platform/:ro" \ - -v "${current_directory}/protocol/:/protocol/:ro" \ - -v "${current_directory}/${working_directory}/:/code/:rw" \ - -v "${current_directory}/.vendor/:/.vendor/:ro" \ - -v "${current_directory}/artifacts/:/artifacts/:rw" \ - --env "NETWORK=${network}" \ - --env "PROTOCOL=${protocol}" \ - --env "PROFILE=${profile}" \ - --env "RELEASE_VERSION=${generated_release_version}" \ - --env "CHECK_DEPENDENCIES_UPDATED=${upload_artifacts}" \ - --pull "never" "localhost/wasm-optimizer" - - name: "Check for WASM binaries larger than allowed limit" - shell: "sh" - env: - max_wasm_file_size: |- - ${{ inputs.max-wasm-file-size }} - run: |- - large_files="$(find -size "+${max_wasm_file_size}" -printf "%f - %s bytes\n")" - - if [ -n "${large_files}" ] - then - echo "### These files are larger than the allowed limit: - ${large_files}" >> "${GITHUB_STEP_SUMMARY}" - - exit 1 - fi - working-directory: "./artifacts/" - - name: "Checking WASM binaries" - shell: "sh" - env: - available_wasm_capabilities: |- - ${{ inputs.available-wasm-capabilities }} - run: |- - if ! cosmwasm-check --available-capabilities \ - "${available_wasm_capabilities}" *".wasm" 2>&1 1>output - then - printf "### CosmWasm's checks failed:\n" \ - >> "${GITHUB_STEP_SUMMARY}" - - tee -a "${GITHUB_STEP_SUMMARY}" < output - - exit 1 - else - rm "output" - fi - working-directory: "./artifacts/" - - name: "Copy deployment script to artifacts directory" - shell: "sh" - if: |- - inputs.upload-artifacts == 'true' - run: |- - sudo cp -R "./scripts/" "./artifacts/" - - name: "Generate artifacts archive label" - if: |- - inputs.upload-artifacts == 'true' - id: "artifact-label" - shell: "sh" - env: - working_directory: |- - ${{ inputs.working-directory }} - network: |- - ${{ inputs.network }} - protocol: |- - ${{ inputs.protocol }} - profile: |- - ${{ inputs.profile }} - run: |- - label="${working_directory}" - - if [ "${network}" = "@agnostic" -a "${protocol}" = "@agnostic" ] - then - label="${label}-${profile}" - else - label="${label}-${network}-${protocol}" - fi - - echo "artifact-label<> "${GITHUB_OUTPUT}" - - name: "Upload artifacts" - if: |- - inputs.upload-artifacts == 'true' - uses: "actions/upload-artifact@v4" - with: - name: |- - optimized-binaries-${{ - steps.artifact-label.outputs.artifact-label - }} - path: "./artifacts/*" diff --git a/.github/actions/cache-rust/action.yaml b/.github/actions/cache-rust/action.yaml deleted file mode 100644 index fc9ba3e1b..000000000 --- a/.github/actions/cache-rust/action.yaml +++ /dev/null @@ -1,346 +0,0 @@ -name: "Cache Rust toolchains and Cargo indexes & dependencies" -description: "Action for caching Rust specific stable versions & nightly - versions and Cargo indexes & dependencies." -author: "The Dev Nolus Team " - -inputs: - cache-cargo: - description: "Indicates whether to also restore Cargo indexes & downloads - from cache." - required: true - working-directory: - description: "The directory of the workspace root, containing the - workspace \"Cargo.lock\". Required in combination with \"cache-cargo\"." - required: false - cache-rust-stable: - description: "Indicates whether to also restore stable Rust toolchains - from cache." - required: true - rust-stable: - description: "Indicates the specific used stable Rust toolchain. Required - in combination with \"cache-cargo\" and/or \"cache-rust-stable\"." - required: false - cache-rust-nightly: - description: "Indicates whether to also restore nightly Rust toolchains - from cache." - required: true - rust-nightly: - description: "Indicates the specific used nightly Rust toolchain. Required - in combination with \"cache-rust-nightly\"." - required: false - no-fetching: - description: "Indicates whether to restore Rust and Cargo indexes & - downloads from cache or just create such cache if it doesn't already - exist." - required: true - fail-on-cache-miss: - description: "Indicates whether action should fail in case the cache is not - already available." - required: true - -outputs: - cargo-cache-hit: - description: "Indicates whether restoring Cargo indexes & downloads from the - cache was successful." - value: |- - ${{ steps.restore-cargo.outputs.cache-hit }} - stable-cache-hit: - description: 'Indicates whether restoring stable Rust versions from the - cache was successful.' - value: |- - ${{ steps.restore-stable.outputs.cache-hit }} - nightly-cache-hit: - description: 'Indicates whether restoring nightly Rust versions from the - cache was successful.' - value: |- - ${{ steps.restore-nightly.outputs.cache-hit }} - -runs: - using: "composite" - steps: - - name: 'Check inputs' - shell: "sh" - env: - cache_cargo: |- - ${{ inputs.cache-cargo }} - working_directory: |- - ${{ inputs.working-directory }} - cache_rust_stable: |- - ${{ inputs.cache-rust-stable }} - rust_stable: |- - ${{ inputs.rust-stable }} - cache_rust_nightly: |- - ${{ inputs.cache-rust-nightly }} - rust_nightly: |- - ${{ inputs.rust-nightly }} - fail_on_cache_miss: |- - ${{ inputs.fail-on-cache-miss }} - run: |- - error_code="0" - - ensure_value_is_boolean() { - case "${value}" in - ("false"|"true") ;; - (*) - "echo" "Expected boolean value for parameter, but got: \"${value}\"\ - !" - - error_code="1" - ;; - esac - } - - for value in \ - "${cache_cargo}" \ - "${cache_rust_stable}" \ - "${cache_rust_nightly}" \ - "${fail_on_cache_miss}" - do - "ensure_value_is_boolean" "${value}" - done - - if [ "${cache_cargo}" = "true" -a "${cache_rust_stable}" = "false" \ - -a "${fail_on_cache_miss}" = 'false' ] - then - echo "Setting \"cache-rust-stable\" to \"true\" is required when \ - \"cache-cargo\" is set to \"true\" and \"fail-on-cache-miss\" is set \ - to \"false\"!" - - error_code="1" - fi - - if [ "${cache_cargo}" = "true" -a -z "${rust_stable}" ] - then - echo "Setting \"rust-stable\" is required when \"cache-cargo\" is \ - set to \"true\"!" - - error_code="1" - fi - - if [ "${cache_cargo}" = "true" -a -z "${working_directory}" ] - then - echo "Setting \"working-directory\" is required when \"cache-cargo\" \ - is set to \"true\"!" - - error_code="1" - fi - - if [ "${cache_cargo}" = "false" -a -n "${working_directory}" ] - then - echo "\"working-directory\" must not be set when \"cache-cargo\" is \ - set to \"false\"!" - - error_code="1" - fi - - if [ "${cache_rust_stable}" = "true" -a -z "${rust_stable}" ] - then - echo "Setting \"rust-stable\" is required when \"cache-rust-stable\" \ - is set to \"true\"!" - - error_code="1" - fi - - if [ "${cache_cargo}" = "false" -a "${cache_rust_stable}" = "false" \ - -a -n "${rust_stable}" ] - then - echo "\"rust-stable\" must not be set when \"cache-rust-stable\" is \ - set to \"false\"!" - - error_code="1" - fi - - if [ "${cache_rust_nightly}" = "true" -a -z "${rust_nightly}" ] - then - echo "Setting \"rust-nightly\" is required when \ - \"cache-rust-nightly\" is set to \"true\"!" - - error_code="1" - fi - - if [ "${cache_rust_nightly}" = "false" -a -n "${rust_nightly}" ] - then - echo "\"rust-nightly\" must not be set when \"cache-rust-nightly\" \ - is set to \"false\"!" - - error_code="1" - fi - - exit "${error_code}" - ############## START OF CARGO INDEXES & DEPENDENCIES [PT. 1] ############## - - name: "Generate cache Cargo keys & paths" - if: |- - inputs.cache-cargo == 'true' - id: "generate-cargo-keys-paths" - shell: "sh" - env: - key: |- - cargo-${{ inputs.working-directory }}-${{ hashFiles( - format('./.cargo/**', inputs.working-directory), - format('./{0}/Cargo.lock', inputs.working-directory) - ) }} - path: |- - ${{ format('./{0}/.cargo', inputs.working-directory) }} - ./.vendor - ~/.cargo/git - ~/.cargo/registry - run: |- - echo "key<> "${GITHUB_OUTPUT}" - - name: "Restore Cargo indexes & downloads from cache" - if: |- - inputs.cache-cargo == 'true' - id: "restore-cargo" - uses: "actions/cache/restore@v4" - with: - key: |- - ${{ steps.generate-cargo-keys-paths.outputs.key }} - path: |- - ${{ steps.generate-cargo-keys-paths.outputs.path }} - fail-on-cache-miss: |- - ${{ inputs.fail-on-cache-miss }} - lookup-only: |- - ${{ inputs.no-fetching }} - ############### END OF CARGO INDEXES & DEPENDENCIES [PT. 1] ############### - ###################### START OF STABLE RUST TOOLCHAIN ###################### - - name: "Generate cache stable Rust keys & paths" - if: |- - inputs.cache-rust-stable == 'true' - id: "generate-stable-rust-keys-paths" - shell: "sh" - env: - key: |- - rustup-${{ inputs.rust-stable }} - path: |- - ~/.rustup/toolchains/${{ inputs.rust-stable }}-* - ~/.rustup/update-hashes/${{ inputs.rust-stable }}-* - run: |- - echo "key<> "${GITHUB_OUTPUT}" - - name: "Restore stable Rust toolchain from cache" - if: |- - inputs.cache-rust-stable == 'true' - id: "restore-stable" - uses: "actions/cache/restore@v4" - with: - key: |- - ${{ steps.generate-stable-rust-keys-paths.outputs.key }} - path: |- - ${{ steps.generate-stable-rust-keys-paths.outputs.path }} - fail-on-cache-miss: |- - ${{ inputs.fail-on-cache-miss }} - lookup-only: |- - ${{ toJSON( - inputs.no-fetching == 'true' && inputs.cache-cargo != 'true' - ) }} - - name: "Install stable Rust toolchain" - if: |- - inputs.cache-rust-stable == 'true' - && steps.restore-stable.outputs.cache-hit != 'true' - shell: "sh" - env: - stable_rust_version: |- - ${{ inputs.rust-stable }} - run: |- - rustup toolchain install "${stable_rust_version}" --profile minimal \ - --component rustfmt,clippy - - name: "Cache stable Rust toolchain" - if: |- - inputs.cache-rust-stable == 'true' - && steps.restore-stable.outputs.cache-hit != 'true' - uses: "actions/cache/save@v4" - with: - key: |- - ${{ steps.generate-stable-rust-keys-paths.outputs.key }} - path: |- - ${{ steps.generate-stable-rust-keys-paths.outputs.path }} - ####################### END OF STABLE RUST TOOLCHAIN ####################### - ############## START OF CARGO INDEXES & DEPENDENCIES [PT. 2] ############## - - name: "Vendor dependencies" - if: |- - inputs.cache-cargo == 'true' - && steps.restore-cargo.outputs.cache-hit != 'true' - shell: "sh" - env: - stable_rust_version: |- - ${{ inputs.rust-stable }} - run: |- - mkdir --parents "./.cargo/" - - cargo "+${stable_rust_version}" vendor --versioned-dirs "../.vendor/" \ - 1>>"./.cargo/config.toml" - working-directory: |- - ${{ inputs.working-directory }} - - name: "Cache Cargo indexes and dependencies" - if: |- - inputs.cache-cargo == 'true' - && steps.restore-cargo.outputs.cache-hit != 'true' - uses: "actions/cache/save@v4" - with: - key: |- - ${{ steps.generate-cargo-keys-paths.outputs.key }} - path: |- - ${{ steps.generate-cargo-keys-paths.outputs.path }} - ############### END OF CARGO INDEXES & DEPENDENCIES [PT. 2] ############### - ##################### START OF NIGHTLY RUST TOOLCHAIN ##################### - - name: "Generate cache nightly Rust keys & paths" - if: |- - inputs.cache-rust-nightly == 'true' - id: "generate-nightly-rust-keys-paths" - shell: "sh" - env: - key: |- - rustup-${{ inputs.rust-nightly }} - path: |- - ~/.rustup/toolchains/${{ inputs.rust-nightly }}-* - ~/.rustup/update-hashes/${{ inputs.rust-nightly }}-* - run: |- - echo "key<> "${GITHUB_OUTPUT}" - - name: "Restore nightly Rust toolchain from cache" - if: |- - inputs.cache-rust-nightly == 'true' - id: "restore-nightly" - uses: "actions/cache/restore@v4" - with: - key: |- - ${{ steps.generate-nightly-rust-keys-paths.outputs.key }} - path: |- - ${{ steps.generate-nightly-rust-keys-paths.outputs.path }} - fail-on-cache-miss: |- - ${{ inputs.fail-on-cache-miss }} - lookup-only: |- - ${{ inputs.no-fetching }} - - name: "Install nightly Rust toolchain" - if: |- - inputs.cache-rust-nightly == 'true' - && steps.restore-nightly.outputs.cache-hit != 'true' - shell: "sh" - env: - nightly_rust_version: |- - ${{ inputs.rust-nightly }} - run: |- - rustup toolchain install "${nightly_rust_version}" --profile minimal - - name: "Cache nightly Rust toolchain" - if: |- - inputs.cache-rust-nightly == 'true' - && steps.restore-nightly.outputs.cache-hit != 'true' - uses: "actions/cache/save@v4" - with: - key: |- - ${{ steps.generate-nightly-rust-keys-paths.outputs.key }} - path: |- - ${{ steps.generate-nightly-rust-keys-paths.outputs.path }} - ###################### END OF NIGHTLY RUST TOOLCHAIN ###################### diff --git a/.github/actions/configuration/action.yaml b/.github/actions/configuration/action.yaml deleted file mode 100644 index 02e337a5e..000000000 --- a/.github/actions/configuration/action.yaml +++ /dev/null @@ -1,314 +0,0 @@ -name: "Configuration" -description: "Action for exporting configurations which should be used by the - rest of the workflows and actions." -author: "The Dev Nolus Team " - -runs: - using: composite - steps: - - name: "Export configurations" - id: "configuration" - shell: "sh" - env: - ########################## START OF EDIT HERE ########################## - # The format of the build combinations JSON is: - # { - # "platform": [ - # { - # "profile": "", - # "max_wasm_file_size": "" - # }, - # ... - # ], - # "protocol": { - # "": { - # "profile": "", - # "max_wasm_file_size": "", - # "protocols": [ - # "", - # ... - # ] - # }, - # ... - # }, - # "tests": { - # "": [ - # "", - # ... - # ], - # ... - # } - # } - stable_rust_version: '1.78' - nightly_rust_version: 'nightly-2024-05-12' - dev_profile_with_debug_assertions: 'ci_dev' - dev_profile_without_debug_assertions: 'ci_dev_no_debug_assertions' - build_combinations_json: |- - { - "platform": [ - { - "profile": "test_nets_release", - "max_wasm_file_size": "5M" - }, - { - "profile": "production_nets_release", - "max_wasm_file_size": "5M" - } - ], - "protocol": { - "net_dev": { - "profile": "production_nets_release", - "max_wasm_file_size": "5M", - "protocols": [ - "neutron-astroport-usdc_axelar", - "osmosis-osmosis-usdc_axelar", - "osmosis-osmosis-osmo" - ] - }, - "net_test": { - "profile": "production_nets_release", - "max_wasm_file_size": "5M", - "protocols": [ - "neutron-astroport-usdc_axelar", - "osmosis-osmosis-usdc_axelar", - "osmosis-osmosis-osmo" - ] - }, - "net_main": { - "profile": "production_nets_release", - "max_wasm_file_size": "5M", - "protocols": [ - "neutron-astroport-usdc_axelar", - "neutron-astroport-usdc_noble", - "osmosis-osmosis-akt", - "osmosis-osmosis-all_btc", - "osmosis-osmosis-all_sol", - "osmosis-osmosis-statom", - "osmosis-osmosis-usdc_axelar", - "osmosis-osmosis-usdc_noble" - ] - } - }, - "tests": { - "net_main": [ - "neutron-astroport-usdc_axelar", - "neutron-astroport-usdc_noble", - "osmosis-osmosis-all_btc", - "osmosis-osmosis-all_sol", - "osmosis-osmosis-statom", - "osmosis-osmosis-usdc_axelar", - "osmosis-osmosis-usdc_noble" - ] - } - } - available_wasm_capabilities: |- - cosmwasm_1_1,cosmwasm_1_2,iterator,neutron,staking,stargate - ########################### END OF EDIT HERE ########################### - run: |- - test_err() { - if [ "${?}" -ne 0 ] - then - echo "${1}" - - exit 1 - fi - } - - build_combinations_json="$( - jq -c <> "${GITHUB_OUTPUT}" - -outputs: - stable-rust-version: - description: '' - value: |- - ${{ steps.configuration.outputs.stable-rust-version }} - nightly-rust-version: - description: '' - value: |- - ${{ steps.configuration.outputs.nightly-rust-version }} - dev-profile-with-debug-assertions: - description: '' - value: |- - ${{ steps.configuration.outputs.dev-profile-with-debug-assertions }} - dev-profile-without-debug-assertions: - description: '' - value: |- - ${{ steps.configuration.outputs.dev-profile-without-debug-assertions }} - formatting-matrix-json: - description: '' - value: |- - ${{ steps.configuration.outputs.formatting-matrix-json }} - linting-matrix-json: - description: '' - value: |- - ${{ steps.configuration.outputs.linting-matrix-json }} - unused-deps-matrix-json: - description: '' - value: |- - ${{ steps.configuration.outputs.unused-deps-matrix-json }} - packages-tests-matrix-json: - description: '' - value: |- - ${{ steps.configuration.outputs.packages-tests-matrix-json }} - build-optimized-matrix-json: - description: '' - value: |- - ${{ steps.configuration.outputs.build-optimized-matrix-json }} - available-wasm-capabilities: - description: '' - value: |- - ${{ steps.configuration.outputs.available-wasm-capabilities }} - networks-and-protocols-json: - description: '' - value: |- - ${{ steps.configuration.outputs.networks-and-protocols-json }} diff --git a/.github/actions/install-tool/action.yaml b/.github/actions/install-tool/action.yaml index 53c3230f7..e60fba146 100644 --- a/.github/actions/install-tool/action.yaml +++ b/.github/actions/install-tool/action.yaml @@ -4,230 +4,200 @@ description: "Action for installing a tool, or restoring it from cache if such author: "The Dev Nolus Team " inputs: - no-fetching: - description: "Indicates whether to restore tool from cache or just create - such cache if it doesn't already exist." - required: true fail-on-cache-miss: description: "Indicates whether the action should fail in case the cache is not already available." required: true + local: + description: "Indicates whether the package is locally sourced. When set + \"true\", it is required for the used stable Rust toolchain to be + available." + required: true + no-fetching: + description: "Indicates whether to restore tool from cache or just create + such cache if it doesn't already exist." + required: true tool: description: "The name of the package, if the package is not locally sourced, or it's directory, if it's locally sourced. The installed binary is required to have the same name as the package, or directory in the case of locally sourced ones." required: true - local: - description: "Indicates whether the package is locally sourced. When set - \"true\", it is required for the used stable Rust toolchain to be - available." - required: true - rust-version: - description: "Indicates the Rust toolchain to be used when installing the - tool. Required when used in combination with local." - required: false - tools-deps-restored: - description: "Indicates whether the dependencies of the \"tools\" workspace - are already restored from the caches. If set to \"false\", the action will - fail on a cache miss during restoration from the caches." - required: false runs: - using: composite + using: "composite" steps: - name: 'Check inputs' shell: "sh" env: fail_on_cache_miss: |- ${{ inputs.fail-on-cache-miss }} + no_fetching: |- + ${{ inputs.no-fetching }} local: |- ${{ inputs.local }} - rust_version: |- - ${{ inputs.rust-version }} - tools_deps_restored: |- - ${{ inputs.tools-deps-restored }} run: |- - error_code='0' - - if '[' "${local}" = 'false' -a -n "${rust_version}" ] - then - echo "\"rust-version\" must not be set when \"local\" is set to \ - \"false\"!" - - error_code='1' - fi - - if '[' "${local}" = 'false' -a -n "${tools_deps_restored}" ] - then - echo "\"tools-deps-restored\" must not be set when \"local\" is set \ - to \"false\"!" - - error_code='1' - fi - - if '[' "${local}" = 'true' -a -z "${rust_version}" ] - then - echo "Setting \"rust-version\" is required when \"local\" is set to \ - \"true\"!" - - error_code='1' - fi - - if '[' "${fail_on_cache_miss}" = 'false' -a "${local}" = 'true' -a -z \ - "${tools_deps_restored}" ] - then - echo "Setting \"tools-deps-restored\" is required when \"local\" is \ - set to \"true\" and \"fail-on-cache-miss\" is set to \"false\"!" - - error_code='1' - fi - - if '[' "${fail_on_cache_miss}" = 'true' -a "${local}" = 'true' -a -n \ - "${tools_deps_restored}" ] - then - echo "\"tools-deps-restored\" must not be set when \ - \"fail-on-cache-miss\" is set to \"true\" and \"local\" is set to \ - \"true\"!" - - error_code='1' - fi - - exit "${error_code}" - ##################### START OF CRATES.IO TOOL [PT. 1] ##################### - - id: 'crates-io-tool-key' - if: |- - inputs.local != 'true' + set -eu + + check_boolean() { + set -eu + + case "${1:?}" in + ("false"|"true") + shift + ;; + (*) + "echo" "Variable does not contain a boolean value!" + + exit 1 + esac + + case "${#}" in + ("0") ;; + (*) + "echo" "Function expects only one argument!" + + exit 1 + esac + } + + "check_boolean" "${fail_on_cache_miss:?}" + "check_boolean" "${local:?}" + "check_boolean" "${no_fetching:?}" + - id: "cache-key" shell: "sh" env: + local: |- + ${{ inputs.local }} tool: |- ${{ inputs.tool }} - run: | - version="$( - curl --silent "https://crates.io/api/v1/crates/${tool}" \ - | jq .crate.max_stable_version \ - | sed -E 's/^"([[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+)"$/\1/g' - )" - - echo "key=tool-${tool}-${version}" >> "${GITHUB_OUTPUT}" - - id: "crates-io-tool-restore" - if: |- - inputs.local != 'true' + run: |- + case "${local}" in + ("false") + tool_info="$( + "curl" \ + --silent \ + "https://crates.io/api/v1/crates/${tool:?}" + )" + + key="$( + "jq" \ + --exit-status \ + --raw-output \ + ".crate.max_stable_version" \ + <"${files:?}" + + file_digests="$( + "xargs" \ + -0 \ + -E "" \ + "sha256sum" \ + --binary \ + <"${files:?}" + )" + + digest="$( + "sha256sum" \ + <>"${GITHUB_OUTPUT:?}" + - id: "cache-restore" uses: "actions/cache/restore@v4" with: - key: |- - ${{ steps.crates-io-tool-key.outputs.key }} - path: |- - ${{ format('~/.cargo/bin/{0}', inputs.tool) }} fail-on-cache-miss: |- ${{ inputs.fail-on-cache-miss }} + key: |- + ${{ steps.cache-key.outputs.key }} lookup-only: |- ${{ inputs.no-fetching }} - ###################### END OF CRATES.IO TOOL [PT. 1] ###################### - ####################### START OF LOCAL TOOL [PT. 1] ####################### - - id: 'local-tool-key' - if: |- - inputs.local == 'true' - shell: "sh" - env: - tool: |- - ${{ inputs.tool }} - hash: | - ${{ hashFiles( - './.cargo/**', - './tools/Cargo.toml', - './tools/Cargo.lock', - format('./tools/{0}/**', inputs.tool) - ) }} - run: |- - echo "key<> "${GITHUB_OUTPUT}" - - id: 'local-tool-restore' - if: |- - inputs.local == 'true' - uses: 'actions/cache/restore@v4' - with: - key: |- - ${{ steps.local-tool-key.outputs.key }} path: |- ${{ format('~/.cargo/bin/{0}', inputs.tool) }} - fail-on-cache-miss: |- - ${{ inputs.fail-on-cache-miss }} - lookup-only: |- - ${{ inputs.no-fetching }} - ######################## END OF LOCAL TOOL [PT. 1] ######################## - ######################### START OF SET PERMISSIONS ######################### - if: |- inputs.no-fetching != 'true' - && ( - ( - steps.crates-io-tool-restore.conclusion == 'success' - && steps.crates-io-tool-restore.outputs.cache-hit == 'true' - ) - || ( - steps.local-tool-restore.conclusion == 'success' - && steps.local-tool-restore.outputs.cache-hit == 'true' - ) - ) + && steps.cache-restore.conclusion == 'success' + && steps.cache-restore.outputs.cache-hit == 'true' shell: "sh" env: tool: |- ${{ inputs.tool }} run: |- - chmod a+x ~/.cargo/bin/"${tool}" - ########################## END OF SET PERMISSIONS ########################## - ##################### START OF CRATES.IO TOOL [PT. 2] ##################### + set -eu + + "chmod" \ + "0555" \ + "/${HOME:?}/.cargo/bin/${tool:?}" - if: |- - steps.crates-io-tool-restore.conclusion == 'success' - && steps.crates-io-tool-restore.outputs.cache-hit != 'true' + steps.cache-restore.conclusion == 'success' + && steps.cache-restore.outputs.cache-hit != 'true' shell: "sh" env: + local: |- + ${{ inputs.local }} tool: |- ${{ inputs.tool }} run: |- - cargo +stable install --force "${tool}" - - if: |- - steps.crates-io-tool-restore.conclusion == 'success' - && steps.crates-io-tool-restore.outputs.cache-hit != 'true' - uses: "actions/cache/save@v4" - with: - key: |- - ${{ steps.crates-io-tool-key.outputs.key }} - path: |- - ${{ format('~/.cargo/bin/{0}', inputs.tool) }} - ###################### END OF CRATES.IO TOOL [PT. 2] ###################### - ####################### START OF LOCAL TOOL [PT. 2] ####################### - - if: |- - inputs.tools-deps-restored != 'true' - && steps.local-tool-restore.conclusion == 'success' - && steps.local-tool-restore.outputs.cache-hit != 'true' - uses: "./.github/actions/cache-rust" - with: - cache-cargo: "true" - working-directory: "tools" - cache-rust-stable: "false" - cache-rust-nightly: "false" - no-fetching: "false" - fail-on-cache-miss: "true" + set -eu + + case "${local:?}" in + ("false") + "cargo" \ + "install" \ + --force \ + "${tool:?}" + ;; + ("true") + "cargo" \ + "install" \ + --force \ + --path "./tools/${tool:?}/" + ;; + esac - if: |- - steps.local-tool-restore.conclusion == 'success' - && steps.local-tool-restore.outputs.cache-hit != 'true' - shell: "sh" - env: - rust_version: |- - ${{ inputs.rust-version }} - tool: |- - ${{ inputs.tool }} - run: |- - cargo "+${rust_version}" install --force --path "./tools/${tool}" - - if: | - steps.local-tool-restore.conclusion == 'success' - && steps.local-tool-restore.outputs.cache-hit != 'true' + steps.cache-restore.conclusion == 'success' + && steps.cache-restore.outputs.cache-hit != 'true' uses: "actions/cache/save@v4" with: key: |- - ${{ steps.local-tool-key.outputs.key }} + ${{ steps.cache-key.outputs.key }} path: |- ${{ format('~/.cargo/bin/{0}', inputs.tool) }} - ######################## END OF LOCAL TOOL [PT. 2] ######################## diff --git a/.github/actions/linting/action.yaml b/.github/actions/linting/action.yaml deleted file mode 100644 index 00634c0ab..000000000 --- a/.github/actions/linting/action.yaml +++ /dev/null @@ -1,65 +0,0 @@ -name: "Linting" -description: "Action for linting" -author: "The Dev Nolus Team " - -inputs: - rust-version: - description: "" - required: true - working-directory: - description: "" - required: true - network: - description: "" - required: true - protocol: - description: "" - required: true - profile: - description: "" - required: true - -runs: - using: composite - steps: - - name: "Restore Rust toolchain and dependencies" - uses: "./.github/actions/cache-rust" - with: - cache-cargo: "true" - working-directory: |- - ${{ inputs.working-directory }} - cache-rust-stable: "true" - rust-stable: |- - ${{ inputs.rust-version }} - cache-rust-nightly: "false" - no-fetching: "false" - fail-on-cache-miss: "true" - - name: "Restore \"cargo-each\"" - uses: "./.github/actions/install-tool" - with: - no-fetching: "false" - fail-on-cache-miss: "true" - tool: "cargo-each" - local: "true" - rust-version: |- - ${{ inputs.rust-version }} - - name: 'Run linter' - shell: "sh" - env: - rust_version: |- - ${{ inputs.rust-version }} - working_directory: |- - ${{ inputs.working-directory }} - network: |- - ${{ inputs.network }} - protocol: |- - ${{ inputs.protocol }} - profile: |- - ${{ inputs.profile }} - run: | - cargo "+${rust_version}" -- each run --external-command \ - --print-command --github-actions-logging --tag ci --tag "${network}" \ - --tag "${protocol}" -- ../lint.sh --profile "${profile}" \ - --not-as-workspace - working-directory: |- - ${{ inputs.working-directory }} diff --git a/.github/actions/run-code-coverage-tests/action.yaml b/.github/actions/run-code-coverage-tests/action.yaml deleted file mode 100644 index 449d8bc84..000000000 --- a/.github/actions/run-code-coverage-tests/action.yaml +++ /dev/null @@ -1,71 +0,0 @@ -name: "Run code coverage tests" -description: "Action for running code coverage tests" -author: "The Dev Nolus Team " - -inputs: - rust-version: - description: "" - required: true - working-directory: - description: "" - required: true - network: - description: "" - required: true - protocol: - description: "" - required: true - profile: - description: "" - required: true - -runs: - using: composite - steps: - - name: "Restore Rust toolchain and dependencies" - uses: "./.github/actions/cache-rust" - with: - cache-cargo: "true" - working-directory: |- - ${{ inputs.working-directory }} - cache-rust-stable: "true" - rust-stable: |- - ${{ inputs.rust-version }} - cache-rust-nightly: "false" - no-fetching: "false" - fail-on-cache-miss: "true" - - name: "Restore \"cargo-tarpaulin\"" - uses: "./.github/actions/install-tool" - with: - no-fetching: "false" - fail-on-cache-miss: "true" - tool: "cargo-tarpaulin" - local: "false" - - name: "Restore \"cargo-each\"" - uses: "./.github/actions/install-tool" - with: - no-fetching: "false" - fail-on-cache-miss: "true" - tool: "cargo-each" - local: "true" - rust-version: |- - ${{ inputs.rust-version }} - - name: "Run tests" - shell: "sh" - env: - rust_version: |- - ${{ inputs.rust-version }} - working_directory: |- - ${{ inputs.working-directory }} - network: |- - ${{ inputs.network }} - protocol: |- - ${{ inputs.protocol }} - profile: |- - ${{ inputs.profile }} - run: | - cargo "+${rust_version}" -- each run --print-command \ - --github-actions-logging --tag ci --tag "${network}" \ - --tag "${protocol}" -- test --profile "${profile}" --all-targets - working-directory: |- - ${{ inputs.working-directory }} diff --git a/.github/actions/run-tests/action.yaml b/.github/actions/run-tests/action.yaml deleted file mode 100644 index 9399cdc69..000000000 --- a/.github/actions/run-tests/action.yaml +++ /dev/null @@ -1,72 +0,0 @@ -name: "Run tests" -description: "Action for running individual packages' tests" -author: "The Dev Nolus Team " - -inputs: - rust-version: - description: "" - required: true - working-directory: - description: "" - required: true - network: - description: "" - required: true - protocol: - description: "" - required: true - profile: - description: "" - required: true - -runs: - using: composite - steps: - - name: "Restore Rust toolchain and dependencies" - uses: "./.github/actions/cache-rust" - with: - cache-cargo: "true" - working-directory: |- - ${{ inputs.working-directory }} - cache-rust-stable: "true" - rust-stable: |- - ${{ inputs.rust-version }} - cache-rust-nightly: "false" - no-fetching: "false" - fail-on-cache-miss: "true" - - name: "Restore \"cargo-nextest\"" - uses: "./.github/actions/install-tool" - with: - no-fetching: "false" - fail-on-cache-miss: "true" - tool: "cargo-nextest" - local: "false" - - name: "Restore \"cargo-each\"" - uses: "./.github/actions/install-tool" - with: - no-fetching: "false" - fail-on-cache-miss: "true" - tool: "cargo-each" - local: "true" - rust-version: |- - ${{ inputs.rust-version }} - - name: "Run tests" - shell: "sh" - env: - rust_version: |- - ${{ inputs.rust-version }} - working_directory: |- - ${{ inputs.working-directory }} - network: |- - ${{ inputs.network }} - protocol: |- - ${{ inputs.protocol }} - profile: |- - ${{ inputs.profile }} - run: | - cargo "+${rust_version}" -- each run --print-command \ - --github-actions-logging --tag ci --tag "${network}" \ - --tag "${protocol}" -- nextest run --all-targets \ - --cargo-profile "${profile}" - working-directory: |- - ${{ inputs.working-directory }} diff --git a/.github/actions/unused-deps/action.yaml b/.github/actions/unused-deps/action.yaml deleted file mode 100644 index 87e956ec4..000000000 --- a/.github/actions/unused-deps/action.yaml +++ /dev/null @@ -1,69 +0,0 @@ -name: "Unused dependencies" -description: "Action for checking for unused dependencies" -author: "The Dev Nolus Team " - -inputs: - stable-rust-version: - description: "" - required: true - nightly-rust-version: - description: "" - required: true - working-directory: - description: "" - required: true - network: - description: "" - required: true - protocol: - description: "" - required: true - -runs: - using: composite - steps: - - name: "Restore Rust toolchain and dependencies" - uses: "./.github/actions/cache-rust" - with: - cache-cargo: "true" - working-directory: |- - ${{ inputs.working-directory }} - cache-rust-stable: "false" - rust-stable: |- - ${{ inputs.stable-rust-version }} - cache-rust-nightly: "true" - rust-nightly: |- - ${{ inputs.nightly-rust-version }} - no-fetching: "false" - fail-on-cache-miss: "true" - - name: "Restore \"cargo-each\"" - uses: "./.github/actions/install-tool" - with: - no-fetching: "false" - fail-on-cache-miss: "true" - tool: "cargo-each" - local: "true" - rust-version: |- - ${{ inputs.stable-rust-version }} - - name: "Restore \"cargo-udeps\"" - uses: "./.github/actions/install-tool" - with: - no-fetching: "false" - fail-on-cache-miss: "true" - tool: "cargo-udeps" - local: "false" - - name: "Check for unused dependencies" - shell: "sh" - env: - rust_version: |- - ${{ inputs.nightly-rust-version }} - network: |- - ${{ inputs.network }} - protocol: |- - ${{ inputs.protocol }} - run: | - cargo "+${rust_version}" -- each run --print-command \ - --github-actions-logging --tag ci --tag "${network}" \ - --tag "${protocol}" -- udeps --all-targets - working-directory: |- - ${{ inputs.working-directory }} diff --git a/.github/test-data/build-configuration/protocol.json b/.github/test-data/build-configuration/protocol.json new file mode 100644 index 000000000..fa10f069c --- /dev/null +++ b/.github/test-data/build-configuration/protocol.json @@ -0,0 +1,12 @@ +{ + "dex": "osmosis", + "dex_network": "OSMOSIS", + "liquidity_provider_currency_ticker": "USDC_AXELAR", + "stable_currency_ticker": "ATOM", + "lease_currencies_tickers": [ + "ATOM", + "AKT", + "JUNO", + "OSMO" + ] +} diff --git a/.github/test-data/build-configuration/topology.json b/.github/test-data/build-configuration/topology.json new file mode 100644 index 000000000..c60a6bee8 --- /dev/null +++ b/.github/test-data/build-configuration/topology.json @@ -0,0 +1,293 @@ +{ + "host_network": { + "name": "NOLUS", + "currency": { + "id": "NLS", + "native": { + "name": "Nolus", + "symbol": "unls", + "decimal_digits": "6" + } + } + }, + "networks": { + "OSMOSIS": { + "currencies": { + "OSMO": { + "native": { + "name": "Osmosis OSMO", + "symbol": "uosmo", + "decimal_digits": "6" + }, + "icon": "https://nolus.io/currencies/osmosis-osmo.svg" + }, + "USDC_AXELAR": { + "ibc": { + "network": "AXELAR", + "currency": "USDC" + }, + "icon": "https://nolus.io/currencies/osmosis-usdc.svg" + }, + "ATOM": { + "ibc": { + "network": "COSMOS_HUB", + "currency": "ATOM" + }, + "icon": "https://nolus.io/currencies/osmosis-atom.svg" + }, + "NLS": { + "ibc": { + "network": "NOLUS", + "currency": "NLS" + }, + "icon": "https://nolus.io/currencies/osmosis-nls.svg" + }, + "AKT": { + "ibc": { + "network": "AKASH", + "currency": "AKT" + }, + "icon": "https://nolus.io/currencies/osmosis-akt.svg" + }, + "JUNO": { + "ibc": { + "network": "JUNO", + "currency": "JUNO" + }, + "icon": "https://nolus.io/currencies/osmosis-juno.svg" + } + }, + "dexes": { + "osmosis": { + "type": "osmosis", + "swap_pairs": { + "AKT": [ + "OSMO" + ], + "ATOM": [ + "OSMO" + ], + "OSMO": [ + "AKT", + "ATOM" + ], + "NLS": [ + "AKT", + "ATOM" + ], + "USDC_AXELAR": [ + "NLS", + "OSMO" + ] + } + } + } + }, + "AXELAR": { + "currencies": { + "USDC": { + "native": { + "name": "Usdc", + "symbol": "uausdc", + "decimal_digits": "6" + } + } + } + }, + "COSMOS_HUB": { + "currencies": { + "ATOM": { + "native": { + "name": "Cosmos Hub ATOM", + "symbol": "uatom", + "decimal_digits": "6" + } + } + } + }, + "AKASH": { + "currencies": { + "AKT": { + "native": { + "name": "Akash", + "symbol": "uakt", + "decimal_digits": "6" + } + } + } + }, + "JUNO": { + "currencies": { + "JUNO": { + "native": { + "name": "Juno", + "symbol": "ujunox", + "decimal_digits": "6" + } + } + } + }, + "NEUTRON": { + "currencies": { + "NTRN": { + "native": { + "name": "Neutron", + "symbol": "untrn", + "decimal_digits": "6" + }, + "icon": "https://nolus.io/currencies/neutron-ntrn.svg" + }, + "USDC_AXELAR": { + "ibc": { + "network": "AXELAR", + "currency": "USDC" + }, + "icon": "https://nolus.io/currencies/neutron-usdc.svg" + }, + "ATOM": { + "ibc": { + "network": "COSMOS_HUB", + "currency": "ATOM" + }, + "icon": "https://nolus.io/currencies/neutron-atom.svg" + }, + "NLS": { + "ibc": { + "network": "NOLUS", + "currency": "NLS" + }, + "icon": "https://nolus.io/currencies/neutron-nls.svg" + } + }, + "dexes": { + "astroport": { + "type": "astroport_test", + "swap_pairs": { + "NTRN": [ + "NLS" + ], + "NLS": [ + "NTRN" + ], + "USDC_AXELAR": [ + "ATOM", + "NTRN" + ] + } + } + } + } + }, + "channels": [ + { + "a": { + "network": "NOLUS", + "ch": "channel-0" + }, + "b": { + "network": "OSMOSIS", + "ch": "channel-1636" + } + }, + { + "a": { + "network": "OSMOSIS", + "ch": "channel-3" + }, + "b": { + "network": "AXELAR", + "ch": "channel-227" + } + }, + { + "a": { + "network": "OSMOSIS", + "ch": "channel-73" + }, + "b": { + "network": "AKASH", + "ch": "channel-1" + } + }, + { + "a": { + "network": "COSMOS_HUB", + "ch": "channel-2500" + }, + "b": { + "network": "OSMOSIS", + "ch": "channel-12" + } + }, + { + "a": { + "network": "OSMOSIS", + "ch": "channel-1" + }, + "b": { + "network": "JUNO", + "ch": "channel-190" + } + }, + { + "a": { + "network": "NOLUS", + "ch": "channel-116" + }, + "b": { + "network": "NEUTRON", + "ch": "channel-209" + } + }, + { + "a": { + "network": "NEUTRON", + "ch": "channel-8" + }, + "b": { + "network": "AXELAR", + "ch": "channel-237" + } + }, + { + "a": { + "network": "NEUTRON", + "ch": "channel-1" + }, + "b": { + "network": "COSMOS_HUB", + "ch": "channel-16" + } + } + ], + "definitions": [ + "This is the descriptor of the network topology and currencies of interest for the Nolus AMM protocol.", + "", + "The network topology is represented as a collection of networks and the ICS-20 transfer channels that connect them.", + "Some networks may have DEX services available. Each DEX is uniquely named and should have a type supported by Nolus.", + "The supported types are `osmosis`, `astroport_test`, and `astroport_main`.", + "", + "On a given network, each currency is identified by its 'ticker'. A currency with ticker NLS on a network NOLUS is required.", + "The Nolus network description should not contain other currencies. They are defined in the 'protocols' object.", + "", + "A currency is either native or ibc on a network. In the latter case it points to the 'burning' currency residing at a network", + "that is at one hop distance. In the former case it is described with name, symbol and number of decimal digits.", + "", + "The 'name' is a human-readable description of the currency", + "", + "The 'symbol' is the base denomination of the currency at its native chain.", + "", + "The 'decimal_digits' value represents the number of decimal digits this denomination has.", + "For example, '6' for OSMO means 10^6 units of its base denomination uosmo are equal to 1 OSMO", + "", + "The 'icon' is an optional currency attribute that provides a visual representation of the currency at that network and the others", + "where the currency might be sent over ibc. In other workds, if there is no icon attribute of an ibc originating currency then ", + "the icon is derived from the network and currency it points to. This might be applied multiple times traversing the ibc path ", + "toward its native network.", + "", + "The currency symbol at a given network is either equal to the currency 'symbol' if it is a native for that network, or ", + "'ibc/' + sha256('transfer' + '/' + ch[0] + '/' + ... + 'transfer' + '/' + ch[k] + '/' + symbol) if it is a native on ", + "network 'K' reachable through a sequence of channels with names 'ch[0]', 'ch[1]' ... 'ch[k]' at their minting side.", + "More info is available [here](https://github.com/cosmos/ibc-go/blob/c86d27fc280cfb342a9e4689b381e5823441b694/modules/apps/transfer/types/trace.go#L19)." + ] +} \ No newline at end of file diff --git a/.github/workflows/code_coverage.yaml b/.github/workflows/code_coverage.yaml index 7080a4601..f4030bf85 100644 --- a/.github/workflows/code_coverage.yaml +++ b/.github/workflows/code_coverage.yaml @@ -1,8 +1,8 @@ -name: " Code coverage" +name: "Code coverage" run-name: "Running code coverage for smart contracts" -on: - workflow_dispatch: +#on: +# workflow_dispatch: # schedule: # - cron: "0 0 * * *" diff --git a/.github/workflows/smart_contracts.yaml b/.github/workflows/smart_contracts.yaml index 47f05bcd1..4127f30d9 100644 --- a/.github/workflows/smart_contracts.yaml +++ b/.github/workflows/smart_contracts.yaml @@ -38,761 +38,376 @@ env: ${{ toJSON(github.ref_type == 'tag' || (github.event_name == 'workflow_dispatch' && inputs.upload-artifacts)) }} jobs: - configuration: + load-configuration: runs-on: "ubuntu-latest" - name: "Configuration" outputs: - stable-rust-version: |- - ${{ steps.configuration.outputs.stable-rust-version }} - nightly-rust-version: |- - ${{ steps.configuration.outputs.nightly-rust-version }} - dev-profile-with-debug-assertions: |- - ${{ steps.configuration.outputs.dev-profile-with-debug-assertions }} - dev-profile-without-debug-assertions: |- - ${{ steps.configuration.outputs.dev-profile-without-debug-assertions }} - formatting-matrix-json: |- - ${{ steps.configuration.outputs.formatting-matrix-json }} - linting-matrix-json: |- - ${{ steps.configuration.outputs.linting-matrix-json }} - unused-deps-matrix-json: |- - ${{ steps.configuration.outputs.unused-deps-matrix-json }} - packages-tests-matrix-json: |- - ${{ steps.configuration.outputs.packages-tests-matrix-json }} - build-optimized-matrix-json: |- - ${{ steps.configuration.outputs.build-optimized-matrix-json }} - available-wasm-capabilities: |- - ${{ steps.configuration.outputs.available-wasm-capabilities }} - networks-and-protocols-json: |- - ${{ steps.configuration.outputs.networks-and-protocols-json }} + dex-types-json: |- + ${{ steps.configuration.outputs.dex-types-json }} + profiles-json: |- + ${{ steps.configuration.outputs.profiles-json }} + workspaces-json: |- + ${{ steps.configuration.outputs.workspaces-json }} steps: - uses: "actions/checkout@v4" - id: "configuration" - uses: "./.github/actions/configuration" - install_crates-io_tooling: + run: |- + set -eu + + . "./scripts/check/configuration.sh" + + workspaces_quoted="$( + "jq" \ + --raw-input \ + <>"${GITHUB_OUTPUT}" + prepare_tool_caches: 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] + include: + - local: "false" + tool: "cargo-audit" + - local: "false" + tool: "cargo-udeps" + - local: "true" + tool: "cargo-each" 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" + local: "${{ matrix.local }}" no-fetching: "true" - fail-on-cache-miss: "false" - cache_nightly_rust_toolchain: - runs-on: "ubuntu-latest" + tool: "${{ matrix.tool }}" + workspace_check: 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" + - "load-configuration" + - "prepare_tool_caches" 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: + workspace: "${{ fromJSON(needs.load-configuration.outputs.workspaces-json) }}" 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 }}] + env: + workspace: |- + ${{ matrix.workspace }} steps: - - if: |- - env.UPLOAD_ARTIFACTS == 'true' - uses: "actions/checkout@v4" - - uses: "./.github/actions/cache-rust" - if: |- - env.UPLOAD_ARTIFACTS == 'true' + - uses: "actions/checkout@v4" + - uses: "./.github/actions/install-tool" 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: |- - cargo "+${stable_rust_version}" update --locked - working-directory: |- - ${{ matrix.working-directory }} - generate_release_version: - runs-on: "ubuntu-latest" - needs: - - "check_deps_versions" - name: "Generate release version label" - env: - ref_type: |- - ${{ github.ref_type }} - ref_name: |- - ${{ github.ref_name }} - outputs: - release-version: |- - ${{ steps.release-version.outputs.release-version }} - steps: - - id: "release-version" - run: |- - if test "${UPLOAD_ARTIFACTS}" = 'true' - then - release_version="${ref_type}-${ref_name}-$(date -Iminute)" - - echo "Release version: ${release_version}" \ - >> "${GITHUB_STEP_SUMMARY}" - else - release_version="${RELEASE_VERSION}" - fi + local: "false" + no-fetching: "false" + tool: "cargo-audit" + - run: |- + set -eu - echo "release-version=${release_version}" >> "${GITHUB_OUTPUT}" - audit_dependencies: - runs-on: "ubuntu-latest" + "cp" \ + -R \ + "./.cargo" \ + "./${workspace:?}/.cargo" + - run: |- + set -eu + + "sh" \ + -eu \ + "./scripts/check/workspace_checks.sh" \ + "./${workspace:?}" + instance_lint: needs: - - "configuration" - - "cache_stable_rust_toolchain" - - "check_deps_versions" - - "install_crates-io_tooling" + - "load-configuration" + - "prepare_tool_caches" strategy: fail-fast: true matrix: - working-directory: - - "platform" - - "protocol" - - "tests" - - "tools" - name: |- - Audit dependencies [${{ matrix.working-directory }}] + dex-type: "${{ fromJSON(needs.load-configuration.outputs.dex-types-json) }}" + profile: "${{ fromJSON(needs.load-configuration.outputs.profiles-json) }}" + workspace: "${{ fromJSON(needs.load-configuration.outputs.workspaces-json) }}" + runs-on: "ubuntu-latest" 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: | - 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 + local: "true" + no-fetching: "false" + tool: "cargo-each" + - run: |- + "cp" \ + -R \ + "./.github/test-data/build-configuration" \ + "./" - env: - stable_rust_version: |- - ${{ needs.configuration.outputs.stable-rust-version }} + dex_type: |- + ${{ matrix.dex-type }} + profile: |- + ${{ matrix.profile }} + workspace: |- + ${{ matrix.workspace }} run: |- - cargo "+${stable_rust_version}" audit - working-directory: |- - ${{ matrix.working-directory }} - check_formatting: - runs-on: "ubuntu-latest" + set -eu + + "sh" \ + -eu \ + "./scripts/check/instance_lint.sh" \ + "./${workspace:?}" \ + "${dex_type:?}" \ + "${profile:?}" + instance_check_deps: needs: - - "configuration" - - "cache_stable_rust_toolchain" + - "load-configuration" + - "prepare_tool_caches" 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 }}] + matrix: + dex-type: "${{ fromJSON(needs.load-configuration.outputs.dex-types-json) }}" + workspace: "${{ fromJSON(needs.load-configuration.outputs.workspaces-json) }}" + runs-on: "ubuntu-latest" steps: - uses: "actions/checkout@v4" - ### TODO remove [start] - - env: - network: |- - ${{ matrix.network }} - protocol: |- - ${{ matrix.protocol }} - run: |- - set -e - - if [ ! -d "./packages/currencies/src_by_protocol/${protocol}/${network}/" ] - then - exit - fi - - files="$( - ls "./packages/currencies/src_by_protocol/${protocol}/${network}/" - )" - - if [ -z "${files}" ] - then - exit - fi - - cp \ - -R \ - -f \ - "./packages/currencies/src_by_protocol/${protocol}/${network}/"* \ - "./packages/currencies/src/" - working-directory: |- - ${{ matrix.working-directory }} - ### TODO remove [end] - - uses: "./.github/actions/cache-rust" + - uses: "./.github/actions/install-tool" with: - cache-cargo: "false" - cache-rust-stable: "true" - rust-stable: |- - ${{ needs.configuration.outputs.stable-rust-version }} - cache-rust-nightly: "false" + fail-on-cache-miss: "true" + local: "false" no-fetching: "false" + tool: "cargo-udeps" + - uses: "./.github/actions/install-tool" + with: fail-on-cache-miss: "true" + local: "true" + no-fetching: "false" + tool: "cargo-each" + - run: |- + "rustup" \ + "toolchain" \ + "add" \ + "nightly" + - run: |- + "cp" \ + -R \ + "./.github/test-data/build-configuration" \ + "./" - env: - stable_rust_version: |- - ${{ needs.configuration.outputs.stable-rust-version }} - if: |- - matrix.working-directory != 'protocol' || ( - matrix.network != '@agnostic' && matrix.protocol != '@agnostic' - ) + dex_type: |- + ${{ matrix.dex-type }} + workspace: |- + ${{ matrix.workspace }} run: |- - set -e - - if [ -f "../rustfmt.toml" ] - then - cp "../rustfmt.toml" "./" - fi - - cargo "+${stable_rust_version}" fmt --check - working-directory: |- - ${{ matrix.working-directory }} - install_local_tooling: - runs-on: "ubuntu-latest" + set -eu + + "sh" \ + -eu \ + "./scripts/check/protocol_check_deps.sh" \ + "./${workspace:?}" \ + "${dex_type:?}" + instance_tests: needs: - - "configuration" - - "cache_stable_rust_toolchain" - - "cache_cargo_and_vendor_deps" - - "check_deps_versions" - - "check_formatting" + - "load-configuration" + - "prepare_tool_caches" strategy: fail-fast: true matrix: - tool: - # Add necessary tooling - - "cargo-each" - name: |- - Install tool [${{ matrix.tool }}; local] + dex-type: "${{ fromJSON(needs.load-configuration.outputs.dex-types-json) }}" + profile: "${{ fromJSON(needs.load-configuration.outputs.profiles-json) }}" + workspace: "${{ fromJSON(needs.load-configuration.outputs.workspaces-json) }}" + runs-on: "ubuntu-latest" 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 }} + fail-on-cache-miss: "true" 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" - ### TODO remove [start] - - env: - network: |- - ${{ matrix.network }} - protocol: |- - ${{ matrix.protocol }} - run: |- - set -e - - if [ ! -d "./packages/currencies/src_by_protocol/${protocol}/${network}/" ] - then - exit - fi - - files="$( - ls "./packages/currencies/src_by_protocol/${protocol}/${network}/" - )" - - if [ -z "${files}" ] - then - exit - fi - - cp \ + no-fetching: "false" + tool: "cargo-each" + - run: |- + "cp" \ -R \ - -f \ - "./packages/currencies/src_by_protocol/${protocol}/${network}/"* \ - "./packages/currencies/src/" - working-directory: |- - ${{ matrix.working-directory }} - ### TODO remove [end] - - uses: "./.github/actions/linting" - with: - rust-version: |- - ${{ needs.configuration.outputs.stable-rust-version }} - working-directory: |- - ${{ matrix.working-directory }} - network: |- - ${{ matrix.network }} - protocol: |- - ${{ matrix.protocol }} + "./.github/test-data/build-configuration" \ + "./" + - env: + dex_type: |- + ${{ matrix.dex-type }} 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" - ### TODO remove [start] - - env: - network: |- - ${{ matrix.network }} - protocol: |- - ${{ matrix.protocol }} + workspace: |- + ${{ matrix.workspace }} run: |- - set -e - - if [ ! -d "./packages/currencies/src_by_protocol/${protocol}/${network}/" ] - then - exit - fi - - files="$( - ls "./packages/currencies/src_by_protocol/${protocol}/${network}/" - )" - - if [ -z "${files}" ] - then - exit - fi - - cp \ - -R \ - -f \ - "./packages/currencies/src_by_protocol/${protocol}/${network}/"* \ - "./packages/currencies/src/" - working-directory: |- - ${{ matrix.working-directory }} - ### TODO remove [end] - - 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" + set -eu + + "sh" \ + -eu \ + "./scripts/check/instance_tests.sh" \ + "./${workspace:?}" \ + "${dex_type:?}" \ + "${profile:?}" + build: 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" - ### TODO remove [start] - - env: - network: |- - ${{ matrix.network }} - protocol: |- - ${{ matrix.protocol }} - run: |- - set -e - - if [ ! -d "./packages/currencies/src_by_protocol/${protocol}/${network}/" ] - then - exit - fi - - files="$( - ls "./packages/currencies/src_by_protocol/${protocol}/${network}/" - )" - - if [ -z "${files}" ] - then - exit - fi - - cp \ - -R \ - -f \ - "./packages/currencies/src_by_protocol/${protocol}/${network}/"* \ - "./packages/currencies/src/" - working-directory: |- - ${{ matrix.working-directory }} - ### TODO remove [end] - - 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: + - "load-configuration" + - "workspace_check" + - "instance_lint" + - "instance_check_deps" + - "instance_tests" 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: |- - printf "${file_hashes}; ${stable_rust_version}; ${UPLOAD_ARTIFACTS}" \ - | sha256sum --tag \ - | sed 's/SHA256 (-) = /id=container-/' >> "${GITHUB_OUTPUT}" - - id: "cache-container" + with: + fetch-depth: "0" + fetch-tags: "true" + - id: "restore-builder-base-container-cache" uses: "actions/cache/restore@v4" with: - key: |- - ${{ steps.container-cache-id.outputs.id }} - path: "container.tar" - lookup-only: "true" + key: "builder-base-container" + path: |- + builder-base-container.tar - if: |- - steps.cache-container.outputs.cache-hit != 'true' - env: - stable_rust_version: |- - ${{ needs.configuration.outputs.stable-rust-version }} + !steps.restore-builder-base-container-cache.outputs.cache-hit run: |- - docker image build . -f "Containerfile" \ - -t "localhost/wasm-optimizer" \ - --build-arg "rust_ver=${stable_rust_version}" \ - --build-arg "check_container_dependencies_updated=\ - ${UPLOAD_ARTIFACTS}" - - docker image save -o "container.tar" "localhost/wasm-optimizer" + "docker" \ + "buildx" \ + "build" \ + --file "build.Containerfile" \ + --tag "builder-base" \ + --target "builder-base" \ + "." - if: |- - steps.cache-container.outputs.cache-hit != 'true' - uses: "actions/cache/save@v4" - with: - key: |- - ${{ steps.container-cache-id.outputs.id }} - path: "container.tar" - build_and_check_optimized_protocol: - runs-on: "ubuntu-latest" - needs: - - "configuration" - - "cache_cargo_and_vendor_deps" - - "generate_release_version" - - "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" - ### TODO remove [start] - - env: - network: |- - ${{ matrix.network }} - protocol: |- - ${{ matrix.protocol }} + !steps.restore-builder-base-container-cache.outputs.cache-hit run: |- - set -e - - if [ ! -d "./packages/currencies/src_by_protocol/${protocol}/${network}/" ] - then - exit - fi - - files="$( - ls "./packages/currencies/src_by_protocol/${protocol}/${network}/" - )" - - if [ -z "${files}" ] - then - exit - fi - - cp \ - -R \ - -f \ - "./packages/currencies/src_by_protocol/${protocol}/${network}/"* \ - "./packages/currencies/src/" - working-directory: |- - ${{ matrix.working-directory }} - ### TODO remove [end] - - uses: "./.github/actions/build-and-check-optimized" + "docker" \ + "save" \ + --output "builder-base-container.tar" \ + "builder-base" + - if: |- + !steps.restore-builder-base-container-cache.outputs.cache-hit + uses: "actions/cache/save@v4" 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" + key: "builder-base-container" + path: |- + builder-base-container.tar + - if: |- + steps.restore-builder-base-container-cache.outputs.cache-hit run: |- - cargo +stable install git-cliff - - uses: "actions/checkout@v4" + "docker" \ + "load" \ + --input "builder-base-container.tar" + - run: |- + set -eu + + builder_image() { + target="${1:?}" + + "docker" \ + "buildx" \ + "build" \ + --build-arg "check_dependencies_updated=${UPLOAD_ARTIFACTS:?}" \ + --file "build.Containerfile" \ + --tag "${target:?}-builder" \ + --target "${target:?}-builder" \ + "." + } + + for workspace in \ + "platform" \ + "protocol" + do + "builder_image" "${workspace:?}" + done + - run: |- + set -eux + + build_and_pack() { + network="${1:?}" + + "mkdir" "./artifacts-${network:?}/" + + "docker" \ + "run" \ + --volume "./artifacts-${network:?}/:/artifacts/" \ + "platform-builder" \ + "${network:?}" + } + + for network in \ + "test-net" \ + "production-net" + do + "build_and_pack" "${network:?}" + done + - run: |- + "docker" \ + "image" \ + "save" \ + --output "protocol-builder.tar" \ + "protocol-builder" + - uses: "actions/upload-artifact@v4" with: - fetch-depth: 0 - - name: "Download artifacts" - uses: "actions/download-artifact@v4" + if-no-files-found: "error" + name: "platform-test-net" + path: |- + ./artifacts-test-net/* + - uses: "actions/upload-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 -e - - 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" + if-no-files-found: "error" + name: "platform-production-net" + path: |- + ./artifacts-production-net/* + - uses: "actions/upload-artifact@v4" with: - name: |- - ${{ github.ref_name }} - draft: true - body_path: "./changelog" - generate_release_notes: false - files: | - ./artifacts/*.zip + if-no-files-found: "error" + name: "protocol-builder" + path: |- + ./protocol-builder.tar