diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 2305259..87edc39 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -54,6 +54,22 @@ jobs: run: ./check_tags.sh if: env.SHOULD_DEPLOY == 'yes' + - name: Compute cache key + id: yarnCacheKey + run: echo "::set-output name=value::$(node build/azure-pipelines/computeYarnCacheKey.js)" + + - name: Get yarn cache directory path + id: yarnCacheDirPath + run: echo "::set-output name=dir::$(yarn cache dir)" + + - name: Cache yarn directory + uses: actions/cache@v2 + with: + path: ${{ steps.yarnCacheDirPath.outputs.dir }} + key: ${{ runner.os }}-yarnCacheDir-${{ steps.yarnCacheKey.outputs.value }} + restore-keys: ${{ runner.os }}-yarnCacheDir- + if: env.SHOULD_BUILD == 'yes' + - name: Build env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index ae00853..4456ba0 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -35,7 +35,23 @@ jobs: run: | . check_tags.sh if: env.SHOULD_DEPLOY == 'yes' - + + - name: Compute cache key + id: yarnCacheKey + run: echo "::set-output name=value::$(node build/azure-pipelines/computeYarnCacheKey.js)" + + - name: Get yarn cache directory path + id: yarnCacheDirPath + run: echo "::set-output name=dir::$(yarn cache dir)" + + - name: Cache yarn directory + uses: actions/cache@v2 + with: + path: ${{ steps.yarnCacheDirPath.outputs.dir }} + key: ${{ runner.os }}-yarnCacheDir-${{ steps.yarnCacheKey.outputs.value }} + restore-keys: ${{ runner.os }}-yarnCacheDir- + if: env.SHOULD_BUILD == 'yes' + - name: Build env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 2dda0e2..898001f 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -49,6 +49,22 @@ jobs: shell: bash if: env.SHOULD_DEPLOY == 'yes' + - name: Compute cache key + id: yarnCacheKey + run: echo "::set-output name=value::$(node build/azure-pipelines/computeYarnCacheKey.js)" + + - name: Get yarn cache directory path + id: yarnCacheDirPath + run: echo "::set-output name=dir::$(yarn cache dir)" + + - name: Cache yarn directory + uses: actions/cache@v2 + with: + path: ${{ steps.yarnCacheDirPath.outputs.dir }} + key: ${{ runner.os }}-yarnCacheDir-${{ steps.yarnCacheKey.outputs.value }} + restore-keys: ${{ runner.os }}-yarnCacheDir- + if: env.SHOULD_BUILD == 'yes' + - name: Build env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/build/azure-pipelines/computeYarnCacheKey.js b/build/azure-pipelines/computeYarnCacheKey.js new file mode 100644 index 0000000..f275804 --- /dev/null +++ b/build/azure-pipelines/computeYarnCacheKey.js @@ -0,0 +1,24 @@ +const fs = require("fs"); +const crypto = require("crypto"); +const path = require("path"); +const { dirs } = require('../../vscode/build/npm/dirs'); + +const ROOT = path.join(__dirname, '../../vscode'); + +const shasum = crypto.createHash('sha1'); + +shasum.update(fs.readFileSync(path.join(ROOT, '.yarnrc'))); +shasum.update(fs.readFileSync(path.join(ROOT, 'remote/.yarnrc'))); + +// Add `yarn.lock` files +for (let dir of dirs) { + const yarnLockPath = path.join(ROOT, dir, 'yarn.lock'); + shasum.update(fs.readFileSync(yarnLockPath)); +} + +// Add any other command line arguments +for (let i = 2; i < process.argv.length; i++) { + shasum.update(process.argv[i]); +} + +process.stdout.write(shasum.digest('hex')); \ No newline at end of file