浏览代码

CI: add actions/cache steps

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
Manos Pitsidianakis 7 月之前
父节点
当前提交
2257b91b
共有 3 个文件被更改,包括 96 次插入5 次删除
  1. 35 0
      .gitea/workflows/build.yaml
  2. 40 5
      .gitea/workflows/lints.yaml
  3. 21 0
      .gitea/workflows/manifest_lints.yaml

+ 35 - 0
.gitea/workflows/build.yaml

@@ -47,7 +47,21 @@ jobs:
         run: |
         run: |
           apt-get update
           apt-get update
           apt-get install -y libdbus-1-dev pkg-config mandoc libssl-dev make
           apt-get install -y libdbus-1-dev pkg-config mandoc libssl-dev make
+      - name: Cache rustup
+        id: cache-rustup
+        uses: actions/cache@v4
+        with:
+          path: |
+            ~/.rustup/
+            ~/.cargo/env
+            ~/.cargo/config.toml
+            ~/.cargo/bin/
+            ~/.cargo/registry/index/
+            ~/.cargo/registry/cache/
+            ~/.cargo/git/db/
+          key: build-workflow-${{ matrix.build }}-rustup
       - id: rustup-setup
       - id: rustup-setup
+        if: steps.cache-rustup.outputs.cache-hit != 'true'
         name: Install rustup and toolchains
         name: Install rustup and toolchains
         shell: bash
         shell: bash
         run: |
         run: |
@@ -58,7 +72,14 @@ jobs:
             echo "CARGO_HOME=${CARGO_HOME:-$HOME/.cargo}" >> $GITHUB_ENV
             echo "CARGO_HOME=${CARGO_HOME:-$HOME/.cargo}" >> $GITHUB_ENV
             rustup toolchain install --profile minimal ${{ matrix.rust }} --target ${{ matrix.target }}
             rustup toolchain install --profile minimal ${{ matrix.rust }} --target ${{ matrix.target }}
           fi
           fi
+      - name: Source .cargo/env
+        shell: bash
+        run: |
+          source "${HOME}/.cargo/env"
+          echo "${CARGO_HOME:-$HOME/.cargo}/bin" >> $GITHUB_PATH
+          echo "CARGO_HOME=${CARGO_HOME:-$HOME/.cargo}" >> $GITHUB_ENV
       - name: Setup Rust target
       - name: Setup Rust target
+        if: steps.cache-rustup.outputs.cache-hit != 'true'
         run: |
         run: |
           mkdir -p "${{ env.CARGO_HOME }}"
           mkdir -p "${{ env.CARGO_HOME }}"
           cat << EOF > "${{ env.CARGO_HOME }}"/config.toml
           cat << EOF > "${{ env.CARGO_HOME }}"/config.toml
@@ -66,11 +87,25 @@ jobs:
           target = "${{ matrix.target }}"
           target = "${{ matrix.target }}"
           EOF
           EOF
       - name: Add test dependencies
       - name: Add test dependencies
+        if: steps.cache-rustup.outputs.cache-hit != 'true'
         run: |
         run: |
           cargo install --quiet --version 0.9.54 --target "${{ matrix.target }}" cargo-nextest
           cargo install --quiet --version 0.9.54 --target "${{ matrix.target }}" cargo-nextest
+      - name: Restore build artifacts cache in target dir
+        id: cache-deps
+        uses: actions/cache/restore@v4
+        with:
+          path: target/
+          key: workflow-${{ matrix.build }}-cargo-${{ hashFiles('**/Cargo.lock') }}
       - name: cargo-check
       - name: cargo-check
         run: |
         run: |
           make -f ./.gitea/Makefile.build cargo-check
           make -f ./.gitea/Makefile.build cargo-check
+      - if: steps.cache-deps.outputs.cache-hit != 'true'
+        name: Save build artifacts in target dir
+        id: save-cache-deps
+        uses: actions/cache/save@v4
+        with:
+          path: target/
+          key: workflow-${{ matrix.build }}-cargo-${{ hashFiles('**/Cargo.lock') }}
       - name: cargo-test-compiles
       - name: cargo-test-compiles
         if: success() || failure()
         if: success() || failure()
         run: |
         run: |

