diff --git a/.github/actions/destroy-feature-environment/action.yml b/.github/actions/delete-feature-environment/action.yml similarity index 87% rename from .github/actions/destroy-feature-environment/action.yml rename to .github/actions/delete-feature-environment/action.yml index 9e744eaaf4..6aa7997d16 100644 --- a/.github/actions/destroy-feature-environment/action.yml +++ b/.github/actions/delete-feature-environment/action.yml @@ -19,13 +19,13 @@ inputs: outputs: deployment-name: description: 'Output with a deployment name for working with deployments' - value: ${{ steps.get_branch.outputs.branch_name }} + value: ${{ steps.get-ref-properties.outputs.branch-name-flattened }} runs: using: "composite" steps: - name: Get branch name and commit SHA - id: get_branch - uses: ./.github/actions/get-branch + id: get-ref-properties + uses: ./.github/actions/get-ref-properties - name: Checkout aleph-apps repo uses: actions/checkout@v3 @@ -47,7 +47,7 @@ runs: - name: Destroy feature branch shell: bash env: - APP_NAME: fe-${{ steps.get_branch.outputs.branch_appname }} + APP_NAME: fe-${{ steps.get-ref-properties.outputs.branch-name-for-argo }} run: | ALEPH_PATH=$(pwd) @@ -57,7 +57,7 @@ runs: - name: Commit deletion of the feature environment. uses: EndBug/add-and-commit@v9.1.1 env: - APP_NAME: fe-${{ steps.get_branch.outputs.branch_appname }} + APP_NAME: fe-${{ steps.get-ref-properties.outputs.branch-name-for-argo }} with: author_name: AlephZero Automation author_email: alephzero@10clouds.com @@ -83,7 +83,7 @@ runs: - name: Clean S3 storage shell: bash env: - BRANCH_NAME: ${{ steps.get_branch.outputs.branch_name }} + BRANCH_NAME: ${{ steps.get-ref-properties.outputs.branch-name-flattened }} run: | aws s3 rm --recursive \ s3://fe-alephzero-devnet-eu-central-1-keys-bucket/fe-${{ env.BRANCH_NAME }} diff --git a/.github/actions/get-ref-properties/action.yml b/.github/actions/get-ref-properties/action.yml index 42c87dca68..043f361849 100644 --- a/.github/actions/get-ref-properties/action.yml +++ b/.github/actions/get-ref-properties/action.yml @@ -12,6 +12,9 @@ outputs: branch-name-flattened: description: Branch name with / (slash) replaced with - (hyphen) value: ${{ steps.branch.outputs.name-flattened }} + branch-name-for-argo: + description: Branch name that matches [a-z0-9-.]+ for ArgoCD app name + value: ${{ steps.branch.outputs.name-for-argo }} tag: description: Tag name value: ${{ steps.tag.outputs.name }} @@ -42,6 +45,8 @@ runs: run: | echo name=$(echo ${HEAD_REF#refs/heads/}) >> $GITHUB_OUTPUT echo name-flattened=$(echo ${HEAD_REF#refs/heads/} | tr / -) >> $GITHUB_OUTPUT + echo name-for-argo=$(echo ${HEAD_REF#refs/heads/} \ + | tr / - | tr '[:upper:]' '[:lower:]' | tr -c '[a-z0-9-.]' '-') >> $GITHUB_OUTPUT - name: Get commit properties id: commit diff --git a/.github/actions/install-rust-toolchain/action.yml b/.github/actions/install-rust-toolchain/action.yml new file mode 100644 index 0000000000..d3f580ebd7 --- /dev/null +++ b/.github/actions/install-rust-toolchain/action.yml @@ -0,0 +1,91 @@ +--- +name: Install rust toolchain +description: | + Parses rust-toolchain.toml file and installs rust toolchain based on its contents: + * channel, e.g nightly-2022-10-30 + * list of targets, e.g. ["wasm32-unknown-unknown"] + * list of components, e.g. ["clippy", "rustfmt"] + Also, this action contains set of inputs that can override any of the above. + Existence of rust-toolchain.toml file is not mandatory, yet channel is then required to be + passed as an input. +inputs: + channel: + description: | + Toolchain channel. It's required only when rust-toolchain.toml file does not specify it. + required: false + targets: + description: Optional. List of targets to install with the given channel. + required: false + components: + description: Optional. List of cargo components to install. + required: false + +runs: + using: composite + steps: + # This step needs to be extracted either to docker image or to setup of self-hosted runner + - name: Install rustup + shell: bash + run: | + if ! command -v rustup &>/dev/null; then + curl --proto '=https' --tlsv1.2 --retry 10 --retry-connrefused -fsSL \ + "https://sh.rustup.rs" | sh -s -- --default-toolchain none -y + echo "${CARGO_HOME:-$HOME/.cargo}/bin" >> $GITHUB_PATH + fi + + - name: Read channel from rust-toolchain.toml + id: toolchain-channel + uses: SebRollen/toml-action@v1.0.2 + with: + file: 'rust-toolchain.toml' + field: 'toolchain.channel' + + - name: Read components from rust-toolchain.toml + id: toolchain-components + uses: SebRollen/toml-action@v1.0.2 + with: + file: 'rust-toolchain.toml' + field: 'toolchain.components' + + - name: Read targets from rust-toolchain.toml + id: toolchain-targets + uses: SebRollen/toml-action@v1.0.2 + with: + file: 'rust-toolchain.toml' + field: 'toolchain.targets' + + - name: Install rust toolchain + id: install-rust-toolchain + shell: bash + env: + CHANNEL: ${{ inputs.channel || steps.toolchain-channel.outputs.value }} + run: | + if [[ -z "${{ steps.toolchain-channel.outputs.value }}" ]]; then + echo "Could not find value for toolchain.channel in rust-toolchain.toml!" + exit 1 + fi + rustup toolchain install ${{ env.CHANNEL }} + echo "channel=${{ env.CHANNEL }}" >> $GITHUB_OUTPUT + + - name: Add components (optional) + if: inputs.components != '' || steps.toolchain-components.outputs.value != '' + shell: bash + env: + COMPONENTS: ${{ inputs.components || steps.toolchain-components.outputs.value }} + run: | + components=$(echo ${{ env.COMPONENTS }} | tr -d '[]' | sed 's/,/ /g') + for component in $components; do + rustup component add $component + done + + - name: Add targets (optional) + if: inputs.targets != '' || steps.toolchain-targets.outputs.value != '' + shell: bash + env: + TARGETS: ${{ inputs.targets || steps.toolchain-targets.outputs.value }} + run: | + targets=$(echo ${{ env.TARGETS }} | tr -d '[]' | sed 's/,/ /g') + for target in $targets; do + rustup target add $target \ + --toolchain ${{ steps.install-rust-toolchain.outputs.channel }} + done diff --git a/.github/workflows/_build-liminal-node.yml b/.github/workflows/_build-liminal-node.yml index 40be13f2c5..1242734695 100644 --- a/.github/workflows/_build-liminal-node.yml +++ b/.github/workflows/_build-liminal-node.yml @@ -17,10 +17,9 @@ jobs: uses: actions/checkout@v3 - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 - - - name: Install WASM target - run: rustup target add wasm32-unknown-unknown + uses: ./.github/actions/install-rust-toolchain + with: + targets: wasm32-unknown-unknown - name: Build test binary and runtime run: | diff --git a/.github/workflows/_build-production-node-and-e2e-client-image.yml b/.github/workflows/_build-production-node-and-e2e-client-image.yml index 95179c949e..c9195e4a84 100644 --- a/.github/workflows/_build-production-node-and-e2e-client-image.yml +++ b/.github/workflows/_build-production-node-and-e2e-client-image.yml @@ -41,8 +41,8 @@ jobs: if-no-files-found: error retention-days: 7 - - name: Install Rust Toolchain - uses: actions-rs/toolchain@v1 + - name: Install Rust toolchain + uses: ./.github/actions/install-rust-toolchain - name: Build binary and docker image run: | diff --git a/.github/workflows/_build-production-node-and-runtime.yml b/.github/workflows/_build-production-node-and-runtime.yml index c72c7e1d0a..3772d3cb0e 100644 --- a/.github/workflows/_build-production-node-and-runtime.yml +++ b/.github/workflows/_build-production-node-and-runtime.yml @@ -25,10 +25,9 @@ jobs: uses: ./.github/actions/get-ref-properties - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 - - - name: Install WASM target - run: rustup target add wasm32-unknown-unknown + uses: ./.github/actions/install-rust-toolchain + with: + targets: wasm32-unknown-unknown - name: Build production binary and runtime run: cargo build --profile production -p aleph-node diff --git a/.github/workflows/_build-test-node-and-e2e-client-image.yml b/.github/workflows/_build-test-node-and-e2e-client-image.yml index 85a9abc143..0bfe1e3bfa 100644 --- a/.github/workflows/_build-test-node-and-e2e-client-image.yml +++ b/.github/workflows/_build-test-node-and-e2e-client-image.yml @@ -42,7 +42,7 @@ jobs: retention-days: 7 - name: Install Rust Toolchain - uses: actions-rs/toolchain@v1 + uses: ./.github/actions/install-rust-toolchain - name: Build binary and docker image run: | diff --git a/.github/workflows/_build-test-node-and-runtime.yml b/.github/workflows/_build-test-node-and-runtime.yml index 91f353a01d..5e1eca1270 100644 --- a/.github/workflows/_build-test-node-and-runtime.yml +++ b/.github/workflows/_build-test-node-and-runtime.yml @@ -25,10 +25,9 @@ jobs: uses: ./.github/actions/get-ref-properties - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 - - - name: Install WASM target - run: rustup target add wasm32-unknown-unknown + uses: ./.github/actions/install-rust-toolchain + with: + targets: wasm32-unknown-unknown - name: Build test binary and runtime run: | diff --git a/.github/workflows/_check-excluded-packages.yml b/.github/workflows/_check-excluded-packages.yml index 30f19dd105..a41ee5469b 100644 --- a/.github/workflows/_check-excluded-packages.yml +++ b/.github/workflows/_check-excluded-packages.yml @@ -16,7 +16,10 @@ jobs: uses: actions/checkout@v3 - name: Install rust toolchain - uses: actions-rs/toolchain@v1 + uses: ./.github/actions/install-rust-toolchain + with: + targets: wasm32-unknown-unknown + components: clippy rustfmt - name: Read excluded packages from Cargo.toml id: read_excluded @@ -39,9 +42,6 @@ jobs: echo "targets=$targets" >> $GITHUB_OUTPUT - name: Check excluded packages - env: - RUSTC_WRAPPER: "" - RUSTC_WORKSPACE_WRAPPER: sccache run: | packages="${{ steps.format_output.outputs.packages }}" packages="${packages//'%0A'/$'\n'}" @@ -54,8 +54,6 @@ jobs: fi echo "Checking package $p..." pushd "$p" - rustup component add clippy rustfmt - rustup target add wasm32-unknown-unknown cargo fmt --all --check cargo clippy -- --no-deps -D warnings popd diff --git a/.github/workflows/_check-runtime-determimism.yml b/.github/workflows/_check-runtime-determimism.yml index 75e95a3857..bda8bb30c1 100644 --- a/.github/workflows/_check-runtime-determimism.yml +++ b/.github/workflows/_check-runtime-determimism.yml @@ -7,7 +7,7 @@ on: jobs: main: - name: Verify runtime build determinism + name: Check runtime build determinism runs-on: self-hosted env: RUST_BACKTRACE: full @@ -17,10 +17,9 @@ jobs: uses: actions/checkout@v3 - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 - - - name: Install WASM target - run: rustup target add wasm32-unknown-unknown + uses: ./.github/actions/install-rust-toolchain + with: + targets: wasm32-unknown-unknown - name: Download production runtime from artifacts uses: actions/download-artifact@v3 diff --git a/.github/workflows/_unit-tests-and-static-checks.yml b/.github/workflows/_unit-tests-and-static-checks.yml index 278d49b9da..f86c89b56f 100644 --- a/.github/workflows/_unit-tests-and-static-checks.yml +++ b/.github/workflows/_unit-tests-and-static-checks.yml @@ -16,13 +16,10 @@ jobs: uses: actions/checkout@v3 - name: Install Rust Toolchain - uses: actions-rs/toolchain@v1 - - - name: Install clippy and fmt - run: rustup component add clippy rustfmt - - - name: Install WASM target - run: rustup target add wasm32-unknown-unknown + uses: ./.github/actions/install-rust-toolchain + with: + targets: wasm32-unknown-unknown + components: clippy rustfmt - name: Run Format Checks uses: actions-rs/cargo@v1 diff --git a/.github/workflows/build-and-push-cliain.yml b/.github/workflows/build-and-push-cliain.yml index 7d2d0c1630..f514593037 100644 --- a/.github/workflows/build-and-push-cliain.yml +++ b/.github/workflows/build-and-push-cliain.yml @@ -22,7 +22,7 @@ jobs: uses: actions/checkout@v3 - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 + uses: ./.github/actions/install-rust-toolchain - name: Cargo | Build release binary run: | diff --git a/.github/workflows/build-docs.yaml b/.github/workflows/build-docs.yaml index b5a56d5783..2a97229aa3 100644 --- a/.github/workflows/build-docs.yaml +++ b/.github/workflows/build-docs.yaml @@ -17,7 +17,7 @@ jobs: uses: actions/checkout@v3 - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 + uses: ./.github/actions/install-rust-toolchain - name: rustdoc | Build aleph-client docs run: | diff --git a/.github/workflows/deploy-feature-envs.yaml b/.github/workflows/deploy-feature-envs.yaml index 1740eb47b5..152c6d1032 100644 --- a/.github/workflows/deploy-feature-envs.yaml +++ b/.github/workflows/deploy-feature-envs.yaml @@ -97,7 +97,7 @@ jobs: - name: Delete old FE when redeploying if: contains( github.event.pull_request.labels.*.name, env.LABEL_DEPLOYED) - uses: ./.github/actions/destroy-feature-environment + uses: ./.github/actions/delete-feature-environment with: gh-ci-token: ${{ secrets.CI_GH_TOKEN }} aws-access-key: ${{ secrets.AWS_DEVNET_ACCESS_KEY_ID }} @@ -497,7 +497,7 @@ jobs: uses: actions/checkout@v3 - name: Delete FE - uses: ./.github/actions/destroy-feature-environment + uses: ./.github/actions/delete-feature-environment id: delete_fe with: gh-ci-token: ${{ secrets.CI_GH_TOKEN }} @@ -558,7 +558,7 @@ jobs: uses: actions/checkout@v3 - name: Delete FE - uses: ./.github/actions/destroy-feature-environment + uses: ./.github/actions/delete-feature-environment id: delete_fe with: gh-ci-token: ${{ secrets.CI_GH_TOKEN }} diff --git a/.github/workflows/on-pull-request-commit.yml b/.github/workflows/on-pull-request-commit.yml index 8678716297..03e1977a2a 100644 --- a/.github/workflows/on-pull-request-commit.yml +++ b/.github/workflows/on-pull-request-commit.yml @@ -401,11 +401,10 @@ jobs: uses: actions/checkout@v3 - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 - - - name: Install rust-src - working-directory: ./contracts - run: rustup component add rust-src + uses: ./.github/actions/install-rust-toolchain + with: + targets: wasm32-unknown-unknown + components: rust-src - name: Run e2e test uses: ./.github/actions/run-e2e-test diff --git a/BUILD.md b/BUILD.md index 8931e98a33..3b423c5bbc 100644 --- a/BUILD.md +++ b/BUILD.md @@ -106,4 +106,4 @@ After a successful build the binary can be found in `target/release/aleph-node`. [nix]: https://nixos.org/download.html [rustup]: https://rustup.rs/ [docker]: https://docs.docker.com/engine/install/ubuntu/ -[rust-toolchain]: ./rust-toolchain +[rust-toolchain]: ./rust-toolchain.toml diff --git a/nix/versions.nix b/nix/versions.nix index ccf2d4fa99..93477c4a6d 100644 --- a/nix/versions.nix +++ b/nix/versions.nix @@ -2,7 +2,7 @@ rec { rustToolchain = let - # use Rust toolchain declared by the rust-toolchain file + # use Rust toolchain declared by the rust-toolchain.toml file rustToolchain = with nixpkgs; overrideRustTarget ( rustChannelOf { date = "2022-10-30"; channel = "nightly"; } ); overrideRustTarget = rustChannel: rustChannel // { @@ -15,7 +15,7 @@ rec { nixpkgs = let - # this overlay allows us to use a version of the rust toolchain specified by the rust-toolchain file + # this overlay allows us to use a version of the rust toolchain specified by the rust-toolchain.toml file rustOverlay = import (builtins.fetchTarball { # link: https://github.com/mozilla/nixpkgs-mozilla/tree/f233fdc4ff6ba2ffeb1e3e3cd6d63bb1297d6996 diff --git a/rust-toolchain b/rust-toolchain deleted file mode 100644 index 06f480baab..0000000000 --- a/rust-toolchain +++ /dev/null @@ -1 +0,0 @@ -nightly-2022-10-30 diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000000..8dc85561f7 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly-2022-10-30"