From 46996d4eba7d6bf7bd80ff0b50c3d9a45f5c81af Mon Sep 17 00:00:00 2001 From: Adam Gutglick Date: Wed, 2 Oct 2024 13:13:38 +0100 Subject: [PATCH] Minimal shared rust/python/flatc actions we can reuse in other places (#1) Co-authored-by: Robert Kruszewski --- .github/actions/lint-proto/action.yml | 2 +- .github/actions/setup-flatc/action.yml | 16 +++++++++ .github/actions/setup-python/action.yml | 46 +++++++++++++++++++++++++ .github/actions/setup-rust/action.yml | 40 +++++++++++++++++++++ .gitignore | 3 +- 5 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 .github/actions/setup-flatc/action.yml create mode 100644 .github/actions/setup-python/action.yml create mode 100644 .github/actions/setup-rust/action.yml diff --git a/.github/actions/lint-proto/action.yml b/.github/actions/lint-proto/action.yml index ab644f1..d27c99a 100644 --- a/.github/actions/lint-proto/action.yml +++ b/.github/actions/lint-proto/action.yml @@ -11,4 +11,4 @@ runs: using: "docker" image: "docker://yoheimuta/protolint:0.50.5" args: - - ${{ inputs.working-directory }} \ No newline at end of file + - ${{ inputs.working-directory }} diff --git a/.github/actions/setup-flatc/action.yml b/.github/actions/setup-flatc/action.yml new file mode 100644 index 0000000..a251844 --- /dev/null +++ b/.github/actions/setup-flatc/action.yml @@ -0,0 +1,16 @@ +name: Setup Flatc +description: Install the flatbuffers compiler + +runs: + using: "composite" + steps: + - name: Download flatc + shell: bash + run: | + curl -sL https://github.com/google/flatbuffers/releases/download/v24.3.25/Linux.flatc.binary.clang++-15.zip > ${{ runner.temp }}/flatc.zip + unzip ${{ runner.temp }}/flatc.zip -d ${{ runner.temp }}/flatc + echo "PATH=${{ runner.temp }}/flatc:$PATH" >> $GITHUB_ENV + + - name: Export Path + shell: bash + run: echo "PATH=$PATH" >> $GITHUB_ENV diff --git a/.github/actions/setup-python/action.yml b/.github/actions/setup-python/action.yml new file mode 100644 index 0000000..cc75d64 --- /dev/null +++ b/.github/actions/setup-python/action.yml @@ -0,0 +1,46 @@ +name: "Setup Rust" +description: "Toolchain setup and Initial compilation" +inputs: + rye-version: + description: "Rye version to use" + required: true + default: "0.41.0" + +runs: + using: "composite" + steps: + - name: Rye Cache + id: rye-cache + uses: actions/cache@v4 + with: + path: ~/.rye + key: "rye-${{ runner.os }}-${{ inputs.rye-version }}" + + - name: Rye Install + shell: bash + run: curl -sSf https://rye.astral.sh/get | bash + if: steps.rye-cache.outputs.cache-hit != 'true' + env: + RYE_VERSION: "${{ inputs.rye-version }}" + RYE_INSTALL_OPTION: "--yes" + + - name: Rye Shims + shell: bash + run: echo "~/.rye/shims" >> $GITHUB_PATH + + - name: Venv Cache + id: venv-cache + uses: actions/cache@v4 + with: + path: .venv + key: "venv-${{ runner.os }}-${{ hashFiles('requirements**.lock') }}" + + - name: Rye Sync + shell: bash + # --no-lock prevents resolution of the lock file. The locks are still respected. + # We always run `rye sync` even if the cache fetch was successful since it builds our Rust extensions for us. + run: rye sync --no-lock + + - name: Export Path + shell: bash + run: echo "PATH=$PATH" >> $GITHUB_ENV diff --git a/.github/actions/setup-rust/action.yml b/.github/actions/setup-rust/action.yml new file mode 100644 index 0000000..5b5e072 --- /dev/null +++ b/.github/actions/setup-rust/action.yml @@ -0,0 +1,40 @@ +name: Setup Rust +description: Sets up Rust and relevant toolchain components + +inputs: + components: + description: Comma-separated list of components to be additionally installed for a new toolchain + required: false + default: clippy, rustfmt + +runs: + using: "composite" + steps: + - name: Rust Version + id: rust-version + shell: bash + run: echo "version=$(cat rust-toolchain.toml | grep channel | awk -F'\"' '{print $2}')" >> $GITHUB_OUTPUT + + - name: Rust Toolchain + id: rust-toolchain + uses: dtolnay/rust-toolchain@master + if: steps.rustup-cache.outputs.cache-hit != 'true' + with: + toolchain: "${{ steps.rust-version.outputs.version }}" + components: ${{ inputs.components }} + + - name: Rust Dependency Cache + uses: Swatinem/rust-cache@v2 + with: + save-if: ${{ github.ref_name == 'develop' }} + shared-key: "shared" # To allow reuse across jobs + + - name: Rust Compile Cache + uses: mozilla-actions/sccache-action@v0.0.6 + + - name: Rust Compile Cache Config + shell: bash + run: | + echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV + echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV + echo "CARGO_INCREMENTAL=0" >> $GITHUB_ENV diff --git a/.gitignore b/.gitignore index 723ef36..4045fd6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.idea \ No newline at end of file +.idea +.vscode/