From fcb70d01b3bc12a451793fae90a3ce0982f53edf Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Fri, 15 Apr 2022 18:54:47 -0700 Subject: [PATCH] ci: Rework Cargo and Yarn caching. (#87) * Add caching. * Move around. * Log dir. * Add restore keys. * Fix keys. * More. * More. * Polish. --- .github/workflows/moon.yml | 17 ++++++-- .github/workflows/node.yml | 16 ++++++- .github/workflows/release-npm.yml | 9 +++- .github/workflows/release.yml | 71 ++++++++++++++++++++----------- .github/workflows/rust.yml | 9 ++++ 5 files changed, 91 insertions(+), 31 deletions(-) diff --git a/.github/workflows/moon.yml b/.github/workflows/moon.yml index 0dfeab4b467..8d4754f5d5d 100644 --- a/.github/workflows/moon.yml +++ b/.github/workflows/moon.yml @@ -17,21 +17,30 @@ jobs: with: fetch-depth: 0 - uses: actions/cache@v3 + name: Cache cargo with: path: | + ~/.cargo/bin ~/.cargo/registry ~/.cargo/git key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo- - uses: actions/cache@v3 + name: Cache node modules with: path: | - ~/.yarn/cache - ./.yarn/install-state.gz + ~/.yarn + .yarn/install-state.gz key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }} + restore-keys: ${{ runner.os }}-yarn- - uses: actions/cache@v3 + name: Cache moon toolchain with: path: ~/.moon/tools - key: ${{ runner.os }}-moon + key: + ${{ runner.os }}-moon-node@${{ matrix.node-version }}-${{ + hashFiles('.moon/workspace.yml') }} + restore-keys: ${{ runner.os }}-moon-node@${{ matrix.node-version }}- - uses: actions-rs/toolchain@v1 with: toolchain: 1.60.0 @@ -40,3 +49,5 @@ jobs: with: command: run args: -- --logLevel trace ci + env: + MOON_NODE_VERSION: ${{ matrix.node-version }} diff --git a/.github/workflows/node.yml b/.github/workflows/node.yml index c33a3964252..9c43404906d 100644 --- a/.github/workflows/node.yml +++ b/.github/workflows/node.yml @@ -8,8 +8,14 @@ jobs: steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 + - uses: actions/cache@v3 + name: Cache node modules with: - cache: yarn + path: | + ~/.yarn + .yarn/install-state.gz + key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }} + restore-keys: ${{ runner.os }}-yarn- - run: yarn install --immutable - run: yarn run build version: @@ -20,6 +26,12 @@ jobs: with: fetch-depth: 0 - uses: actions/setup-node@v3 + - uses: actions/cache@v3 + name: Cache node modules with: - cache: yarn + path: | + ~/.yarn + .yarn/install-state.gz + key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }} + restore-keys: ${{ runner.os }}-yarn- - run: yarn version check diff --git a/.github/workflows/release-npm.yml b/.github/workflows/release-npm.yml index 05a92bb5b98..4c4cdb5e1da 100644 --- a/.github/workflows/release-npm.yml +++ b/.github/workflows/release-npm.yml @@ -16,9 +16,16 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: - cache: yarn check-latest: true node-version: 16 + - uses: actions/cache@v3 + name: Cache node modules + with: + path: | + ~/.yarn + .yarn/install-state.gz + key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }} + restore-keys: ${{ runner.os }}-yarn- - name: Install dependencies run: yarn install - name: Build packages diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fe0b7596d3f..592a312c99a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -50,29 +50,27 @@ jobs: - uses: actions/setup-node@v3 with: architecture: ${{ matrix.arch }} - cache: yarn check-latest: true node-version: 16 + - uses: actions/cache@v3 + name: Cache cargo + with: + path: | + ~/.cargo/bin + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo- - uses: actions-rs/toolchain@v1 with: override: true profile: minimal target: ${{ matrix.target }} toolchain: stable - - name: Generate lockfile - uses: actions-rs/cargo@v1 + - uses: actions-rs/cargo@v1 + name: Generate lockfile with: command: generate-lockfile - - name: Cache cargo registry - uses: actions/cache@v3 - with: - path: ~/.cargo/registry - key: ${{ matrix.target }}-node@16-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }} - - name: Cache cargo index - uses: actions/cache@v3 - with: - path: ~/.cargo/git - key: ${{ matrix.target }}-node@16-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }} - name: Setup toolchain if: ${{ matrix.setup }} run: ${{ matrix.setup }} @@ -85,8 +83,8 @@ jobs: BINARY: ${{ matrix.binary }} TARGET: ${{ matrix.target }} RUSTFLAGS: '-C strip=symbols' - - name: Upload artifact - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v2 + name: Upload artifact with: name: binary-${{ matrix.target }} path: ${{ matrix.binary }} @@ -116,18 +114,34 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: - cache: yarn check-latest: true node-version: 16 - - name: Download artifacts - uses: actions/download-artifact@v2 + - uses: actions/cache@v3 + name: Cache cargo + with: + path: | + ~/.cargo/bin + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo- + - uses: actions/cache@v3 + name: Cache node modules + with: + path: | + ~/.yarn + .yarn/install-state.gz + key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }} + restore-keys: ${{ runner.os }}-yarn- + - uses: actions/download-artifact@v2 + name: Download artifacts with: path: artifacts - name: Sync artifact binaries run: node ./scripts/release/syncArtifacts.mjs shell: bash - name: Install dependencies - run: yarn install + run: yarn install --immutable - name: List packages run: ls -R ./packages/core-linux-* ./packages/core-macos-* ./packages/core-windows-* shell: bash @@ -149,13 +163,20 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: - cache: yarn check-latest: true node-version: 16 + - uses: actions/cache@v3 + name: Cache node modules + with: + path: | + ~/.yarn + .yarn/install-state.gz + key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }} + restore-keys: ${{ runner.os }}-yarn- - name: Install dependencies - run: yarn install - - name: Download artifacts - uses: actions/download-artifact@v2 + run: yarn install --immutable + - uses: actions/download-artifact@v2 + name: Download artifacts with: path: artifacts - name: Sync artifact binaries @@ -171,8 +192,8 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} # TODO changelog - - name: Create GitHub release - uses: softprops/action-gh-release@v1 + - uses: softprops/action-gh-release@v1 + name: Create GitHub release with: fail_on_unmatched_files: true files: artifacts/release/* diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 2b592859fa6..c3554b5c6c4 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -11,11 +11,14 @@ jobs: steps: - uses: actions/checkout@v3 - uses: actions/cache@v3 + name: Cache cargo with: path: | + ~/.cargo/bin ~/.cargo/registry ~/.cargo/git key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo- - uses: actions-rs/toolchain@v1 with: toolchain: 1.60.0 @@ -35,11 +38,14 @@ jobs: steps: - uses: actions/checkout@v3 - uses: actions/cache@v3 + name: Cache cargo with: path: | + ~/.cargo/bin ~/.cargo/registry ~/.cargo/git key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo- - uses: actions-rs/toolchain@v1 with: toolchain: 1.60.0 @@ -59,11 +65,14 @@ jobs: steps: - uses: actions/checkout@v3 - uses: actions/cache@v3 + name: Cache cargo with: path: | + ~/.cargo/bin ~/.cargo/registry ~/.cargo/git key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo- - uses: actions-rs/toolchain@v1 with: toolchain: 1.60.0