From 1729a4d479778e12a6d5a0fb58b85ebfbbd56939 Mon Sep 17 00:00:00 2001 From: BSKY Date: Mon, 23 Mar 2020 23:35:15 +0900 Subject: [PATCH] npm run format --- .github/workflows/workflow.yml | 128 ++++++++++++++++----------------- .vscode/launch.json | 32 ++++----- CODE_OF_CONDUCT.md | 20 +++--- CONTRIBUTING.md | 2 +- README.md | 38 +++++----- __tests__/actionUtils.test.ts | 14 ++-- __tests__/restore.test.ts | 26 +++---- __tests__/save.test.ts | 18 ++--- __tests__/tar.test.ts | 6 +- action.yml | 26 +++---- examples.md | 32 ++++++--- jest.config.js | 28 ++++---- src/cacheHttpClient.ts | 26 +++---- src/constants.ts | 8 +-- src/restore.ts | 2 +- src/save.ts | 2 +- src/tar.ts | 2 +- src/utils/actionUtils.ts | 4 +- tsconfig.json | 14 ++-- 19 files changed, 222 insertions(+), 206 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index c394023..bce1022 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -5,12 +5,12 @@ on: branches: - master paths-ignore: - - '**.md' + - "**.md" push: branches: - master paths-ignore: - - '**.md' + - "**.md" jobs: # Build and unit test @@ -21,30 +21,30 @@ jobs: fail-fast: false runs-on: ${{ matrix.os }} steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Setup Node.js - uses: actions/setup-node@v1 - with: - node-version: '12.x' - - name: Determine npm cache directory - id: npm-cache - run: | - echo "::set-output name=dir::$(npm config get cache)" - - name: Restore npm cache - uses: actions/cache@v1 - with: - path: ${{ steps.npm-cache.outputs.dir }} - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - run: npm ci - - name: Prettier Format Check - run: npm run format-check - - name: ESLint Check - run: npm run lint - - name: Build & Test - run: npm run test + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Node.js + uses: actions/setup-node@v1 + with: + node-version: "12.x" + - name: Determine npm cache directory + id: npm-cache + run: | + echo "::set-output name=dir::$(npm config get cache)" + - name: Restore npm cache + uses: actions/cache@v1 + with: + path: ${{ steps.npm-cache.outputs.dir }} + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + - run: npm ci + - name: Prettier Format Check + run: npm run format-check + - name: ESLint Check + run: npm run lint + - name: Build & Test + run: npm run test # End to end save and restore test-save: @@ -53,16 +53,16 @@ jobs: os: [ubuntu-latest, windows-latest, macOS-latest] runs-on: ${{ matrix.os }} steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Generate files - shell: bash - run: __tests__/create-cache-files.sh ${{ runner.os }} - - name: Save cache - uses: ./ - with: - key: test-${{ runner.os }}-${{ github.run_id }} - path: test-cache + - name: Checkout + uses: actions/checkout@v2 + - name: Generate files + shell: bash + run: __tests__/create-cache-files.sh ${{ runner.os }} + - name: Save cache + uses: ./ + with: + key: test-${{ runner.os }}-${{ github.run_id }} + path: test-cache test-restore: needs: test-save strategy: @@ -70,16 +70,16 @@ jobs: os: [ubuntu-latest, windows-latest, macOS-latest] runs-on: ${{ matrix.os }} steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Restore cache - uses: ./ - with: - key: test-${{ runner.os }}-${{ github.run_id }} - path: test-cache - - name: Verify cache - shell: bash - run: __tests__/verify-cache-files.sh ${{ runner.os }} + - name: Checkout + uses: actions/checkout@v2 + - name: Restore cache + uses: ./ + with: + key: test-${{ runner.os }}-${{ github.run_id }} + path: test-cache + - name: Verify cache + shell: bash + run: __tests__/verify-cache-files.sh ${{ runner.os }} # End to end with proxy test-proxy-save: @@ -95,15 +95,15 @@ jobs: env: https_proxy: http://squid-proxy:3128 steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Generate files - run: __tests__/create-cache-files.sh proxy - - name: Save cache - uses: ./ - with: - key: test-proxy-${{ github.run_id }} - path: test-cache + - name: Checkout + uses: actions/checkout@v2 + - name: Generate files + run: __tests__/create-cache-files.sh proxy + - name: Save cache + uses: ./ + with: + key: test-proxy-${{ github.run_id }} + path: test-cache test-proxy-restore: needs: test-proxy-save runs-on: ubuntu-latest @@ -118,12 +118,12 @@ jobs: env: https_proxy: http://squid-proxy:3128 steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Restore cache - uses: ./ - with: - key: test-proxy-${{ github.run_id }} - path: test-cache - - name: Verify cache - run: __tests__/verify-cache-files.sh proxy + - name: Checkout + uses: actions/checkout@v2 + - name: Restore cache + uses: ./ + with: + key: test-proxy-${{ github.run_id }} + path: test-cache + - name: Verify cache + run: __tests__/verify-cache-files.sh proxy diff --git a/.vscode/launch.json b/.vscode/launch.json index c90eda7..992410a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,17 +1,17 @@ { - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "type": "node", - "request": "launch", - "name": "Jest Test", - "program": "${workspaceFolder}/node_modules/jest/bin/jest", - "args": ["--runInBand", "--config=${workspaceFolder}/jest.config.js"], - "console": "integratedTerminal", - "internalConsoleOptions": "neverOpen" - }, - ] -} \ No newline at end of file + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Jest Test", + "program": "${workspaceFolder}/node_modules/jest/bin/jest", + "args": ["--runInBand", "--config=${workspaceFolder}/jest.config.js"], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen" + } + ] +} diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index a0047d8..964fb4b 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -14,21 +14,21 @@ appearance, race, religion, or sexual identity and orientation. Examples of behavior that contributes to creating a positive environment include: -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members +- Using welcoming and inclusive language +- Being respectful of differing viewpoints and experiences +- Gracefully accepting constructive criticism +- Focusing on what is best for the community +- Showing empathy towards other community members Examples of unacceptable behavior by participants include: -* The use of sexualized language or imagery and unwelcome sexual attention or +- The use of sexualized language or imagery and unwelcome sexual attention or advances -* Trolling, insulting/derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or electronic +- Trolling, insulting/derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information, such as a physical or electronic address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a +- Other conduct which could reasonably be considered inappropriate in a professional setting ## Our Responsibilities diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e11bb5a..687268d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -31,4 +31,4 @@ Here are a few things you can do that will increase the likelihood of your pull - [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/) - [Using Pull Requests](https://help.github.com/articles/about-pull-requests/) -- [GitHub Help](https://help.github.com) \ No newline at end of file +- [GitHub Help](https://help.github.com) diff --git a/README.md b/README.md index 5c86306..7a03131 100644 --- a/README.md +++ b/README.md @@ -11,17 +11,18 @@ See ["Caching dependencies to speed up workflows"](https://help.github.com/githu ## Usage ### Pre-requisites + Create a workflow `.yml` file in your repositories `.github/workflows` directory. An [example workflow](#example-workflow) is available below. For more information, reference the GitHub Help Documentation for [Creating a workflow file](https://help.github.com/en/articles/configuring-a-workflow#creating-a-workflow-file). ### Inputs -* `path` - A directory to store and save the cache -* `key` - An explicit key for restoring and saving the cache -* `restore-keys` - An ordered list of keys to use for restoring the cache if no cache hit occurred for key +- `path` - A directory to store and save the cache +- `key` - An explicit key for restoring and saving the cache +- `restore-keys` - An ordered list of keys to use for restoring the cache if no cache hit occurred for key ### Outputs -* `cache-hit` - A boolean value to indicate an exact match was found for the key +- `cache-hit` - A boolean value to indicate an exact match was found for the key > See [Skipping steps based on cache-hit](#Skipping-steps-based-on-cache-hit) for info on using this output @@ -37,21 +38,21 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v1 - - name: Cache Primes - id: cache-primes - uses: actions/cache@v1 - with: - path: prime-numbers - key: ${{ runner.os }}-primes + - name: Cache Primes + id: cache-primes + uses: actions/cache@v1 + with: + path: prime-numbers + key: ${{ runner.os }}-primes - - name: Generate Prime Numbers - if: steps.cache-primes.outputs.cache-hit != 'true' - run: /generate-primes.sh -d prime-numbers + - name: Generate Prime Numbers + if: steps.cache-primes.outputs.cache-hit != 'true' + run: /generate-primes.sh -d prime-numbers - - name: Use Prime Numbers - run: /primes.sh -d prime-numbers + - name: Use Prime Numbers + run: /primes.sh -d prime-numbers ``` ## Implementation Examples @@ -81,13 +82,14 @@ See [Examples](examples.md) for a list of `actions/cache` implementations for us ## Cache Limits -A repository can have up to 5GB of caches. Once the 5GB limit is reached, older caches will be evicted based on when the cache was last accessed. Caches that are not accessed within the last week will also be evicted. +A repository can have up to 5GB of caches. Once the 5GB limit is reached, older caches will be evicted based on when the cache was last accessed. Caches that are not accessed within the last week will also be evicted. ## Skipping steps based on cache-hit Using the `cache-hit` output, subsequent steps (such as install or build) can be skipped when a cache hit occurs on the key. Example: + ```yaml steps: - uses: actions/checkout@v2 @@ -106,7 +108,9 @@ steps: > Note: The `id` defined in `actions/cache` must match the `id` in the `if` statement (i.e. `steps.[ID].outputs.cache-hit`) ## Contributing + We would love for you to contribute to `@actions/cache`, pull requests are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) for more information. ## License + The scripts and documentation in this project are released under the [MIT License](LICENSE) diff --git a/__tests__/actionUtils.test.ts b/__tests__/actionUtils.test.ts index ea33ef2..dac7388 100644 --- a/__tests__/actionUtils.test.ts +++ b/__tests__/actionUtils.test.ts @@ -51,7 +51,7 @@ test("isExactKeyMatch with empty cache entry returns false", () => { test("isExactKeyMatch with different keys returns false", () => { const key = "linux-rust"; const cacheEntry: ArtifactCacheEntry = { - cacheKey: "linux-" + cacheKey: "linux-", }; expect(actionUtils.isExactKeyMatch(key, cacheEntry)).toBe(false); @@ -60,7 +60,7 @@ test("isExactKeyMatch with different keys returns false", () => { test("isExactKeyMatch with different key accents returns false", () => { const key = "linux-áccent"; const cacheEntry: ArtifactCacheEntry = { - cacheKey: "linux-accent" + cacheKey: "linux-accent", }; expect(actionUtils.isExactKeyMatch(key, cacheEntry)).toBe(false); @@ -69,7 +69,7 @@ test("isExactKeyMatch with different key accents returns false", () => { test("isExactKeyMatch with same key returns true", () => { const key = "linux-rust"; const cacheEntry: ArtifactCacheEntry = { - cacheKey: "linux-rust" + cacheKey: "linux-rust", }; expect(actionUtils.isExactKeyMatch(key, cacheEntry)).toBe(true); @@ -78,7 +78,7 @@ test("isExactKeyMatch with same key returns true", () => { test("isExactKeyMatch with same key and different casing returns true", () => { const key = "linux-rust"; const cacheEntry: ArtifactCacheEntry = { - cacheKey: "LINUX-RUST" + cacheKey: "LINUX-RUST", }; expect(actionUtils.isExactKeyMatch(key, cacheEntry)).toBe(true); @@ -102,7 +102,7 @@ test("setOutputAndState with undefined entry to set cache-hit output", () => { test("setOutputAndState with exact match to set cache-hit output and state", () => { const key = "linux-rust"; const cacheEntry: ArtifactCacheEntry = { - cacheKey: "linux-rust" + cacheKey: "linux-rust", }; const setOutputMock = jest.spyOn(core, "setOutput"); @@ -123,7 +123,7 @@ test("setOutputAndState with exact match to set cache-hit output and state", () test("setOutputAndState with no exact match to set cache-hit output and state", () => { const key = "linux-rust"; const cacheEntry: ArtifactCacheEntry = { - cacheKey: "linux-rust-bb828da54c148048dd17899ba9fda624811cfb43" + cacheKey: "linux-rust-bb828da54c148048dd17899ba9fda624811cfb43", }; const setOutputMock = jest.spyOn(core, "setOutput"); @@ -160,7 +160,7 @@ test("getCacheState with valid state", () => { cacheKey: "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43", scope: "refs/heads/master", creationTime: "2019-11-13T19:18:02+00:00", - archiveLocation: "www.actionscache.test/download" + archiveLocation: "www.actionscache.test/download", }; const getStateMock = jest.spyOn(core, "getState"); getStateMock.mockImplementation(() => { diff --git a/__tests__/restore.test.ts b/__tests__/restore.test.ts index 8ad0cef..fb6fe38 100644 --- a/__tests__/restore.test.ts +++ b/__tests__/restore.test.ts @@ -73,11 +73,11 @@ test("restore with no key", async () => { test("restore with too many keys should fail", async () => { const key = "node-test"; - const restoreKeys = [...Array(20).keys()].map(x => x.toString()); + const restoreKeys = [...Array(20).keys()].map((x) => x.toString()); testUtils.setInputs({ path: "node_modules", key, - restoreKeys + restoreKeys, }); const failedMock = jest.spyOn(core, "setFailed"); await run(); @@ -90,7 +90,7 @@ test("restore with large key should fail", async () => { const key = "foo".repeat(512); // Over the 512 character limit testUtils.setInputs({ path: "node_modules", - key + key, }); const failedMock = jest.spyOn(core, "setFailed"); await run(); @@ -103,7 +103,7 @@ test("restore with invalid key should fail", async () => { const key = "comma,comma"; testUtils.setInputs({ path: "node_modules", - key + key, }); const failedMock = jest.spyOn(core, "setFailed"); await run(); @@ -116,7 +116,7 @@ test("restore with no cache found", async () => { const key = "node-test"; testUtils.setInputs({ path: "node_modules", - key + key, }); const infoMock = jest.spyOn(core, "info"); @@ -142,7 +142,7 @@ test("restore with server error should fail", async () => { const key = "node-test"; testUtils.setInputs({ path: "node_modules", - key + key, }); const logWarningMock = jest.spyOn(actionUtils, "logWarning"); @@ -175,7 +175,7 @@ test("restore with restore keys and no cache found", async () => { testUtils.setInputs({ path: "node_modules", key, - restoreKeys: [restoreKey] + restoreKeys: [restoreKey], }); const infoMock = jest.spyOn(core, "info"); @@ -201,7 +201,7 @@ test("restore with cache found", async () => { const key = "node-test"; testUtils.setInputs({ path: "node_modules", - key + key, }); const infoMock = jest.spyOn(core, "info"); @@ -211,7 +211,7 @@ test("restore with cache found", async () => { const cacheEntry: ArtifactCacheEntry = { cacheKey: key, scope: "refs/heads/master", - archiveLocation: "www.actionscache.test/download" + archiveLocation: "www.actionscache.test/download", }; const getCacheMock = jest.spyOn(cacheHttpClient, "getCacheEntry"); getCacheMock.mockImplementation(() => { @@ -269,7 +269,7 @@ test("restore with a pull request event and cache found", async () => { const key = "node-test"; testUtils.setInputs({ path: "node_modules", - key + key, }); process.env[Events.Key] = Events.PullRequest; @@ -281,7 +281,7 @@ test("restore with a pull request event and cache found", async () => { const cacheEntry: ArtifactCacheEntry = { cacheKey: key, scope: "refs/heads/master", - archiveLocation: "www.actionscache.test/download" + archiveLocation: "www.actionscache.test/download", }; const getCacheMock = jest.spyOn(cacheHttpClient, "getCacheEntry"); getCacheMock.mockImplementation(() => { @@ -338,7 +338,7 @@ test("restore with cache found for restore key", async () => { testUtils.setInputs({ path: "node_modules", key, - restoreKeys: [restoreKey] + restoreKeys: [restoreKey], }); const infoMock = jest.spyOn(core, "info"); @@ -348,7 +348,7 @@ test("restore with cache found for restore key", async () => { const cacheEntry: ArtifactCacheEntry = { cacheKey: restoreKey, scope: "refs/heads/master", - archiveLocation: "www.actionscache.test/download" + archiveLocation: "www.actionscache.test/download", }; const getCacheMock = jest.spyOn(cacheHttpClient, "getCacheEntry"); getCacheMock.mockImplementation(() => { diff --git a/__tests__/save.test.ts b/__tests__/save.test.ts index 2765367..224ea24 100644 --- a/__tests__/save.test.ts +++ b/__tests__/save.test.ts @@ -42,8 +42,8 @@ beforeAll(() => { }); jest.spyOn(actionUtils, "resolvePaths").mockImplementation( - async filePaths => { - return filePaths.map(x => path.resolve(x)); + async (filePaths) => { + return filePaths.map((x) => path.resolve(x)); } ); @@ -81,7 +81,7 @@ test("save with no primary key in state outputs warning", async () => { cacheKey: "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43", scope: "refs/heads/master", creationTime: "2019-11-13T19:18:02+00:00", - archiveLocation: "www.actionscache.test/download" + archiveLocation: "www.actionscache.test/download", }; jest.spyOn(core, "getState") @@ -112,7 +112,7 @@ test("save with exact match returns early", async () => { cacheKey: primaryKey, scope: "refs/heads/master", creationTime: "2019-11-13T19:18:02+00:00", - archiveLocation: "www.actionscache.test/download" + archiveLocation: "www.actionscache.test/download", }; jest.spyOn(core, "getState") @@ -147,7 +147,7 @@ test("save with missing input outputs warning", async () => { cacheKey: "Linux-node-", scope: "refs/heads/master", creationTime: "2019-11-13T19:18:02+00:00", - archiveLocation: "www.actionscache.test/download" + archiveLocation: "www.actionscache.test/download", }; jest.spyOn(core, "getState") @@ -178,7 +178,7 @@ test("save with large cache outputs warning", async () => { cacheKey: "Linux-node-", scope: "refs/heads/master", creationTime: "2019-11-13T19:18:02+00:00", - archiveLocation: "www.actionscache.test/download" + archiveLocation: "www.actionscache.test/download", }; jest.spyOn(core, "getState") @@ -227,7 +227,7 @@ test("save with reserve cache failure outputs warning", async () => { cacheKey: "Linux-node-", scope: "refs/heads/master", creationTime: "2019-11-13T19:18:02+00:00", - archiveLocation: "www.actionscache.test/download" + archiveLocation: "www.actionscache.test/download", }; jest.spyOn(core, "getState") @@ -277,7 +277,7 @@ test("save with server error outputs warning", async () => { cacheKey: "Linux-node-", scope: "refs/heads/master", creationTime: "2019-11-13T19:18:02+00:00", - archiveLocation: "www.actionscache.test/download" + archiveLocation: "www.actionscache.test/download", }; jest.spyOn(core, "getState") @@ -337,7 +337,7 @@ test("save with valid inputs uploads a cache", async () => { cacheKey: "Linux-node-", scope: "refs/heads/master", creationTime: "2019-11-13T19:18:02+00:00", - archiveLocation: "www.actionscache.test/download" + archiveLocation: "www.actionscache.test/download", }; jest.spyOn(core, "getState") diff --git a/__tests__/tar.test.ts b/__tests__/tar.test.ts index fdf637a..684b0c6 100644 --- a/__tests__/tar.test.ts +++ b/__tests__/tar.test.ts @@ -14,7 +14,7 @@ function getTempDir(): string { } beforeAll(async () => { - jest.spyOn(io, "which").mockImplementation(tool => { + jest.spyOn(io, "which").mockImplementation((tool) => { return Promise.resolve(tool); }); @@ -76,10 +76,10 @@ test("create tar", async () => { "-C", workspace, "--files-from", - "manifest.txt" + "manifest.txt", ], { - cwd: archiveFolder + cwd: archiveFolder, } ); }); diff --git a/action.yml b/action.yml index 1a320f9..0408fe7 100644 --- a/action.yml +++ b/action.yml @@ -1,24 +1,24 @@ -name: 'Cache' -description: 'Cache artifacts like dependencies and build outputs to improve workflow execution time' -author: 'GitHub' +name: "Cache" +description: "Cache artifacts like dependencies and build outputs to improve workflow execution time" +author: "GitHub" inputs: path: - description: 'A directory to store and save the cache' + description: "A directory to store and save the cache" required: true key: - description: 'An explicit key for restoring and saving the cache' + description: "An explicit key for restoring and saving the cache" required: true restore-keys: - description: 'An ordered list of keys to use for restoring the cache if no cache hit occurred for key' + description: "An ordered list of keys to use for restoring the cache if no cache hit occurred for key" required: false outputs: cache-hit: - description: 'A boolean value to indicate an exact match was found for the primary key' + description: "A boolean value to indicate an exact match was found for the primary key" runs: - using: 'node12' - main: 'dist/restore/index.js' - post: 'dist/save/index.js' - post-if: 'success()' + using: "node12" + main: "dist/restore/index.js" + post: "dist/save/index.js" + post-if: "success()" branding: - icon: 'archive' - color: 'gray-dark' + icon: "archive" + color: "gray-dark" diff --git a/examples.md b/examples.md index e3a1a06..47b7fef 100644 --- a/examples.md +++ b/examples.md @@ -30,6 +30,7 @@ - [Swift - Swift Package Manager](#swift---swift-package-manager) ## C# - NuGet + Using [NuGet lock files](https://docs.microsoft.com/nuget/consume-packages/package-references-in-project-files#locking-dependencies): ```yaml @@ -43,7 +44,9 @@ Using [NuGet lock files](https://docs.microsoft.com/nuget/consume-packages/packa Depending on the environment, huge packages might be pre-installed in the global cache folder. If you do not want to include them, consider to move the cache folder like below. ->Note: This workflow does not work for projects that require files to be placed in user profile package folder + +> Note: This workflow does not work for projects that require files to be placed in user profile package folder + ```yaml env: NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages @@ -57,6 +60,7 @@ steps: ``` ## Elixir - Mix + ```yaml - uses: actions/cache@v1 with: @@ -125,7 +129,7 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba For npm, cache files are stored in `~/.npm` on Posix, or `%AppData%/npm-cache` on Windows. See https://docs.npmjs.com/cli/cache#cache ->Note: It is not recommended to cache `node_modules`, as it can break across Node versions and won't work with `npm ci` +> Note: It is not recommended to cache `node_modules`, as it can break across Node versions and won't work with `npm ci` ### macOS and Ubuntu @@ -169,6 +173,7 @@ For npm, cache files are stored in `~/.npm` on Posix, or `%AppData%/npm-cache` o ``` ## Node - Yarn + The yarn cache directory will depend on your operating system and version of `yarn`. See https://yarnpkg.com/lang/en/docs/cli/cache/ for more info. ```yaml @@ -198,7 +203,9 @@ The yarn cache directory will depend on your operating system and version of `ya ``` ## OCaml/Reason - esy + Esy allows you to export built dependencies and import pre-built dependencies. + ```yaml - name: Restore Cache id: restore-cache @@ -218,13 +225,12 @@ Esy allows you to export built dependencies and import pre-built dependencies. ...(Build job)... # Re-export dependencies if anything has changed or if it is the first time - - name: Setting dependency cache + - name: Setting dependency cache run: | esy export-dependencies if: steps.restore-cache.outputs.cache-hit != 'true' ``` - ## PHP - Composer ```yaml @@ -245,11 +251,13 @@ Esy allows you to export built dependencies and import pre-built dependencies. For pip, the cache directory will vary by OS. See https://pip.pypa.io/en/stable/reference/pip_install/#caching Locations: - - Ubuntu: `~/.cache/pip` - - Windows: `~\AppData\Local\pip\Cache` - - macOS: `~/Library/Caches/pip` + +- Ubuntu: `~/.cache/pip` +- Windows: `~\AppData\Local\pip\Cache` +- macOS: `~/Library/Caches/pip` ### Simple example + ```yaml - uses: actions/cache@v1 with: @@ -292,6 +300,7 @@ Replace `~/.cache/pip` with the correct `path` if not using Ubuntu. ### Using a script to get cache location > Note: This uses an internal pip API and may not always work + ```yaml - name: Get pip cache id: pip-cache @@ -311,11 +320,13 @@ Replace `~/.cache/pip` with the correct `path` if not using Ubuntu. For renv, the cache directory will vary by OS. Look at https://rstudio.github.io/renv/articles/renv.html#cache Locations: - - Ubuntu: `~/.local/share/renv` - - macOS: `~/Library/Application Support/renv` - - Windows: `%LOCALAPPDATA%/renv` + +- Ubuntu: `~/.local/share/renv` +- macOS: `~/Library/Application Support/renv` +- Windows: `%LOCALAPPDATA%/renv` ### Simple example + ```yaml - uses: actions/cache@v1 with: @@ -365,6 +376,7 @@ Replace `~/.local/share/renv` with the correct `path` if not using Ubuntu. restore-keys: | ${{ runner.os }}-gems- ``` + When dependencies are installed later in the workflow, we must specify the same path for the bundler. ```yaml diff --git a/jest.config.js b/jest.config.js index 59548f6..b147093 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,23 +1,23 @@ require("nock").disableNetConnect(); module.exports = { - clearMocks: true, - moduleFileExtensions: ["js", "ts"], - testEnvironment: "node", - testMatch: ["**/*.test.ts"], - testRunner: "jest-circus/runner", - transform: { - "^.+\\.ts$": "ts-jest" - }, - verbose: true + clearMocks: true, + moduleFileExtensions: ["js", "ts"], + testEnvironment: "node", + testMatch: ["**/*.test.ts"], + testRunner: "jest-circus/runner", + transform: { + "^.+\\.ts$": "ts-jest", + }, + verbose: true, }; const processStdoutWrite = process.stdout.write.bind(process.stdout); // eslint-disable-next-line @typescript-eslint/explicit-function-return-type process.stdout.write = (str, encoding, cb) => { - // Core library will directly call process.stdout.write for commands - // We don't want :: commands to be executed by the runner during tests - if (!str.match(/^::/)) { - return processStdoutWrite(str, encoding, cb); - } + // Core library will directly call process.stdout.write for commands + // We don't want :: commands to be executed by the runner during tests + if (!str.match(/^::/)) { + return processStdoutWrite(str, encoding, cb); + } }; diff --git a/src/cacheHttpClient.ts b/src/cacheHttpClient.ts index c83e307..64117bb 100644 --- a/src/cacheHttpClient.ts +++ b/src/cacheHttpClient.ts @@ -4,7 +4,7 @@ import { BearerCredentialHandler } from "@actions/http-client/auth"; import { IHttpClientResponse, IRequestOptions, - ITypedResponse + ITypedResponse, } from "@actions/http-client/interfaces"; import * as crypto from "crypto"; import * as fs from "fs"; @@ -14,7 +14,7 @@ import { ArtifactCacheEntry, CommitCacheRequest, ReserveCacheRequest, - ReserveCacheResponse + ReserveCacheResponse, } from "./contracts"; import * as utils from "./utils/actionUtils"; @@ -34,7 +34,7 @@ function isRetryableStatusCode(statusCode?: number): boolean { const retryableStatusCodes = [ HttpCodes.BadGateway, HttpCodes.ServiceUnavailable, - HttpCodes.GatewayTimeout + HttpCodes.GatewayTimeout, ]; return retryableStatusCodes.includes(statusCode); } @@ -64,8 +64,8 @@ function createAcceptHeader(type: string, apiVersion: string): string { function getRequestOptions(): IRequestOptions { const requestOptions: IRequestOptions = { headers: { - Accept: createAcceptHeader("application/json", "6.0-preview.1") - } + Accept: createAcceptHeader("application/json", "6.0-preview.1"), + }, }; return requestOptions; @@ -86,7 +86,7 @@ export function getCacheVersion(): string { // Add salt to cache version to support breaking changes in cache entry const components = [ core.getInput(Inputs.Path, { required: true }), - versionSalt + versionSalt, ]; return crypto @@ -130,7 +130,7 @@ async function pipeResponseToStream( response: IHttpClientResponse, stream: NodeJS.WritableStream ): Promise { - return new Promise(resolve => { + return new Promise((resolve) => { response.message.pipe(stream).on("close", () => { resolve(); }); @@ -154,7 +154,7 @@ export async function reserveCache(key: string): Promise { const reserveCacheRequest: ReserveCacheRequest = { key, - version + version, }; const response = await httpClient.postJson( getCacheApiUrl("caches"), @@ -180,16 +180,16 @@ async function uploadChunk( end: number ): Promise { core.debug( - `Uploading chunk of size ${end - - start + - 1} bytes at offset ${start} with content range: ${getContentRange( + `Uploading chunk of size ${ + end - start + 1 + } bytes at offset ${start} with content range: ${getContentRange( start, end )}` ); const additionalHeaders = { "Content-Type": "application/octet-stream", - "Content-Range": getContentRange(start, end) + "Content-Range": getContentRange(start, end), }; const uploadChunkRequest = async (): Promise => { @@ -263,7 +263,7 @@ async function uploadFile( fd, start, end, - autoClose: false + autoClose: false, }); await uploadChunk( diff --git a/src/constants.ts b/src/constants.ts index 2b78f62..ae3640e 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,22 +1,22 @@ export enum Inputs { Key = "key", Path = "path", - RestoreKeys = "restore-keys" + RestoreKeys = "restore-keys", } export enum Outputs { - CacheHit = "cache-hit" + CacheHit = "cache-hit", } export enum State { CacheKey = "CACHE_KEY", - CacheResult = "CACHE_RESULT" + CacheResult = "CACHE_RESULT", } export enum Events { Key = "GITHUB_EVENT_NAME", Push = "push", - PullRequest = "pull_request" + PullRequest = "pull_request", } export const CacheFilename = "cache.tgz"; diff --git a/src/restore.ts b/src/restore.ts index 112e851..fae6cde 100644 --- a/src/restore.ts +++ b/src/restore.ts @@ -26,7 +26,7 @@ async function run(): Promise { const restoreKeys = core .getInput(Inputs.RestoreKeys) .split("\n") - .filter(x => x !== ""); + .filter((x) => x !== ""); const keys = [primaryKey, ...restoreKeys]; core.debug("Resolved Keys:"); diff --git a/src/save.ts b/src/save.ts index 6fdca6e..c448c55 100644 --- a/src/save.ts +++ b/src/save.ts @@ -48,7 +48,7 @@ async function run(): Promise { core .getInput(Inputs.Path, { required: true }) .split("\n") - .filter(x => x !== "") + .filter((x) => x !== "") ); core.debug("Cache Paths:"); diff --git a/src/tar.ts b/src/tar.ts index 3ca3019..c59ebb7 100644 --- a/src/tar.ts +++ b/src/tar.ts @@ -62,7 +62,7 @@ export async function createTar( "-C", workingDirectory, "--files-from", - manifestFilename + manifestFilename, ]; await execTar(args, archiveFolder); } diff --git a/src/utils/actionUtils.ts b/src/utils/actionUtils.ts index 0c02013..9c145a6 100644 --- a/src/utils/actionUtils.ts +++ b/src/utils/actionUtils.ts @@ -47,7 +47,7 @@ export function isExactKeyMatch( cacheResult && cacheResult.cacheKey && cacheResult.cacheKey.localeCompare(key, undefined, { - sensitivity: "accent" + sensitivity: "accent", }) === 0 ); } @@ -88,7 +88,7 @@ export async function resolvePaths(patterns: string[]): Promise { const paths: string[] = []; const workspace = process.env["GITHUB_WORKSPACE"] ?? process.cwd(); const globber = await glob.create(patterns.join("\n"), { - implicitDescendants: false + implicitDescendants: false, }); for await (const file of globber.globGenerator()) { diff --git a/tsconfig.json b/tsconfig.json index 960dc9f..e496f1a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,8 +2,8 @@ "compilerOptions": { /* Basic Options */ // "incremental": true, /* Enable incremental compilation */ - "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ + "target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */, + "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */, // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ @@ -11,8 +11,8 @@ // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ // "sourceMap": true, /* Generates corresponding '.map' file. */ // "outFile": "./", /* Concatenate and emit output to single file. */ - "outDir": "./lib", /* Redirect output structure to the directory. */ - "rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + "outDir": "./lib" /* Redirect output structure to the directory. */, + "rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */, // "composite": true, /* Enable project compilation */ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ // "removeComments": true, /* Do not emit comments to output. */ @@ -22,8 +22,8 @@ // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ /* Strict Type-Checking Options */ - "strict": true, /* Enable all strict type-checking options. */ - "noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */ + "strict": true /* Enable all strict type-checking options. */, + "noImplicitAny": false /* Raise error on expressions and declarations with an implied 'any' type. */, // "strictNullChecks": true, /* Enable strict null checks. */ // "strictFunctionTypes": true, /* Enable strict checking of function types. */ // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ @@ -45,7 +45,7 @@ // "typeRoots": [], /* List of folders to include type definitions from. */ // "types": [], /* Type declaration files to be included in compilation. */ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ - "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */