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