name: Install Rust

inputs:
  toolchain:
    description: The Rust version to use, default env.RUST_TOOLCHAIN
    required: true

runs:
  using: "composite"
  steps:
    - name: Install Rust Stable
      id: rust_toolchain
      uses: actions-rs/toolchain@v1
      with:
          toolchain: ${{ inputs.toolchain }} 
          override: true
          profile: minimal
          components: rustfmt, clippy

    - name: Add Cargo bin to Path 
      run: |
        echo "$HOME/.cargo/bin" >> $GITHUB_PATH
      shell: bash

    - name: Verify Rust install 
      run: |
        echo "Verifying rust '${{ inputs.toolchain }}' ..."
        rustc --version
        cargo --version
        cargo clippy --version
        rustfmt --version
      shell: bash

    - name: Share rustc hash
      run: |
       echo 'RUSTC_HASH=${{ steps.rust_toolchain.outputs.rustc_hash }}' >> $GITHUB_ENV
      shell: bash