+ 40 - 5
.gitea/workflows/lints.yaml

@@ -45,7 +45,21 @@ jobs:
         run: |
         run: |
           echo MELI_MSRV=$(grep -m1 rust-version meli/Cargo.toml | head -n1 | cut -d'"' -f 2 | head -n1) >> $GITHUB_ENV
           echo MELI_MSRV=$(grep -m1 rust-version meli/Cargo.toml | head -n1 | cut -d'"' -f 2 | head -n1) >> $GITHUB_ENV
           printf "Rust MSRV is %s\n" $(grep -m1 rust-version meli/Cargo.toml | head -n1 | cut -d'"' -f 2 | head -n1)
           printf "Rust MSRV is %s\n" $(grep -m1 rust-version meli/Cargo.toml | head -n1 | cut -d'"' -f 2 | head -n1)
+      - name: Cache rustup
+        id: cache-rustup
+        uses: actions/cache@v4
+        with:
+          path: |
+            ~/.rustup/
+            ~/.cargo/env
+            ~/.cargo/config.toml
+            ~/.cargo/bin/
+            ~/.cargo/registry/index/
+            ~/.cargo/registry/cache/
+            ~/.cargo/git/db/
+          key: lints-workflow-${{ matrix.build }}-rustup
       - id: rustup-setup
       - id: rustup-setup
+        if: steps.cache-rustup.outputs.cache-hit != 'true'
         name: Install Rustup and toolchains
         name: Install Rustup and toolchains
         shell: bash
         shell: bash
         run: |
         run: |
@@ -60,7 +74,14 @@ jobs:
             rustup component add rustfmt --toolchain ${{ matrix.rust }}-${{ matrix.target }}
             rustup component add rustfmt --toolchain ${{ matrix.rust }}-${{ matrix.target }}
             rustup default ${{ matrix.rust }}
             rustup default ${{ matrix.rust }}
           fi
           fi
+      - name: Source .cargo/env
+        shell: bash
+        run: |
+          source "${HOME}/.cargo/env"
+          echo "${CARGO_HOME:-$HOME/.cargo}/bin" >> $GITHUB_PATH
+          echo "CARGO_HOME=${CARGO_HOME:-$HOME/.cargo}" >> $GITHUB_ENV
       - name: Setup Rust target
       - name: Setup Rust target
+        if: steps.cache-rustup.outputs.cache-hit != 'true'
         run: |
         run: |
           mkdir -p "${{ env.CARGO_HOME }}"
           mkdir -p "${{ env.CARGO_HOME }}"
           cat << EOF > "${{ env.CARGO_HOME }}"/config.toml
           cat << EOF > "${{ env.CARGO_HOME }}"/config.toml
@@ -68,11 +89,30 @@ jobs:
           target = "${{ matrix.target }}"
           target = "${{ matrix.target }}"
           EOF
           EOF
       - name: Add lint dependencies
       - name: Add lint dependencies
+        if: steps.cache-rustup.outputs.cache-hit != 'true'
         shell: bash
         shell: bash
         run: |
         run: |
           cargo install --version 0.15.1 --target "${{ matrix.target }}" cargo-msrv
           cargo install --version 0.15.1 --target "${{ matrix.target }}" cargo-msrv
           # "This package is currently implemented using rust-analyzer internals, so cannot be published on crates.io."
           # "This package is currently implemented using rust-analyzer internals, so cannot be published on crates.io."
           RUSTFLAGS="" cargo install --locked --target "${{ matrix.target }}" --git https://github.com/dcchut/cargo-derivefmt --rev 95da8eee343de4adb25850893873b979258aed7f --bin cargo-derivefmt
           RUSTFLAGS="" cargo install --locked --target "${{ matrix.target }}" --git https://github.com/dcchut/cargo-derivefmt --rev 95da8eee343de4adb25850893873b979258aed7f --bin cargo-derivefmt
+      - name: Restore build artifacts cache in target dir
+        id: cache-deps
+        uses: actions/cache/restore@v4
+        with:
+          path: target/
+          key: workflow-${{ matrix.build }}-cargo-${{ hashFiles('**/Cargo.lock') }}
+      - name: clippy
+        if: success() || failure()
+        run: |
+          source "${HOME}/.cargo/env"
+          make -f .gitea/Makefile.lint clippy
+      - if: steps.cache-deps.outputs.cache-hit != 'true'
+        name: Save build artifacts in target dir
+        id: save-cache-deps
+        uses: actions/cache/save@v4
+        with:
+          path: target/
+          key: workflow-${{ matrix.build }}-cargo-${{ hashFiles('**/Cargo.lock') }}
       - name: cargo-msrv verify melib MSRV
       - name: cargo-msrv verify melib MSRV
         if: success() || failure()
         if: success() || failure()
         run: |
         run: |
@@ -83,11 +123,6 @@ jobs:
         run: |
         run: |
           source "${HOME}/.cargo/env"
           source "${HOME}/.cargo/env"
           make -f .gitea/Makefile.lint rustfmt
           make -f .gitea/Makefile.lint rustfmt
-      - name: clippy
-        if: success() || failure()
-        run: |
-          source "${HOME}/.cargo/env"
-          make -f .gitea/Makefile.lint clippy
       - name: cargo-derivefmt melib
       - name: cargo-derivefmt melib
         if: success() || failure()
         if: success() || failure()
         run: |
         run: |

+ 21 - 0
.gitea/workflows/manifest_lints.yaml

@@ -42,6 +42,19 @@ jobs:
         run: |
         run: |
           apt-get update
           apt-get update
           apt-get install -y mandoc
           apt-get install -y mandoc
+      - name: Cache rustup
+        id: cache-rustup
+        uses: actions/cache@v4
+        with:
+          path: |
+            ~/.rustup/
+            ~/.cargo/env
+            ~/.cargo/config.toml
+            ~/.cargo/bin/
+            ~/.cargo/registry/index/
+            ~/.cargo/registry/cache/
+            ~/.cargo/git/db/
+          key: manifest_lints-workflow-${{ matrix.build }}-rustup
       - id: rustup-setup
       - id: rustup-setup
         name: Install Rustup and toolchains
         name: Install Rustup and toolchains
         shell: bash
         shell: bash
@@ -55,7 +68,14 @@ jobs:
             rustup component add rustfmt --toolchain ${{ matrix.rust }}-${{ matrix.target }}
             rustup component add rustfmt --toolchain ${{ matrix.rust }}-${{ matrix.target }}
             rustup default ${{ matrix.rust }}
             rustup default ${{ matrix.rust }}
           fi
           fi
+      - name: Source .cargo/env
+        shell: bash
+        run: |
+          source "${HOME}/.cargo/env"
+          echo "${CARGO_HOME:-$HOME/.cargo}/bin" >> $GITHUB_PATH
+          echo "CARGO_HOME=${CARGO_HOME:-$HOME/.cargo}" >> $GITHUB_ENV
       - name: Setup Rust target
       - name: Setup Rust target
+        if: steps.cache-rustup.outputs.cache-hit != 'true'
         run: |
         run: |
           mkdir -p "${{ env.CARGO_HOME }}"
           mkdir -p "${{ env.CARGO_HOME }}"
           cat << EOF > "${{ env.CARGO_HOME }}"/config.toml
           cat << EOF > "${{ env.CARGO_HOME }}"/config.toml
@@ -63,6 +83,7 @@ jobs:
           target = "${{ matrix.target }}"
           target = "${{ matrix.target }}"
           EOF
           EOF
       - name: Add manifest lint dependencies
       - name: Add manifest lint dependencies
+        if: steps.cache-rustup.outputs.cache-hit != 'true'
         run: |
         run: |
           source "${HOME}/.cargo/env"
           source "${HOME}/.cargo/env"
           cargo install --quiet --version 1.0.9 --target "${{ matrix.target }}" cargo-sort
           cargo install --quiet --version 1.0.9 --target "${{ matrix.target }}" cargo-sort