mirror of
https://github.com/actions/cache.git
synced 2026-08-05 19:02:14 +08:00
Compare commits
177 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2c8a9bd745 | |||
| e9b91fdc3f | |||
| e4884b8ff7 | |||
| 10baf0191a | |||
| e39b386c90 | |||
| b692820337 | |||
| 60749128a4 | |||
| 5a912e8b4a | |||
| b9bf592b98 | |||
| 80f777761d | |||
| 27d5ce7f10 | |||
| f280785d7b | |||
| 619aeb1606 | |||
| bcf16c2893 | |||
| 668228422a | |||
| e34039626f | |||
| 8a67110529 | |||
| 1865903e1b | |||
| 5656298164 | |||
| 4e380d19e1 | |||
| b7e8d49f17 | |||
| 984a21b1cb | |||
| acf2f1f76a | |||
| 95a07c5132 | |||
| 90e4fae240 | |||
| b45623637f | |||
| bdb94ce451 | |||
| cb6ea63971 | |||
| 49bc452f55 | |||
| 1e06c934a1 | |||
| a838313d22 | |||
| 6e48a73476 | |||
| 9848277c90 | |||
| 94056f1871 | |||
| b56bb3a202 | |||
| 4a6586c009 | |||
| 0de23fd4eb | |||
| 4e38c8636e | |||
| 24e8b877a8 | |||
| 3baa5f1c7b | |||
| cdf6c1fa76 | |||
| a1bee22673 | |||
| 46957638dc | |||
| dc73bb9f7b | |||
| 345d5c2f76 | |||
| 8b402f58fb | |||
| 304ab5a070 | |||
| 609fc19e67 | |||
| b22231e43d | |||
| 93150cdfb3 | |||
| 9b8ca9f07e | |||
| 5b7a9f8ae5 | |||
| de99935c0c | |||
| 9255dc7a25 | |||
| 8ff5423e8b | |||
| 9233019a15 | |||
| b975f2bb84 | |||
| d0a0e18134 | |||
| 74de208dcf | |||
| ac7f1152ea | |||
| b0f846b50b | |||
| a783357455 | |||
| 3bb0d78750 | |||
| 054c1f2301 | |||
| 07629789a8 | |||
| 9e02f8fbde | |||
| ffd11d22fe | |||
| 5bb537bda8 | |||
| 94a1e4b342 | |||
| 70a5ee3e57 | |||
| 5267c61f02 | |||
| 1513bf9d27 | |||
| 3b0346c531 | |||
| fe92eaff4b | |||
| 8070f1903a | |||
| 1285d7de7c | |||
| 6b1bb4d720 | |||
| 76fc20e7a9 | |||
| a5b36459de | |||
| 0062e4cc5f | |||
| 26b91aff41 | |||
| df217ffc5c | |||
| d3cff5bce3 | |||
| a9d8a74065 | |||
| 249f0e6cee | |||
| aa3f06a4c2 | |||
| b24583c7e6 | |||
| 5650dc9d27 | |||
| 4803712a90 | |||
| e92260483e | |||
| 5868a9c4a9 | |||
| 0057852bfa | |||
| 4f5ea67f1c | |||
| 9fcad95d03 | |||
| 99f840292b | |||
| d6693585a1 | |||
| 941dee2241 | |||
| 638ed79f9d | |||
| 3862dccb17 | |||
| 0400d5f644 | |||
| 374a27f269 | |||
| 358a7306cd | |||
| 2ee706ef74 | |||
| 94f7b5d913 | |||
| c36116c3f4 | |||
| 320fe7d56b | |||
| d81cc477d9 | |||
| de243982c5 | |||
| e7b6a9cc9d | |||
| 7e364f2770 | |||
| 94b8944262 | |||
| 640a1c2554 | |||
| c45d39173a | |||
| 5a3ec84eff | |||
| 7de21022a7 | |||
| 76d40dd347 | |||
| 76dd5eb692 | |||
| 8c80c27c5e | |||
| 45cfd0e7ff | |||
| edd449b9cf | |||
| 0576707e37 | |||
| 3105dc9754 | |||
| 9450d42d15 | |||
| 7d05b27fb9 | |||
| 507b84c6a6 | |||
| f248408e15 | |||
| c30eb5542e | |||
| 5b6ae99d8b | |||
| eca7c65a55 | |||
| 1b5d75f5cf | |||
| d4323d4df1 | |||
| da26677639 | |||
| 7921ae235b | |||
| 3937731706 | |||
| 0c907a75c2 | |||
| 710893c236 | |||
| 9fa7e61ec7 | |||
| 36f1e144e1 | |||
| 53aa38c736 | |||
| 1bd1e32a3b | |||
| 882d7ced4c | |||
| f2695d7a42 | |||
| f46ceeb60d | |||
| e6f5858749 | |||
| 4ae6f21c0d | |||
| c16df86586 | |||
| b109c12f3b | |||
| b7d227d702 | |||
| faf639248d | |||
| 4bc41c01bd | |||
| 6849a64899 | |||
| 5a1720c49e | |||
| d9fef48d24 | |||
| a50e8d027b | |||
| acc9ae5c14 | |||
| 1ea5f18c31 | |||
| cc679ff3ba | |||
| 366d43d6f8 | |||
| 02bf31969b | |||
| 6f6220be5a | |||
| ebdd24ede1 | |||
| 255c8ff306 | |||
| 010f24cd9d | |||
| d6151ba7db | |||
| 4ca7071576 | |||
| 5d692d65f4 | |||
| 3aef79d3a3 | |||
| aa55e5f344 | |||
| 772385291f | |||
| e5dc90df92 | |||
| 8585f2ac5c | |||
| 9803087a86 | |||
| e7e2547a88 | |||
| 71d826cc33 | |||
| 25942a73ac | |||
| d73025053b | |||
| 8469c94c6a |
@@ -0,0 +1,22 @@
|
|||||||
|
# To get started with Dependabot version updates, you'll need to specify which
|
||||||
|
# package ecosystems to update and where the package manifests are located.
|
||||||
|
# Please see the documentation for all configuration options:
|
||||||
|
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
|
||||||
|
|
||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "github-actions"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
||||||
|
groups:
|
||||||
|
minor-actions-dependencies:
|
||||||
|
update-types: [minor, patch]
|
||||||
|
|
||||||
|
- package-ecosystem: "npm"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "daily"
|
||||||
|
allow:
|
||||||
|
- dependency-type: direct
|
||||||
|
- dependency-type: production
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
name: Check dist/
|
name: Check dist content
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -11,9 +11,12 @@ on:
|
|||||||
- '**.md'
|
- '**.md'
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
call-check-dist:
|
call-check-dist:
|
||||||
name: Check dist/
|
name: Check dist/
|
||||||
uses: actions/reusable-workflows/.github/workflows/check-dist.yml@main
|
uses: actions/reusable-workflows/.github/workflows/check-dist.yml@main
|
||||||
with:
|
with:
|
||||||
node-version: "20.x"
|
node-version: "24.x"
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
name: Close inactive issues
|
name: Close inactive issues
|
||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: "30 8 * * *"
|
- cron: "30 8 * * *"
|
||||||
@@ -10,7 +11,7 @@ jobs:
|
|||||||
issues: write
|
issues: write
|
||||||
pull-requests: write
|
pull-requests: write
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/stale@v3
|
- uses: actions/stale@v9
|
||||||
with:
|
with:
|
||||||
days-before-issue-stale: 200
|
days-before-issue-stale: 200
|
||||||
days-before-issue-close: 5
|
days-before-issue-close: 5
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
name: "Code scanning - action"
|
name: Code scanning
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -6,22 +6,21 @@ on:
|
|||||||
schedule:
|
schedule:
|
||||||
- cron: '0 19 * * 0'
|
- cron: '0 19 * * 0'
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
security-events: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
CodeQL-Build:
|
CodeQL-Build:
|
||||||
# CodeQL runs on ubuntu-latest, windows-latest, and macos-latest
|
# CodeQL runs on ubuntu-latest, windows-latest, and macos-latest
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
permissions:
|
|
||||||
# required for all workflows
|
|
||||||
security-events: write
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@v2
|
uses: github/codeql-action/init@v3
|
||||||
# Override language selection by uncommenting this and choosing your languages
|
# Override language selection by uncommenting this and choosing your languages
|
||||||
# with:
|
# with:
|
||||||
# languages: go, javascript, csharp, python, cpp, java, ruby
|
# languages: go, javascript, csharp, python, cpp, java, ruby
|
||||||
@@ -29,7 +28,7 @@ jobs:
|
|||||||
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
|
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
|
||||||
# If this step fails, then you should remove it and run the build manually (see below).
|
# If this step fails, then you should remove it and run the build manually (see below).
|
||||||
- name: Autobuild
|
- name: Autobuild
|
||||||
uses: github/codeql-action/autobuild@v2
|
uses: github/codeql-action/autobuild@v3
|
||||||
|
|
||||||
# ℹ️ Command-line programs to run using the OS shell.
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
|
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
|
||||||
@@ -43,4 +42,4 @@ jobs:
|
|||||||
# make release
|
# make release
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@v2
|
uses: github/codeql-action/analyze@v3
|
||||||
|
|||||||
@@ -1,16 +1,21 @@
|
|||||||
name: Assign issue
|
name: Assign issue
|
||||||
|
|
||||||
on:
|
on:
|
||||||
issues:
|
issues:
|
||||||
types: [opened]
|
types: [opened]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
issues: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
run-action:
|
run-action:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Get current oncall
|
- name: Get current oncall
|
||||||
id: oncall
|
id: oncall
|
||||||
run: |
|
run: |
|
||||||
echo "CURRENT=$(curl --request GET 'https://api.pagerduty.com/oncalls?include[]=users&schedule_ids[]=P5VG2BX&earliest=true' --header 'Authorization: Token token=${{ secrets.PAGERDUTY_TOKEN }}' --header 'Accept: application/vnd.pagerduty+json;version=2' --header 'Content-Type: application/json' | jq -r '.oncalls[].user.name')" >> $GITHUB_OUTPUT
|
echo "CURRENT=$(curl --request GET 'https://api.pagerduty.com/oncalls?include[]=users&schedule_ids[]=P5VG2BX&earliest=true' --header 'Authorization: Token token=${{ secrets.PAGERDUTY_TOKEN }}' --header 'Accept: application/vnd.pagerduty+json;version=2' --header 'Content-Type: application/json' | jq -r '.oncalls[].user.name')" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: add_assignees
|
- name: add_assignees
|
||||||
run: |
|
run: |
|
||||||
curl -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN}}" https://api.github.com/repos/${{github.repository}}/issues/${{ github.event.issue.number}}/assignees -d '{"assignees":["${{steps.oncall.outputs.CURRENT}}"]}'
|
curl -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN}}" https://api.github.com/repos/${{github.repository}}/issues/${{ github.event.issue.number}}/assignees -d '{"assignees":["${{steps.oncall.outputs.CURRENT}}"]}'
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
name: Licensed
|
name: License check
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -9,7 +9,35 @@ on:
|
|||||||
- main
|
- main
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
call-licensed:
|
validate-cached-dependency-records:
|
||||||
name: Licensed
|
runs-on: ubuntu-latest
|
||||||
uses: actions/reusable-workflows/.github/workflows/licensed.yml@main
|
name: Check licenses
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci --ignore-scripts
|
||||||
|
|
||||||
|
- name: Set up Ruby
|
||||||
|
uses: ruby/setup-ruby@v1
|
||||||
|
with:
|
||||||
|
ruby-version: '3.1.7'
|
||||||
|
|
||||||
|
- name: Install licensed tool
|
||||||
|
run: |
|
||||||
|
cd "$RUNNER_TEMP"
|
||||||
|
curl -Lfs -o licensed.tar.gz https://github.com/licensee/licensed/archive/refs/tags/v5.0.4.tar.gz
|
||||||
|
tar -xzf licensed.tar.gz
|
||||||
|
cd licensed-5.0.4
|
||||||
|
bundle install
|
||||||
|
|
||||||
|
- name: Check cached dependency records
|
||||||
|
run: |
|
||||||
|
cd ${{ github.workspace }}
|
||||||
|
BUNDLE_GEMFILE=$RUNNER_TEMP/licensed-5.0.4/Gemfile bundle exec $RUNNER_TEMP/licensed-5.0.4/exe/licensed status
|
||||||
@@ -1,20 +1,25 @@
|
|||||||
name: Add Reviewer PR
|
name: Assign pull request reviewer
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request_target:
|
pull_request_target:
|
||||||
types: [opened]
|
types: [opened]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
pull-requests: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
run-action:
|
run-action:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Get current oncall
|
- name: Get current oncall
|
||||||
id: oncall
|
id: oncall
|
||||||
run: |
|
run: |
|
||||||
echo "CURRENT=$(curl --request GET 'https://api.pagerduty.com/oncalls?include[]=users&schedule_ids[]=P5VG2BX&earliest=true' --header 'Authorization: Token token=${{ secrets.PAGERDUTY_TOKEN }}' --header 'Accept: application/vnd.pagerduty+json;version=2' --header 'Content-Type: application/json' | jq -r '.oncalls[].user.name')" >> $GITHUB_OUTPUT
|
echo "CURRENT=$(curl --request GET 'https://api.pagerduty.com/oncalls?include[]=users&schedule_ids[]=P5VG2BX&earliest=true' --header 'Authorization: Token token=${{ secrets.PAGERDUTY_TOKEN }}' --header 'Accept: application/vnd.pagerduty+json;version=2' --header 'Content-Type: application/json' | jq -r '.oncalls[].user.name')" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Request Review
|
- name: Request Review
|
||||||
run: |
|
run: |
|
||||||
curl -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN}}" https://api.github.com/repos/${{github.repository}}/pulls/${{ github.event.pull_request.number}}/requested_reviewers -d '{"reviewers":["${{steps.oncall.outputs.CURRENT}}"]}'
|
curl -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN}}" https://api.github.com/repos/${{github.repository}}/pulls/${{ github.event.pull_request.number}}/requested_reviewers -d '{"reviewers":["${{steps.oncall.outputs.CURRENT}}"]}'
|
||||||
|
|
||||||
- name: Add Assignee
|
- name: Add Assignee
|
||||||
run: |
|
run: |
|
||||||
curl -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN}}" https://api.github.com/repos/${{github.repository}}/issues/${{ github.event.pull_request.number}}/assignees -d '{"assignees":["${{steps.oncall.outputs.CURRENT}}"]}'
|
curl -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN}}" https://api.github.com/repos/${{github.repository}}/issues/${{ github.event.pull_request.number}}/assignees -d '{"assignees":["${{steps.oncall.outputs.CURRENT}}"]}'
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
name: 'Publish Immutable Action Version'
|
name: Publish immutable action
|
||||||
|
|
||||||
on:
|
on:
|
||||||
release:
|
release:
|
||||||
types: [published]
|
types: [released]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
id-token: write
|
||||||
|
packages: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
publish:
|
publish:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
id-token: write
|
|
||||||
packages: write
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checking out
|
- name: Checking out
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
- name: Publish
|
- name: Publish
|
||||||
id: publish
|
id: publish
|
||||||
uses: actions/publish-immutable-action@0.0.3
|
uses: actions/publish-immutable-action@0.0.3
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
name: Release new action version
|
name: Release new action version
|
||||||
|
|
||||||
on:
|
on:
|
||||||
release:
|
release:
|
||||||
types: [released]
|
types: [released]
|
||||||
@@ -10,6 +11,7 @@ on:
|
|||||||
|
|
||||||
env:
|
env:
|
||||||
TAG_NAME: ${{ github.event.inputs.TAG_NAME || github.event.release.tag_name }}
|
TAG_NAME: ${{ github.event.inputs.TAG_NAME || github.event.release.tag_name }}
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
|
|
||||||
|
|||||||
+157
-10
@@ -10,6 +10,9 @@ on:
|
|||||||
- main
|
- main
|
||||||
- releases/**
|
- releases/**
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# Build and unit test
|
# Build and unit test
|
||||||
build:
|
build:
|
||||||
@@ -20,11 +23,11 @@ jobs:
|
|||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v5
|
||||||
- name: Setup Node.js 20.x
|
- name: Setup Node.js 24.x
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 20.x
|
node-version: 24.x
|
||||||
cache: npm
|
cache: npm
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- name: Prettier Format Check
|
- name: Prettier Format Check
|
||||||
@@ -43,7 +46,7 @@ jobs:
|
|||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v5
|
||||||
- name: Generate files in working directory
|
- name: Generate files in working directory
|
||||||
shell: bash
|
shell: bash
|
||||||
run: __tests__/create-cache-files.sh ${{ runner.os }} test-cache
|
run: __tests__/create-cache-files.sh ${{ runner.os }} test-cache
|
||||||
@@ -57,6 +60,7 @@ jobs:
|
|||||||
path: |
|
path: |
|
||||||
test-cache
|
test-cache
|
||||||
~/test-cache
|
~/test-cache
|
||||||
|
|
||||||
test-restore:
|
test-restore:
|
||||||
needs: test-save
|
needs: test-save
|
||||||
strategy:
|
strategy:
|
||||||
@@ -66,7 +70,7 @@ jobs:
|
|||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v5
|
||||||
- name: Restore cache
|
- name: Restore cache
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
@@ -86,17 +90,88 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container:
|
container:
|
||||||
image: ubuntu:latest
|
image: ubuntu:latest
|
||||||
options: --dns 127.0.0.1
|
options: --cap-add=NET_ADMIN
|
||||||
services:
|
services:
|
||||||
squid-proxy:
|
squid-proxy:
|
||||||
image: ubuntu/squid:latest
|
image: ubuntu/squid:latest
|
||||||
ports:
|
ports:
|
||||||
- 3128:3128
|
- 3128:3128
|
||||||
env:
|
env:
|
||||||
|
http_proxy: http://squid-proxy:3128
|
||||||
https_proxy: http://squid-proxy:3128
|
https_proxy: http://squid-proxy:3128
|
||||||
steps:
|
steps:
|
||||||
|
- name: Wait for proxy to be ready
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
echo "Waiting for squid proxy to be ready..."
|
||||||
|
echo "Resolving squid-proxy hostname:"
|
||||||
|
getent hosts squid-proxy || echo "DNS resolution failed"
|
||||||
|
for i in $(seq 1 30); do
|
||||||
|
if (echo > /dev/tcp/squid-proxy/3128) 2>/dev/null; then
|
||||||
|
echo "Proxy is ready!"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
echo "Attempt $i: Proxy not ready, waiting..."
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
echo "Proxy failed to become ready"
|
||||||
|
exit 1
|
||||||
|
env:
|
||||||
|
http_proxy: ""
|
||||||
|
https_proxy: ""
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
apt-get update
|
||||||
|
apt-get install -y iptables curl
|
||||||
|
- name: Verify proxy is working
|
||||||
|
run: |
|
||||||
|
echo "Testing proxy connectivity..."
|
||||||
|
curl -s -o /dev/null -w "%{http_code}" --proxy http://squid-proxy:3128 http://github.com || true
|
||||||
|
echo "Proxy verification complete"
|
||||||
|
- name: Block direct traffic (enforce proxy usage)
|
||||||
|
run: |
|
||||||
|
# Get the squid-proxy container IP
|
||||||
|
PROXY_IP=$(getent hosts squid-proxy | awk '{ print $1 }')
|
||||||
|
echo "Proxy IP: $PROXY_IP"
|
||||||
|
|
||||||
|
# Allow loopback traffic
|
||||||
|
iptables -A OUTPUT -o lo -j ACCEPT
|
||||||
|
|
||||||
|
# Allow traffic to the proxy container
|
||||||
|
iptables -A OUTPUT -d $PROXY_IP -j ACCEPT
|
||||||
|
|
||||||
|
# Allow established connections
|
||||||
|
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
|
||||||
|
|
||||||
|
# Allow DNS (needed for initial resolution)
|
||||||
|
iptables -A OUTPUT -p udp --dport 53 -j ACCEPT
|
||||||
|
iptables -A OUTPUT -p tcp --dport 53 -j ACCEPT
|
||||||
|
|
||||||
|
# Block all other outbound traffic (HTTP/HTTPS)
|
||||||
|
iptables -A OUTPUT -p tcp --dport 80 -j REJECT
|
||||||
|
iptables -A OUTPUT -p tcp --dport 443 -j REJECT
|
||||||
|
|
||||||
|
# Log the iptables rules for debugging
|
||||||
|
iptables -L -v -n
|
||||||
|
- name: Verify direct HTTPS is blocked
|
||||||
|
run: |
|
||||||
|
echo "Testing that direct HTTPS requests fail..."
|
||||||
|
if curl --noproxy '*' -s --connect-timeout 5 https://github.com > /dev/null 2>&1; then
|
||||||
|
echo "ERROR: Direct HTTPS request succeeded - blocking is not working!"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "SUCCESS: Direct HTTPS request was blocked as expected"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Testing that HTTPS through proxy succeeds..."
|
||||||
|
if curl --proxy http://squid-proxy:3128 -s --connect-timeout 10 https://github.com > /dev/null 2>&1; then
|
||||||
|
echo "SUCCESS: HTTPS request through proxy succeeded"
|
||||||
|
else
|
||||||
|
echo "ERROR: HTTPS request through proxy failed!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v5
|
||||||
- name: Generate files
|
- name: Generate files
|
||||||
run: __tests__/create-cache-files.sh proxy test-cache
|
run: __tests__/create-cache-files.sh proxy test-cache
|
||||||
- name: Save cache
|
- name: Save cache
|
||||||
@@ -104,22 +179,94 @@ jobs:
|
|||||||
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
|
||||||
container:
|
container:
|
||||||
image: ubuntu:latest
|
image: ubuntu:latest
|
||||||
options: --dns 127.0.0.1
|
options: --cap-add=NET_ADMIN
|
||||||
services:
|
services:
|
||||||
squid-proxy:
|
squid-proxy:
|
||||||
image: ubuntu/squid:latest
|
image: ubuntu/squid:latest
|
||||||
ports:
|
ports:
|
||||||
- 3128:3128
|
- 3128:3128
|
||||||
env:
|
env:
|
||||||
|
http_proxy: http://squid-proxy:3128
|
||||||
https_proxy: http://squid-proxy:3128
|
https_proxy: http://squid-proxy:3128
|
||||||
steps:
|
steps:
|
||||||
|
- name: Wait for proxy to be ready
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
echo "Waiting for squid proxy to be ready..."
|
||||||
|
echo "Resolving squid-proxy hostname:"
|
||||||
|
getent hosts squid-proxy || echo "DNS resolution failed"
|
||||||
|
for i in $(seq 1 30); do
|
||||||
|
if (echo > /dev/tcp/squid-proxy/3128) 2>/dev/null; then
|
||||||
|
echo "Proxy is ready!"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
echo "Attempt $i: Proxy not ready, waiting..."
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
echo "Proxy failed to become ready"
|
||||||
|
exit 1
|
||||||
|
env:
|
||||||
|
http_proxy: ""
|
||||||
|
https_proxy: ""
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
apt-get update
|
||||||
|
apt-get install -y iptables curl
|
||||||
|
- name: Verify proxy is working
|
||||||
|
run: |
|
||||||
|
echo "Testing proxy connectivity..."
|
||||||
|
curl -s -o /dev/null -w "%{http_code}" --proxy http://squid-proxy:3128 http://github.com || true
|
||||||
|
echo "Proxy verification complete"
|
||||||
|
- name: Block direct traffic (enforce proxy usage)
|
||||||
|
run: |
|
||||||
|
# Get the squid-proxy container IP
|
||||||
|
PROXY_IP=$(getent hosts squid-proxy | awk '{ print $1 }')
|
||||||
|
echo "Proxy IP: $PROXY_IP"
|
||||||
|
|
||||||
|
# Allow loopback traffic
|
||||||
|
iptables -A OUTPUT -o lo -j ACCEPT
|
||||||
|
|
||||||
|
# Allow traffic to the proxy container
|
||||||
|
iptables -A OUTPUT -d $PROXY_IP -j ACCEPT
|
||||||
|
|
||||||
|
# Allow established connections
|
||||||
|
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
|
||||||
|
|
||||||
|
# Allow DNS (needed for initial resolution)
|
||||||
|
iptables -A OUTPUT -p udp --dport 53 -j ACCEPT
|
||||||
|
iptables -A OUTPUT -p tcp --dport 53 -j ACCEPT
|
||||||
|
|
||||||
|
# Block all other outbound traffic (HTTP/HTTPS)
|
||||||
|
iptables -A OUTPUT -p tcp --dport 80 -j REJECT
|
||||||
|
iptables -A OUTPUT -p tcp --dport 443 -j REJECT
|
||||||
|
|
||||||
|
# Log the iptables rules for debugging
|
||||||
|
iptables -L -v -n
|
||||||
|
- name: Verify direct HTTPS is blocked
|
||||||
|
run: |
|
||||||
|
echo "Testing that direct HTTPS requests fail..."
|
||||||
|
if curl --noproxy '*' -s --connect-timeout 5 https://github.com > /dev/null 2>&1; then
|
||||||
|
echo "ERROR: Direct HTTPS request succeeded - blocking is not working!"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "SUCCESS: Direct HTTPS request was blocked as expected"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Testing that HTTPS through proxy succeeds..."
|
||||||
|
if curl --proxy http://squid-proxy:3128 -s --connect-timeout 10 https://github.com > /dev/null 2>&1; then
|
||||||
|
echo "SUCCESS: HTTPS request through proxy succeeded"
|
||||||
|
else
|
||||||
|
echo "ERROR: HTTPS request through proxy failed!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v5
|
||||||
- name: Restore cache
|
- name: Restore cache
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
|
|||||||
+16
-1
@@ -1,6 +1,14 @@
|
|||||||
sources:
|
sources:
|
||||||
npm: true
|
npm: true
|
||||||
|
|
||||||
|
# Force UTF-8 encoding
|
||||||
|
encoding: 'utf-8'
|
||||||
|
|
||||||
|
# Ignore problematic packages with encoding issues
|
||||||
|
ignored:
|
||||||
|
npm:
|
||||||
|
- form-data
|
||||||
|
|
||||||
allowed:
|
allowed:
|
||||||
- apache-2.0
|
- apache-2.0
|
||||||
- bsd-2-clause
|
- bsd-2-clause
|
||||||
@@ -13,4 +21,11 @@ allowed:
|
|||||||
|
|
||||||
reviewed:
|
reviewed:
|
||||||
npm:
|
npm:
|
||||||
- sax
|
- sax
|
||||||
|
- "@protobuf-ts/plugin-framework" # Apache-2.0
|
||||||
|
- "@protobuf-ts/runtime" # Apache-2.0
|
||||||
|
- fs.realpath # ISC
|
||||||
|
- glob # ISC
|
||||||
|
- prettier # MIT
|
||||||
|
- lodash # MIT
|
||||||
|
- "@actions/http-client" # MIT
|
||||||
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Binary file not shown.
Generated
BIN
Binary file not shown.
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
Generated
BIN
Binary file not shown.
+1
-1
@@ -16,7 +16,7 @@ Please note that this project is released with a [Contributor Code of Conduct][c
|
|||||||
1. [Fork][fork] and clone the repository
|
1. [Fork][fork] and clone the repository
|
||||||
2. Configure and install the dependencies: `npm install`
|
2. Configure and install the dependencies: `npm install`
|
||||||
3. Make sure the tests pass on your machine: `npm run test`
|
3. Make sure the tests pass on your machine: `npm run test`
|
||||||
4. Create a new branch: `git checkout -b my-branch-name`
|
4. Create a new branch: `git switch -c my-branch-name`
|
||||||
5. Make your change, add tests, and make sure the tests still pass
|
5. Make your change, add tests, and make sure the tests still pass
|
||||||
6. Push to your fork and [submit a pull request][pr]
|
6. Push to your fork and [submit a pull request][pr]
|
||||||
7. Pat your self on the back and wait for your pull request to be reviewed and merged.
|
7. Pat your self on the back and wait for your pull request to be reviewed and merged.
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
This action allows caching dependencies and build outputs to improve workflow execution time.
|
This action allows caching dependencies and build outputs to improve workflow execution time.
|
||||||
|
|
||||||
>Two other actions are available in addition to the primary `cache` action:
|
>Two other actions are available in addition to the primary `cache` action:
|
||||||
|
>
|
||||||
>* [Restore action](./restore/README.md)
|
>* [Restore action](./restore/README.md)
|
||||||
>* [Save action](./save/README.md)
|
>* [Save action](./save/README.md)
|
||||||
|
|
||||||
@@ -14,12 +15,47 @@ See ["Caching dependencies to speed up workflows"](https://docs.github.com/en/ac
|
|||||||
|
|
||||||
## What's New
|
## What's New
|
||||||
|
|
||||||
|
### ⚠️ Important changes
|
||||||
|
|
||||||
|
> [!IMPORTANT]
|
||||||
|
> `actions/cache@v5` runs on the Node.js 24 runtime and requires a minimum Actions Runner version of `2.327.1`.
|
||||||
|
> If you are using self-hosted runners, ensure they are updated before upgrading.
|
||||||
|
|
||||||
|
The cache backend service has been rewritten from the ground up for improved performance and reliability. [actions/cache](https://github.com/actions/cache) now integrates with the new cache service (v2) APIs.
|
||||||
|
|
||||||
|
The new service will gradually roll out as of **February 1st, 2025**. The legacy service will also be sunset on the same date. Changes in these releases are **fully backward compatible**.
|
||||||
|
|
||||||
|
**We are deprecating some versions of this action**. We recommend upgrading to version `v4` or `v3` as soon as possible before **February 1st, 2025.** (Upgrade instructions below).
|
||||||
|
|
||||||
|
If you are using pinned SHAs, please use the SHAs of versions `v4.2.0` or `v3.4.0`.
|
||||||
|
|
||||||
|
If you do not upgrade, all workflow runs using any of the deprecated [actions/cache](https://github.com/actions/cache) will fail.
|
||||||
|
|
||||||
|
Upgrading to the recommended versions will not break your workflows.
|
||||||
|
|
||||||
|
> **Additionally, if you are managing your own GitHub runners, you must update your runner version to `2.231.0` or newer to ensure compatibility with the new cache service.**
|
||||||
|
> Failure to update both the action version and your runner version may result in workflow failures after the migration date.
|
||||||
|
|
||||||
|
Read more about the change & access the migration guide: [reference to the announcement](https://github.com/actions/cache/discussions/1510).
|
||||||
|
|
||||||
|
### v6
|
||||||
|
|
||||||
|
* Updated `@actions/cache`, `@actions/core`, `@actions/exec` to latest major versions
|
||||||
|
* Migrated to ESM module system
|
||||||
|
|
||||||
|
### v5
|
||||||
|
|
||||||
|
* Updated to node 24
|
||||||
|
* Requires a minimum Actions Runner version of `2.327.1`
|
||||||
|
|
||||||
### v4
|
### v4
|
||||||
|
|
||||||
|
* Integrated with the new cache service (v2) APIs.
|
||||||
* Updated to node 20
|
* Updated to node 20
|
||||||
|
|
||||||
### v3
|
### v3
|
||||||
|
|
||||||
|
* Integrated with the new cache service (v2) APIs.
|
||||||
* Added support for caching in GHES 3.5+.
|
* Added support for caching in GHES 3.5+.
|
||||||
* Fixed download issue for files > 2GB during restore.
|
* Fixed download issue for files > 2GB during restore.
|
||||||
* Updated the minimum runner version support from node 12 -> node 16.
|
* Updated the minimum runner version support from node 12 -> node 16.
|
||||||
@@ -47,6 +83,8 @@ Create a workflow `.yml` file in your repository's `.github/workflows` directory
|
|||||||
|
|
||||||
If you are using this inside a container, a POSIX-compliant `tar` needs to be included and accessible from the execution path.
|
If you are using this inside a container, a POSIX-compliant `tar` needs to be included and accessible from the execution path.
|
||||||
|
|
||||||
|
Note: `actions/cache@v5` runs on Node.js 24 and requires a minimum Actions Runner version of `2.327.1`.
|
||||||
|
|
||||||
If you are using a `self-hosted` Windows runner, `GNU tar` and `zstd` are required for [Cross-OS caching](https://github.com/actions/cache/blob/main/tips-and-workarounds.md#cross-os-cache) to work. They are also recommended to be installed in general so the performance is on par with `hosted` Windows runners.
|
If you are using a `self-hosted` Windows runner, `GNU tar` and `zstd` are required for [Cross-OS caching](https://github.com/actions/cache/blob/main/tips-and-workarounds.md#cross-os-cache) to work. They are also recommended to be installed in general so the performance is on par with `hosted` Windows runners.
|
||||||
|
|
||||||
### Inputs
|
### Inputs
|
||||||
@@ -90,11 +128,11 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
- name: Cache Primes
|
- name: Cache Primes
|
||||||
id: cache-primes
|
id: cache-primes
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: prime-numbers
|
path: prime-numbers
|
||||||
key: ${{ runner.os }}-primes
|
key: ${{ runner.os }}-primes
|
||||||
@@ -121,11 +159,11 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
- name: Restore cached Primes
|
- name: Restore cached Primes
|
||||||
id: cache-primes-restore
|
id: cache-primes-restore
|
||||||
uses: actions/cache/restore@v4
|
uses: actions/cache/restore@v6
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
path/to/dependencies
|
path/to/dependencies
|
||||||
@@ -136,7 +174,7 @@ jobs:
|
|||||||
.
|
.
|
||||||
- name: Save Primes
|
- name: Save Primes
|
||||||
id: cache-primes-save
|
id: cache-primes-save
|
||||||
uses: actions/cache/save@v4
|
uses: actions/cache/save@v6
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
path/to/dependencies
|
path/to/dependencies
|
||||||
@@ -157,6 +195,7 @@ Every programming language and framework has its own way of caching.
|
|||||||
|
|
||||||
See [Examples](examples.md) for a list of `actions/cache` implementations for use with:
|
See [Examples](examples.md) for a list of `actions/cache` implementations for use with:
|
||||||
|
|
||||||
|
* [Bun](./examples.md#bun)
|
||||||
* [C# - NuGet](./examples.md#c---nuget)
|
* [C# - NuGet](./examples.md#c---nuget)
|
||||||
* [Clojure - Lein Deps](./examples.md#clojure---lein-deps)
|
* [Clojure - Lein Deps](./examples.md#clojure---lein-deps)
|
||||||
* [D - DUB](./examples.md#d---dub)
|
* [D - DUB](./examples.md#d---dub)
|
||||||
@@ -190,7 +229,7 @@ A cache key can include any of the contexts, functions, literals, and operators
|
|||||||
For example, using the [`hashFiles`](https://docs.github.com/en/actions/learn-github-actions/expressions#hashfiles) function allows you to create a new cache when dependencies change.
|
For example, using the [`hashFiles`](https://docs.github.com/en/actions/learn-github-actions/expressions#hashfiles) function allows you to create a new cache when dependencies change.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
path/to/dependencies
|
path/to/dependencies
|
||||||
@@ -208,7 +247,7 @@ Additionally, you can use arbitrary command output in a cache key, such as a dat
|
|||||||
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
|
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: path/to/dependencies
|
path: path/to/dependencies
|
||||||
key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/lockfiles') }}
|
key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/lockfiles') }}
|
||||||
@@ -228,9 +267,9 @@ Example:
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
id: cache
|
id: cache
|
||||||
with:
|
with:
|
||||||
path: path/to/dependencies
|
path: path/to/dependencies
|
||||||
@@ -258,11 +297,11 @@ jobs:
|
|||||||
build-linux:
|
build-linux:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
- name: Cache Primes
|
- name: Cache Primes
|
||||||
id: cache-primes
|
id: cache-primes
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: prime-numbers
|
path: prime-numbers
|
||||||
key: primes
|
key: primes
|
||||||
@@ -273,7 +312,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Cache Numbers
|
- name: Cache Numbers
|
||||||
id: cache-numbers
|
id: cache-numbers
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: numbers
|
path: numbers
|
||||||
key: primes
|
key: primes
|
||||||
@@ -285,11 +324,11 @@ jobs:
|
|||||||
build-windows:
|
build-windows:
|
||||||
runs-on: windows-latest
|
runs-on: windows-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
- name: Cache Primes
|
- name: Cache Primes
|
||||||
id: cache-primes
|
id: cache-primes
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: prime-numbers
|
path: prime-numbers
|
||||||
key: primes
|
key: primes
|
||||||
@@ -315,10 +354,24 @@ There are a number of community practices/workarounds to fulfill specific requir
|
|||||||
|
|
||||||
Please note that Windows environment variables (like `%LocalAppData%`) will NOT be expanded by this action. Instead, prefer using `~` in your paths which will expand to the HOME directory. For example, instead of `%LocalAppData%`, use `~\AppData\Local`. For a list of supported default environment variables, see the [Learn GitHub Actions: Variables](https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables) page.
|
Please note that Windows environment variables (like `%LocalAppData%`) will NOT be expanded by this action. Instead, prefer using `~` in your paths which will expand to the HOME directory. For example, instead of `%LocalAppData%`, use `~\AppData\Local`. For a list of supported default environment variables, see the [Learn GitHub Actions: Variables](https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables) page.
|
||||||
|
|
||||||
## Contributing
|
## Note
|
||||||
|
|
||||||
We would love for you to contribute to `actions/cache`. Pull requests are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) for more information.
|
Thank you for your interest in this GitHub repo, however, right now we are not taking contributions.
|
||||||
|
|
||||||
|
We continue to focus our resources on strategic areas that help our customers be successful while making developers' lives easier. While GitHub Actions remains a key part of this vision, we are allocating resources towards other areas of Actions and are not taking contributions to this repository at this time. The GitHub public roadmap is the best place to follow along for any updates on features we’re working on and what stage they’re in.
|
||||||
|
|
||||||
|
We are taking the following steps to better direct requests related to GitHub Actions, including:
|
||||||
|
|
||||||
|
1. We will be directing questions and support requests to our [Community Discussions area](https://github.com/orgs/community/discussions/categories/actions)
|
||||||
|
|
||||||
|
2. High Priority bugs can be reported through Community Discussions or you can report these to our support team https://support.github.com/contact/bug-report.
|
||||||
|
|
||||||
|
3. Security Issues should be handled as per our [security.md](SECURITY.md).
|
||||||
|
|
||||||
|
We will still provide security updates for this project and fix major breaking changes during this time.
|
||||||
|
|
||||||
|
You are welcome to still raise bugs in this repo.
|
||||||
|
|
||||||
## 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)
|
||||||
+101
@@ -1,9 +1,106 @@
|
|||||||
# Releases
|
# Releases
|
||||||
|
|
||||||
|
## How to prepare a release
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
> Relevant for maintainers with write access only.
|
||||||
|
|
||||||
|
1. Switch to a new branch from `main`.
|
||||||
|
1. Run `npm test` to ensure all tests are passing.
|
||||||
|
1. Update the version in [`package.json`](package.json).
|
||||||
|
1. Run `npm run build` to update the compiled files.
|
||||||
|
1. Update this [`RELEASES.md`](RELEASES.md) with the new version and changes in the `## Changelog` section.
|
||||||
|
1. Run `licensed cache` to update the license report.
|
||||||
|
1. Run `licensed status` and resolve any warnings by updating the [`.licensed.yml`](.licensed.yml) file with the exceptions.
|
||||||
|
1. Commit your changes and push your branch upstream.
|
||||||
|
1. Open a pull request against `main` and get it reviewed and merged.
|
||||||
|
1. Draft a new release https://github.com/actions/cache/releases use the same version number used in `package.json`
|
||||||
|
1. Create a new tag with the version number.
|
||||||
|
1. Auto generate release notes and update them to match the changes you made in `RELEASES.md`.
|
||||||
|
1. Toggle the set as the latest release option.
|
||||||
|
1. Publish the release.
|
||||||
|
1. Navigate to https://github.com/actions/cache/actions/workflows/release-new-action-version.yml
|
||||||
|
1. There should be a workflow run queued with the same version number.
|
||||||
|
1. Approve the run to publish the new version and update the major tags for this action.
|
||||||
|
|
||||||
|
## Changelog
|
||||||
|
|
||||||
|
### 6.0.0
|
||||||
|
|
||||||
|
- Updated `@actions/cache` to ^6.0.1, `@actions/core` to ^3.0.1, `@actions/exec` to ^3.0.0, `@actions/io` to ^3.0.2
|
||||||
|
- Migrated to ESM module system
|
||||||
|
- Upgraded Jest to v30 and test infrastructure to be ESM compatible
|
||||||
|
|
||||||
|
### 5.0.4
|
||||||
|
|
||||||
|
- Bump `minimatch` to v3.1.5 (fixes ReDoS via globstar patterns)
|
||||||
|
- Bump `undici` to v6.24.1 (WebSocket decompression bomb protection, header validation fixes)
|
||||||
|
- Bump `fast-xml-parser` to v5.5.6
|
||||||
|
|
||||||
|
### 5.0.3
|
||||||
|
|
||||||
|
- Bump `@actions/cache` to v5.0.5 (Resolves: https://github.com/actions/cache/security/dependabot/33)
|
||||||
|
- Bump `@actions/core` to v2.0.3
|
||||||
|
|
||||||
|
### 5.0.2
|
||||||
|
|
||||||
|
- Bump `@actions/cache` to v5.0.3 [#1692](https://github.com/actions/cache/pull/1692)
|
||||||
|
|
||||||
|
### 5.0.1
|
||||||
|
|
||||||
|
- Update `@azure/storage-blob` to `^12.29.1` via `@actions/cache@5.0.1` [#1685](https://github.com/actions/cache/pull/1685)
|
||||||
|
|
||||||
|
### 5.0.0
|
||||||
|
|
||||||
|
> [!IMPORTANT]
|
||||||
|
> `actions/cache@v5` runs on the Node.js 24 runtime and requires a minimum Actions Runner version of `2.327.1`.
|
||||||
|
> If you are using self-hosted runners, ensure they are updated before upgrading.
|
||||||
|
|
||||||
|
### 4.3.0
|
||||||
|
|
||||||
|
- Bump `@actions/cache` to [v4.1.0](https://github.com/actions/toolkit/pull/2132)
|
||||||
|
|
||||||
|
### 4.2.4
|
||||||
|
|
||||||
|
- Bump `@actions/cache` to v4.0.5
|
||||||
|
|
||||||
|
### 4.2.3
|
||||||
|
|
||||||
|
- Bump `@actions/cache` to v4.0.3 (obfuscates SAS token in debug logs for cache entries)
|
||||||
|
|
||||||
|
### 4.2.2
|
||||||
|
|
||||||
|
- Bump `@actions/cache` to v4.0.2
|
||||||
|
|
||||||
|
### 4.2.1
|
||||||
|
|
||||||
|
- Bump `@actions/cache` to v4.0.1
|
||||||
|
|
||||||
|
### 4.2.0
|
||||||
|
|
||||||
|
TLDR; The cache backend service has been rewritten from the ground up for improved performance and reliability. [actions/cache](https://github.com/actions/cache) now integrates with the new cache service (v2) APIs.
|
||||||
|
|
||||||
|
The new service will gradually roll out as of **February 1st, 2025**. The legacy service will also be sunset on the same date. Changes in these release are **fully backward compatible**.
|
||||||
|
|
||||||
|
**We are deprecating some versions of this action**. We recommend upgrading to version `v4` or `v3` as soon as possible before **February 1st, 2025.** (Upgrade instructions below).
|
||||||
|
|
||||||
|
If you are using pinned SHAs, please use the SHAs of versions `v4.2.0` or `v3.4.0`
|
||||||
|
|
||||||
|
If you do not upgrade, all workflow runs using any of the deprecated [actions/cache](https://github.com/actions/cache) will fail.
|
||||||
|
|
||||||
|
Upgrading to the recommended versions will not break your workflows.
|
||||||
|
|
||||||
|
### 4.1.2
|
||||||
|
|
||||||
|
- Add GitHub Enterprise Cloud instances hostname filters to inform API endpoint choices - [#1474](https://github.com/actions/cache/pull/1474)
|
||||||
|
- Security fix: Bump braces from 3.0.2 to 3.0.3 - [#1475](https://github.com/actions/cache/pull/1475)
|
||||||
|
|
||||||
### 4.1.1
|
### 4.1.1
|
||||||
|
|
||||||
- Restore original behavior of `cache-hit` output - [#1467](https://github.com/actions/cache/pull/1467)
|
- Restore original behavior of `cache-hit` output - [#1467](https://github.com/actions/cache/pull/1467)
|
||||||
|
|
||||||
### 4.1.0
|
### 4.1.0
|
||||||
|
|
||||||
- Ensure `cache-hit` output is set when a cache is missed - [#1404](https://github.com/actions/cache/pull/1404)
|
- Ensure `cache-hit` output is set when a cache is missed - [#1404](https://github.com/actions/cache/pull/1404)
|
||||||
- Deprecate `save-always` input - [#1452](https://github.com/actions/cache/pull/1452)
|
- Deprecate `save-always` input - [#1452](https://github.com/actions/cache/pull/1452)
|
||||||
|
|
||||||
@@ -19,6 +116,10 @@
|
|||||||
|
|
||||||
- Updated minimum runner version support from node 12 -> node 20
|
- Updated minimum runner version support from node 12 -> node 20
|
||||||
|
|
||||||
|
### 3.4.0
|
||||||
|
|
||||||
|
- Integrated with the new cache service (v2) APIs
|
||||||
|
|
||||||
### 3.3.3
|
### 3.3.3
|
||||||
|
|
||||||
- Updates @actions/cache to v3.2.3 to fix accidental mutated path arguments to `getCacheVersion` [actions/toolkit#1378](https://github.com/actions/toolkit/pull/1378)
|
- Updates @actions/cache to v3.2.3 to fix accidental mutated path arguments to `getCacheVersion` [actions/toolkit#1378](https://github.com/actions/toolkit/pull/1378)
|
||||||
|
|||||||
+109
-65
@@ -1,24 +1,74 @@
|
|||||||
import * as cache from "@actions/cache";
|
import { afterAll, beforeEach, expect, jest, test } from "@jest/globals";
|
||||||
import * as core from "@actions/core";
|
|
||||||
|
|
||||||
import { Events, RefKey } from "../src/constants";
|
// Mock @actions/core
|
||||||
import * as actionUtils from "../src/utils/actionUtils";
|
jest.unstable_mockModule("@actions/core", () => ({
|
||||||
import * as testUtils from "../src/utils/testUtils";
|
getInput: jest.fn((name: string, options?: { required?: boolean }) => {
|
||||||
|
const val =
|
||||||
|
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || "";
|
||||||
|
if (options && options.required && !val) {
|
||||||
|
throw new Error(`Input required and not supplied: ${name}`);
|
||||||
|
}
|
||||||
|
return val.trim();
|
||||||
|
}),
|
||||||
|
setOutput: jest.fn(),
|
||||||
|
setFailed: jest.fn(),
|
||||||
|
info: jest.fn(),
|
||||||
|
warning: jest.fn(),
|
||||||
|
debug: jest.fn(),
|
||||||
|
error: jest.fn(),
|
||||||
|
saveState: jest.fn(),
|
||||||
|
getState: jest.fn(() => ""),
|
||||||
|
isDebug: jest.fn(() => false),
|
||||||
|
exportVariable: jest.fn(),
|
||||||
|
addPath: jest.fn(),
|
||||||
|
group: jest.fn((name: string, fn: () => Promise<unknown>) => fn()),
|
||||||
|
startGroup: jest.fn(),
|
||||||
|
endGroup: jest.fn()
|
||||||
|
}));
|
||||||
|
|
||||||
jest.mock("@actions/core");
|
// Mock @actions/cache
|
||||||
jest.mock("@actions/cache");
|
jest.unstable_mockModule("@actions/cache", () => ({
|
||||||
|
restoreCache: jest.fn(),
|
||||||
|
saveCache: jest.fn(),
|
||||||
|
isFeatureAvailable: jest.fn(() => true),
|
||||||
|
ReserveCacheError: class ReserveCacheError extends Error {
|
||||||
|
constructor(message: string) {
|
||||||
|
super(message);
|
||||||
|
this.name = "ReserveCacheError";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
beforeAll(() => {
|
const core = await import("@actions/core");
|
||||||
jest.spyOn(core, "getInput").mockImplementation((name, options) => {
|
const cache = await import("@actions/cache");
|
||||||
return jest.requireActual("@actions/core").getInput(name, options);
|
const { Events, RefKey } = await import("../src/constants");
|
||||||
});
|
const actionUtils = await import("../src/utils/actionUtils");
|
||||||
});
|
const testUtils = await import("../src/utils/testUtils");
|
||||||
|
|
||||||
afterEach(() => {
|
let pristineEnv: NodeJS.ProcessEnv;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
pristineEnv = { ...process.env };
|
||||||
|
jest.clearAllMocks();
|
||||||
|
jest.mocked(core.getInput).mockImplementation(
|
||||||
|
(name: string, options?: { required?: boolean }) => {
|
||||||
|
const val =
|
||||||
|
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] ||
|
||||||
|
"";
|
||||||
|
if (options && options.required && !val) {
|
||||||
|
throw new Error(`Input required and not supplied: ${name}`);
|
||||||
|
}
|
||||||
|
return val.trim();
|
||||||
|
}
|
||||||
|
);
|
||||||
delete process.env[Events.Key];
|
delete process.env[Events.Key];
|
||||||
delete process.env[RefKey];
|
delete process.env[RefKey];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
process.env = pristineEnv;
|
||||||
|
});
|
||||||
|
|
||||||
test("isGhes returns true if server url is not github.com", () => {
|
test("isGhes returns true if server url is not github.com", () => {
|
||||||
try {
|
try {
|
||||||
process.env["GITHUB_SERVER_URL"] = "http://example.com";
|
process.env["GITHUB_SERVER_URL"] = "http://example.com";
|
||||||
@@ -38,74 +88,46 @@ test("isGhes returns false when server url is github.com", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("isExactKeyMatch with undefined cache key returns false", () => {
|
test("isExactKeyMatch with undefined cache key returns false", () => {
|
||||||
const key = "linux-rust";
|
expect(actionUtils.isExactKeyMatch("linux-rust", undefined)).toBe(false);
|
||||||
const cacheKey = undefined;
|
|
||||||
|
|
||||||
expect(actionUtils.isExactKeyMatch(key, cacheKey)).toBe(false);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("isExactKeyMatch with empty cache key returns false", () => {
|
test("isExactKeyMatch with empty cache key returns false", () => {
|
||||||
const key = "linux-rust";
|
expect(actionUtils.isExactKeyMatch("linux-rust", "")).toBe(false);
|
||||||
const cacheKey = "";
|
|
||||||
|
|
||||||
expect(actionUtils.isExactKeyMatch(key, cacheKey)).toBe(false);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("isExactKeyMatch with different keys returns false", () => {
|
test("isExactKeyMatch with different keys returns false", () => {
|
||||||
const key = "linux-rust";
|
expect(actionUtils.isExactKeyMatch("linux-rust", "linux-")).toBe(false);
|
||||||
const cacheKey = "linux-";
|
|
||||||
|
|
||||||
expect(actionUtils.isExactKeyMatch(key, cacheKey)).toBe(false);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("isExactKeyMatch with different key accents returns false", () => {
|
test("isExactKeyMatch with different key accents returns false", () => {
|
||||||
const key = "linux-áccent";
|
expect(actionUtils.isExactKeyMatch("linux-áccent", "linux-accent")).toBe(
|
||||||
const cacheKey = "linux-accent";
|
false
|
||||||
|
);
|
||||||
expect(actionUtils.isExactKeyMatch(key, cacheKey)).toBe(false);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("isExactKeyMatch with same key returns true", () => {
|
test("isExactKeyMatch with same key returns true", () => {
|
||||||
const key = "linux-rust";
|
expect(actionUtils.isExactKeyMatch("linux-rust", "linux-rust")).toBe(true);
|
||||||
const cacheKey = "linux-rust";
|
|
||||||
|
|
||||||
expect(actionUtils.isExactKeyMatch(key, cacheKey)).toBe(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";
|
expect(actionUtils.isExactKeyMatch("linux-rust", "LINUX-RUST")).toBe(true);
|
||||||
const cacheKey = "LINUX-RUST";
|
|
||||||
|
|
||||||
expect(actionUtils.isExactKeyMatch(key, cacheKey)).toBe(true);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("logWarning logs a message with a warning prefix", () => {
|
test("logWarning logs a message with a warning prefix", () => {
|
||||||
const message = "A warning occurred.";
|
const message = "A warning occurred.";
|
||||||
|
|
||||||
const infoMock = jest.spyOn(core, "info");
|
|
||||||
|
|
||||||
actionUtils.logWarning(message);
|
actionUtils.logWarning(message);
|
||||||
|
expect(core.info).toHaveBeenCalledWith(`[warning]${message}`);
|
||||||
expect(infoMock).toHaveBeenCalledWith(`[warning]${message}`);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("isValidEvent returns false for event that does not have a branch or tag", () => {
|
test("isValidEvent returns false for event that does not have a branch or tag", () => {
|
||||||
const event = "foo";
|
process.env[Events.Key] = "foo";
|
||||||
process.env[Events.Key] = event;
|
expect(actionUtils.isValidEvent()).toBe(false);
|
||||||
|
|
||||||
const isValidEvent = actionUtils.isValidEvent();
|
|
||||||
|
|
||||||
expect(isValidEvent).toBe(false);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("isValidEvent returns true for event that has a ref", () => {
|
test("isValidEvent returns true for event that has a ref", () => {
|
||||||
const event = Events.Push;
|
process.env[Events.Key] = Events.Push;
|
||||||
process.env[Events.Key] = event;
|
|
||||||
process.env[RefKey] = "ref/heads/feature";
|
process.env[RefKey] = "ref/heads/feature";
|
||||||
|
expect(actionUtils.isValidEvent()).toBe(true);
|
||||||
const isValidEvent = actionUtils.isValidEvent();
|
|
||||||
|
|
||||||
expect(isValidEvent).toBe(true);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("getInputAsArray returns empty array if not required and missing", () => {
|
test("getInputAsArray returns empty array if not required and missing", () => {
|
||||||
@@ -115,7 +137,7 @@ test("getInputAsArray returns empty array if not required and missing", () => {
|
|||||||
test("getInputAsArray throws error if required and missing", () => {
|
test("getInputAsArray throws error if required and missing", () => {
|
||||||
expect(() =>
|
expect(() =>
|
||||||
actionUtils.getInputAsArray("foo", { required: true })
|
actionUtils.getInputAsArray("foo", { required: true })
|
||||||
).toThrowError();
|
).toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("getInputAsArray handles single line correctly", () => {
|
test("getInputAsArray handles single line correctly", () => {
|
||||||
@@ -171,7 +193,7 @@ test("getInputAsInt returns undefined if input is invalid or NaN", () => {
|
|||||||
test("getInputAsInt throws if required and value missing", () => {
|
test("getInputAsInt throws if required and value missing", () => {
|
||||||
expect(() =>
|
expect(() =>
|
||||||
actionUtils.getInputAsInt("undefined", { required: true })
|
actionUtils.getInputAsInt("undefined", { required: true })
|
||||||
).toThrowError();
|
).toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("getInputAsBool returns false if input not set", () => {
|
test("getInputAsBool returns false if input not set", () => {
|
||||||
@@ -191,43 +213,65 @@ test("getInputAsBool returns false if input is invalid or NaN", () => {
|
|||||||
test("getInputAsBool throws if required and value missing", () => {
|
test("getInputAsBool throws if required and value missing", () => {
|
||||||
expect(() =>
|
expect(() =>
|
||||||
actionUtils.getInputAsBool("undefined2", { required: true })
|
actionUtils.getInputAsBool("undefined2", { required: true })
|
||||||
).toThrowError();
|
).toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("isCacheFeatureAvailable for ac enabled", () => {
|
test("isCacheFeatureAvailable for ac enabled", () => {
|
||||||
jest.spyOn(cache, "isFeatureAvailable").mockImplementation(() => true);
|
jest.mocked(cache.isFeatureAvailable).mockReturnValue(true);
|
||||||
|
|
||||||
expect(actionUtils.isCacheFeatureAvailable()).toBe(true);
|
expect(actionUtils.isCacheFeatureAvailable()).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("isCacheFeatureAvailable for ac disabled on GHES", () => {
|
test("isCacheFeatureAvailable for ac disabled on GHES", () => {
|
||||||
jest.spyOn(cache, "isFeatureAvailable").mockImplementation(() => false);
|
jest.mocked(cache.isFeatureAvailable).mockReturnValue(false);
|
||||||
|
|
||||||
const message = `Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.
|
const message = `Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.
|
||||||
Otherwise please upgrade to GHES version >= 3.5 and If you are also using Github Connect, please unretire the actions/cache namespace before upgrade (see https://docs.github.com/en/enterprise-server@3.5/admin/github-actions/managing-access-to-actions-from-githubcom/enabling-automatic-access-to-githubcom-actions-using-github-connect#automatic-retirement-of-namespaces-for-actions-accessed-on-githubcom)`;
|
Otherwise please upgrade to GHES version >= 3.5 and If you are also using Github Connect, please unretire the actions/cache namespace before upgrade (see https://docs.github.com/en/enterprise-server@3.5/admin/github-actions/managing-access-to-actions-from-githubcom/enabling-automatic-access-to-githubcom-actions-using-github-connect#automatic-retirement-of-namespaces-for-actions-accessed-on-githubcom)`;
|
||||||
const infoMock = jest.spyOn(core, "info");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
process.env["GITHUB_SERVER_URL"] = "http://example.com";
|
process.env["GITHUB_SERVER_URL"] = "http://example.com";
|
||||||
expect(actionUtils.isCacheFeatureAvailable()).toBe(false);
|
expect(actionUtils.isCacheFeatureAvailable()).toBe(false);
|
||||||
expect(infoMock).toHaveBeenCalledWith(`[warning]${message}`);
|
expect(core.info).toHaveBeenCalledWith(`[warning]${message}`);
|
||||||
} finally {
|
} finally {
|
||||||
delete process.env["GITHUB_SERVER_URL"];
|
delete process.env["GITHUB_SERVER_URL"];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test("isCacheFeatureAvailable for ac disabled on dotcom", () => {
|
test("isCacheFeatureAvailable for ac disabled on dotcom", () => {
|
||||||
jest.spyOn(cache, "isFeatureAvailable").mockImplementation(() => false);
|
jest.mocked(cache.isFeatureAvailable).mockReturnValue(false);
|
||||||
|
|
||||||
const message =
|
const message =
|
||||||
"An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions.";
|
"An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions.";
|
||||||
const infoMock = jest.spyOn(core, "info");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
process.env["GITHUB_SERVER_URL"] = "http://github.com";
|
process.env["GITHUB_SERVER_URL"] = "http://github.com";
|
||||||
expect(actionUtils.isCacheFeatureAvailable()).toBe(false);
|
expect(actionUtils.isCacheFeatureAvailable()).toBe(false);
|
||||||
expect(infoMock).toHaveBeenCalledWith(`[warning]${message}`);
|
expect(core.info).toHaveBeenCalledWith(`[warning]${message}`);
|
||||||
} finally {
|
} finally {
|
||||||
delete process.env["GITHUB_SERVER_URL"];
|
delete process.env["GITHUB_SERVER_URL"];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("isGhes returns false when the GITHUB_SERVER_URL environment variable is not defined", () => {
|
||||||
|
delete process.env["GITHUB_SERVER_URL"];
|
||||||
|
expect(actionUtils.isGhes()).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("isGhes returns false when the GITHUB_SERVER_URL environment variable is set to github.com", () => {
|
||||||
|
process.env["GITHUB_SERVER_URL"] = "https://github.com";
|
||||||
|
expect(actionUtils.isGhes()).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("isGhes returns false when the GITHUB_SERVER_URL environment variable is set to a GitHub Enterprise Cloud-style URL", () => {
|
||||||
|
process.env["GITHUB_SERVER_URL"] = "https://contoso.ghe.com";
|
||||||
|
expect(actionUtils.isGhes()).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("isGhes returns false when the GITHUB_SERVER_URL environment variable has a .localhost suffix", () => {
|
||||||
|
process.env["GITHUB_SERVER_URL"] = "https://mock-github.localhost";
|
||||||
|
expect(actionUtils.isGhes()).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("isGhes returns true when the GITHUB_SERVER_URL environment variable is set to some other URL", () => {
|
||||||
|
process.env["GITHUB_SERVER_URL"] = "https://src.onpremise.fabrikam.com";
|
||||||
|
expect(actionUtils.isGhes()).toBeTruthy();
|
||||||
|
});
|
||||||
|
|||||||
+108
-195
@@ -1,50 +1,66 @@
|
|||||||
import * as cache from "@actions/cache";
|
import { afterEach, beforeEach, expect, jest, test } from "@jest/globals";
|
||||||
import * as core from "@actions/core";
|
|
||||||
|
|
||||||
import { Events, RefKey } from "../src/constants";
|
// Mock @actions/core
|
||||||
import { restoreRun } from "../src/restoreImpl";
|
jest.unstable_mockModule("@actions/core", () => ({
|
||||||
import * as actionUtils from "../src/utils/actionUtils";
|
getInput: jest.fn((name: string, options?: { required?: boolean }) => {
|
||||||
import * as testUtils from "../src/utils/testUtils";
|
const val =
|
||||||
|
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || "";
|
||||||
jest.mock("../src/utils/actionUtils");
|
if (options && options.required && !val) {
|
||||||
|
throw new Error(`Input required and not supplied: ${name}`);
|
||||||
beforeAll(() => {
|
|
||||||
jest.spyOn(actionUtils, "isExactKeyMatch").mockImplementation(
|
|
||||||
(key, cacheResult) => {
|
|
||||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
|
||||||
return actualUtils.isExactKeyMatch(key, cacheResult);
|
|
||||||
}
|
}
|
||||||
);
|
return val.trim();
|
||||||
|
}),
|
||||||
|
setOutput: jest.fn(),
|
||||||
|
setFailed: jest.fn(),
|
||||||
|
info: jest.fn(),
|
||||||
|
warning: jest.fn(),
|
||||||
|
debug: jest.fn(),
|
||||||
|
error: jest.fn(),
|
||||||
|
saveState: jest.fn(),
|
||||||
|
getState: jest.fn(() => ""),
|
||||||
|
isDebug: jest.fn(() => false),
|
||||||
|
exportVariable: jest.fn(),
|
||||||
|
addPath: jest.fn(),
|
||||||
|
group: jest.fn((name: string, fn: () => Promise<unknown>) => fn()),
|
||||||
|
startGroup: jest.fn(),
|
||||||
|
endGroup: jest.fn()
|
||||||
|
}));
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "isValidEvent").mockImplementation(() => {
|
// Mock @actions/cache
|
||||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
jest.unstable_mockModule("@actions/cache", () => ({
|
||||||
return actualUtils.isValidEvent();
|
restoreCache: jest.fn(),
|
||||||
});
|
saveCache: jest.fn(),
|
||||||
|
isFeatureAvailable: jest.fn(() => true),
|
||||||
jest.spyOn(actionUtils, "getInputAsArray").mockImplementation(
|
ReserveCacheError: class ReserveCacheError extends Error {
|
||||||
(name, options) => {
|
constructor(message: string) {
|
||||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
super(message);
|
||||||
return actualUtils.getInputAsArray(name, options);
|
this.name = "ReserveCacheError";
|
||||||
}
|
}
|
||||||
);
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "getInputAsBool").mockImplementation(
|
const core = await import("@actions/core");
|
||||||
(name, options) => {
|
const cache = await import("@actions/cache");
|
||||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
const { Events, RefKey } = await import("../src/constants");
|
||||||
return actualUtils.getInputAsBool(name, options);
|
const { restoreRun } = await import("../src/restoreImpl");
|
||||||
}
|
const testUtils = await import("../src/utils/testUtils");
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.restoreAllMocks();
|
jest.clearAllMocks();
|
||||||
|
(core.getInput as jest.Mock).mockImplementation(
|
||||||
|
(name: string, options?: { required?: boolean }) => {
|
||||||
|
const val =
|
||||||
|
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] ||
|
||||||
|
"";
|
||||||
|
if (options && options.required && !val) {
|
||||||
|
throw new Error(`Input required and not supplied: ${name}`);
|
||||||
|
}
|
||||||
|
return val.trim();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
(cache.isFeatureAvailable as jest.Mock).mockReturnValue(true);
|
||||||
process.env[Events.Key] = Events.Push;
|
process.env[Events.Key] = Events.Push;
|
||||||
process.env[RefKey] = "refs/heads/feature-branch";
|
process.env[RefKey] = "refs/heads/feature-branch";
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false);
|
|
||||||
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
|
|
||||||
() => true
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@@ -62,19 +78,12 @@ test("restore with no cache found", async () => {
|
|||||||
enableCrossOsArchive: false
|
enableCrossOsArchive: false
|
||||||
});
|
});
|
||||||
|
|
||||||
const infoMock = jest.spyOn(core, "info");
|
(cache.restoreCache as jest.Mock).mockResolvedValue(undefined);
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
|
||||||
const restoreCacheMock = jest
|
|
||||||
.spyOn(cache, "restoreCache")
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return Promise.resolve(undefined);
|
|
||||||
});
|
|
||||||
|
|
||||||
await restoreRun();
|
await restoreRun();
|
||||||
|
|
||||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
expect(cache.restoreCache).toHaveBeenCalledWith(
|
||||||
[path],
|
[path],
|
||||||
key,
|
key,
|
||||||
[],
|
[],
|
||||||
@@ -84,12 +93,10 @@ test("restore with no cache found", async () => {
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||||
expect(stateMock).toHaveBeenCalledTimes(1);
|
expect(core.saveState).toHaveBeenCalledTimes(1);
|
||||||
|
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(core.info).toHaveBeenCalledWith(
|
||||||
|
|
||||||
expect(infoMock).toHaveBeenCalledWith(
|
|
||||||
`Cache not found for input keys: ${key}`
|
`Cache not found for input keys: ${key}`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -105,19 +112,12 @@ test("restore with restore keys and no cache found", async () => {
|
|||||||
enableCrossOsArchive: false
|
enableCrossOsArchive: false
|
||||||
});
|
});
|
||||||
|
|
||||||
const infoMock = jest.spyOn(core, "info");
|
(cache.restoreCache as jest.Mock).mockResolvedValue(undefined);
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
|
||||||
const restoreCacheMock = jest
|
|
||||||
.spyOn(cache, "restoreCache")
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return Promise.resolve(undefined);
|
|
||||||
});
|
|
||||||
|
|
||||||
await restoreRun();
|
await restoreRun();
|
||||||
|
|
||||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
expect(cache.restoreCache).toHaveBeenCalledWith(
|
||||||
[path],
|
[path],
|
||||||
key,
|
key,
|
||||||
[restoreKey],
|
[restoreKey],
|
||||||
@@ -127,12 +127,10 @@ test("restore with restore keys and no cache found", async () => {
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||||
expect(stateMock).toHaveBeenCalledTimes(1);
|
expect(core.saveState).toHaveBeenCalledTimes(1);
|
||||||
|
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(core.info).toHaveBeenCalledWith(
|
||||||
|
|
||||||
expect(infoMock).toHaveBeenCalledWith(
|
|
||||||
`Cache not found for input keys: ${key}, ${restoreKey}`
|
`Cache not found for input keys: ${key}, ${restoreKey}`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -146,20 +144,12 @@ test("restore with cache found for key", async () => {
|
|||||||
enableCrossOsArchive: false
|
enableCrossOsArchive: false
|
||||||
});
|
});
|
||||||
|
|
||||||
const infoMock = jest.spyOn(core, "info");
|
(cache.restoreCache as jest.Mock).mockResolvedValue(key);
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
|
||||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
|
||||||
const restoreCacheMock = jest
|
|
||||||
.spyOn(cache, "restoreCache")
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return Promise.resolve(key);
|
|
||||||
});
|
|
||||||
|
|
||||||
await restoreRun();
|
await restoreRun();
|
||||||
|
|
||||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
expect(cache.restoreCache).toHaveBeenCalledWith(
|
||||||
[path],
|
[path],
|
||||||
key,
|
key,
|
||||||
[],
|
[],
|
||||||
@@ -169,15 +159,13 @@ test("restore with cache found for key", async () => {
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", key);
|
expect(core.saveState).toHaveBeenCalledWith("CACHE_RESULT", key);
|
||||||
expect(stateMock).toHaveBeenCalledTimes(2);
|
expect(core.saveState).toHaveBeenCalledTimes(2);
|
||||||
|
expect(core.setOutput).toHaveBeenCalledTimes(1);
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "true");
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true");
|
expect(core.info).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
||||||
|
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||||
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("restore with cache found for restore key", async () => {
|
test("restore with cache found for restore key", async () => {
|
||||||
@@ -191,39 +179,20 @@ test("restore with cache found for restore key", async () => {
|
|||||||
enableCrossOsArchive: false
|
enableCrossOsArchive: false
|
||||||
});
|
});
|
||||||
|
|
||||||
const infoMock = jest.spyOn(core, "info");
|
(cache.restoreCache as jest.Mock).mockResolvedValue(restoreKey);
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
|
||||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
|
||||||
const restoreCacheMock = jest
|
|
||||||
.spyOn(cache, "restoreCache")
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return Promise.resolve(restoreKey);
|
|
||||||
});
|
|
||||||
|
|
||||||
await restoreRun();
|
await restoreRun();
|
||||||
|
|
||||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||||
[path],
|
expect(core.saveState).toHaveBeenCalledWith("CACHE_RESULT", restoreKey);
|
||||||
key,
|
expect(core.saveState).toHaveBeenCalledTimes(2);
|
||||||
[restoreKey],
|
expect(core.setOutput).toHaveBeenCalledTimes(1);
|
||||||
{
|
expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "false");
|
||||||
lookupOnly: false
|
expect(core.info).toHaveBeenCalledWith(
|
||||||
},
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
|
||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", restoreKey);
|
|
||||||
expect(stateMock).toHaveBeenCalledTimes(2);
|
|
||||||
|
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "false");
|
|
||||||
expect(infoMock).toHaveBeenCalledWith(
|
|
||||||
`Cache restored from key: ${restoreKey}`
|
`Cache restored from key: ${restoreKey}`
|
||||||
);
|
);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Fail restore when fail on cache miss is enabled and primary + restore keys not found", async () => {
|
test("Fail restore when fail on cache miss is enabled and primary + restore keys not found", async () => {
|
||||||
@@ -237,35 +206,17 @@ test("Fail restore when fail on cache miss is enabled and primary + restore keys
|
|||||||
failOnCacheMiss: true
|
failOnCacheMiss: true
|
||||||
});
|
});
|
||||||
|
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
(cache.restoreCache as jest.Mock).mockResolvedValue(undefined);
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
|
||||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
|
||||||
const restoreCacheMock = jest
|
|
||||||
.spyOn(cache, "restoreCache")
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return Promise.resolve(undefined);
|
|
||||||
});
|
|
||||||
|
|
||||||
await restoreRun();
|
await restoreRun();
|
||||||
|
|
||||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||||
[path],
|
expect(core.setOutput).toHaveBeenCalledTimes(0);
|
||||||
key,
|
expect(core.setFailed).toHaveBeenCalledWith(
|
||||||
[restoreKey],
|
|
||||||
{
|
|
||||||
lookupOnly: false
|
|
||||||
},
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(0);
|
|
||||||
|
|
||||||
expect(failedMock).toHaveBeenCalledWith(
|
|
||||||
`Failed to restore cache entry. Exiting as fail-on-cache-miss is set. Input key: ${key}`
|
`Failed to restore cache entry. Exiting as fail-on-cache-miss is set. Input key: ${key}`
|
||||||
);
|
);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(1);
|
expect(core.setFailed).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("restore when fail on cache miss is enabled and primary key doesn't match restored key", async () => {
|
test("restore when fail on cache miss is enabled and primary key doesn't match restored key", async () => {
|
||||||
@@ -279,40 +230,20 @@ test("restore when fail on cache miss is enabled and primary key doesn't match r
|
|||||||
failOnCacheMiss: true
|
failOnCacheMiss: true
|
||||||
});
|
});
|
||||||
|
|
||||||
const infoMock = jest.spyOn(core, "info");
|
(cache.restoreCache as jest.Mock).mockResolvedValue(restoreKey);
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
|
||||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
|
||||||
const restoreCacheMock = jest
|
|
||||||
.spyOn(cache, "restoreCache")
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return Promise.resolve(restoreKey);
|
|
||||||
});
|
|
||||||
|
|
||||||
await restoreRun();
|
await restoreRun();
|
||||||
|
|
||||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||||
[path],
|
expect(core.saveState).toHaveBeenCalledWith("CACHE_RESULT", restoreKey);
|
||||||
key,
|
expect(core.saveState).toHaveBeenCalledTimes(2);
|
||||||
[restoreKey],
|
expect(core.setOutput).toHaveBeenCalledTimes(1);
|
||||||
{
|
expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "false");
|
||||||
lookupOnly: false
|
expect(core.info).toHaveBeenCalledWith(
|
||||||
},
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
|
||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", restoreKey);
|
|
||||||
expect(stateMock).toHaveBeenCalledTimes(2);
|
|
||||||
|
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "false");
|
|
||||||
|
|
||||||
expect(infoMock).toHaveBeenCalledWith(
|
|
||||||
`Cache restored from key: ${restoreKey}`
|
`Cache restored from key: ${restoreKey}`
|
||||||
);
|
);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("restore with fail on cache miss disabled and no cache found", async () => {
|
test("restore with fail on cache miss disabled and no cache found", async () => {
|
||||||
@@ -326,33 +257,15 @@ test("restore with fail on cache miss disabled and no cache found", async () =>
|
|||||||
failOnCacheMiss: false
|
failOnCacheMiss: false
|
||||||
});
|
});
|
||||||
|
|
||||||
const infoMock = jest.spyOn(core, "info");
|
(cache.restoreCache as jest.Mock).mockResolvedValue(undefined);
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
|
||||||
const restoreCacheMock = jest
|
|
||||||
.spyOn(cache, "restoreCache")
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return Promise.resolve(undefined);
|
|
||||||
});
|
|
||||||
|
|
||||||
await restoreRun();
|
await restoreRun();
|
||||||
|
|
||||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||||
[path],
|
expect(core.saveState).toHaveBeenCalledTimes(1);
|
||||||
key,
|
expect(core.info).toHaveBeenCalledWith(
|
||||||
[restoreKey],
|
|
||||||
{
|
|
||||||
lookupOnly: false
|
|
||||||
},
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
|
||||||
expect(stateMock).toHaveBeenCalledTimes(1);
|
|
||||||
|
|
||||||
expect(infoMock).toHaveBeenCalledWith(
|
|
||||||
`Cache not found for input keys: ${key}, ${restoreKey}`
|
`Cache not found for input keys: ${key}, ${restoreKey}`
|
||||||
);
|
);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|||||||
+146
-254
@@ -1,51 +1,68 @@
|
|||||||
import * as cache from "@actions/cache";
|
import { afterEach, beforeEach, expect, jest, test } from "@jest/globals";
|
||||||
import * as core from "@actions/core";
|
|
||||||
|
|
||||||
import { Events, Inputs, RefKey } from "../src/constants";
|
// Mock @actions/core
|
||||||
import { restoreImpl } from "../src/restoreImpl";
|
jest.unstable_mockModule("@actions/core", () => ({
|
||||||
import { StateProvider } from "../src/stateProvider";
|
getInput: jest.fn((name: string, options?: { required?: boolean }) => {
|
||||||
import * as actionUtils from "../src/utils/actionUtils";
|
const val =
|
||||||
import * as testUtils from "../src/utils/testUtils";
|
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || "";
|
||||||
|
if (options && options.required && !val) {
|
||||||
jest.mock("../src/utils/actionUtils");
|
throw new Error(`Input required and not supplied: ${name}`);
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
jest.spyOn(actionUtils, "isExactKeyMatch").mockImplementation(
|
|
||||||
(key, cacheResult) => {
|
|
||||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
|
||||||
return actualUtils.isExactKeyMatch(key, cacheResult);
|
|
||||||
}
|
}
|
||||||
);
|
return val.trim();
|
||||||
|
}),
|
||||||
|
setOutput: jest.fn(),
|
||||||
|
setFailed: jest.fn(),
|
||||||
|
info: jest.fn(),
|
||||||
|
warning: jest.fn(),
|
||||||
|
debug: jest.fn(),
|
||||||
|
error: jest.fn(),
|
||||||
|
saveState: jest.fn(),
|
||||||
|
getState: jest.fn(() => ""),
|
||||||
|
isDebug: jest.fn(() => false),
|
||||||
|
exportVariable: jest.fn(),
|
||||||
|
addPath: jest.fn(),
|
||||||
|
group: jest.fn((name: string, fn: () => Promise<unknown>) => fn()),
|
||||||
|
startGroup: jest.fn(),
|
||||||
|
endGroup: jest.fn()
|
||||||
|
}));
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "isValidEvent").mockImplementation(() => {
|
// Mock @actions/cache
|
||||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
jest.unstable_mockModule("@actions/cache", () => ({
|
||||||
return actualUtils.isValidEvent();
|
restoreCache: jest.fn(),
|
||||||
});
|
saveCache: jest.fn(),
|
||||||
|
isFeatureAvailable: jest.fn(() => true),
|
||||||
jest.spyOn(actionUtils, "getInputAsArray").mockImplementation(
|
ReserveCacheError: class ReserveCacheError extends Error {
|
||||||
(name, options) => {
|
constructor(message: string) {
|
||||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
super(message);
|
||||||
return actualUtils.getInputAsArray(name, options);
|
this.name = "ReserveCacheError";
|
||||||
}
|
}
|
||||||
);
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "getInputAsBool").mockImplementation(
|
const core = await import("@actions/core");
|
||||||
(name, options) => {
|
const cache = await import("@actions/cache");
|
||||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
const { Events, Inputs, RefKey } = await import("../src/constants");
|
||||||
return actualUtils.getInputAsBool(name, options);
|
const { restoreImpl } = await import("../src/restoreImpl");
|
||||||
}
|
const { StateProvider } = await import("../src/stateProvider");
|
||||||
);
|
const testUtils = await import("../src/utils/testUtils");
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.restoreAllMocks();
|
jest.clearAllMocks();
|
||||||
|
jest.mocked(core.getInput).mockImplementation(
|
||||||
|
(name: string, options?: { required?: boolean }) => {
|
||||||
|
const val =
|
||||||
|
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] ||
|
||||||
|
"";
|
||||||
|
if (options && options.required && !val) {
|
||||||
|
throw new Error(`Input required and not supplied: ${name}`);
|
||||||
|
}
|
||||||
|
return val.trim();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
jest.mocked(core.getState).mockReturnValue("");
|
||||||
|
jest.mocked(cache.isFeatureAvailable).mockReturnValue(true);
|
||||||
process.env[Events.Key] = Events.Push;
|
process.env[Events.Key] = Events.Push;
|
||||||
process.env[RefKey] = "refs/heads/feature-branch";
|
process.env[RefKey] = "refs/heads/feature-branch";
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false);
|
|
||||||
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
|
|
||||||
() => true
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@@ -55,52 +72,45 @@ afterEach(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("restore with invalid event outputs warning", async () => {
|
test("restore with invalid event outputs warning", async () => {
|
||||||
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
|
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
const invalidEvent = "commit_comment";
|
const invalidEvent = "commit_comment";
|
||||||
process.env[Events.Key] = invalidEvent;
|
process.env[Events.Key] = invalidEvent;
|
||||||
delete process.env[RefKey];
|
delete process.env[RefKey];
|
||||||
await restoreImpl(new StateProvider());
|
await restoreImpl(new StateProvider());
|
||||||
expect(logWarningMock).toHaveBeenCalledWith(
|
expect(core.info).toHaveBeenCalledWith(
|
||||||
`Event Validation Error: The event type ${invalidEvent} is not supported because it's not tied to a branch or tag ref.`
|
`[warning]Event Validation Error: The event type ${invalidEvent} is not supported because it's not tied to a branch or tag ref.`
|
||||||
);
|
);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("restore without AC available should no-op", async () => {
|
test("restore without AC available should no-op", async () => {
|
||||||
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false);
|
jest.mocked(cache.isFeatureAvailable).mockReturnValue(false);
|
||||||
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
|
|
||||||
() => false
|
|
||||||
);
|
|
||||||
|
|
||||||
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
|
|
||||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
|
||||||
|
|
||||||
await restoreImpl(new StateProvider());
|
await restoreImpl(new StateProvider());
|
||||||
|
|
||||||
expect(restoreCacheMock).toHaveBeenCalledTimes(0);
|
expect(cache.restoreCache).toHaveBeenCalledTimes(0);
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
expect(core.setOutput).toHaveBeenCalledTimes(1);
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "false");
|
expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "false");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("restore on GHES without AC available should no-op", async () => {
|
test("restore on GHES without AC available should no-op", async () => {
|
||||||
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true);
|
process.env["GITHUB_SERVER_URL"] = "https://my-ghes-server.com";
|
||||||
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
|
jest.mocked(cache.isFeatureAvailable).mockReturnValue(false);
|
||||||
() => false
|
|
||||||
);
|
|
||||||
|
|
||||||
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
|
|
||||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
|
||||||
|
|
||||||
await restoreImpl(new StateProvider());
|
await restoreImpl(new StateProvider());
|
||||||
|
|
||||||
expect(restoreCacheMock).toHaveBeenCalledTimes(0);
|
expect(cache.restoreCache).toHaveBeenCalledTimes(0);
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
expect(core.setOutput).toHaveBeenCalledTimes(1);
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "false");
|
expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "false");
|
||||||
|
expect(core.info).toHaveBeenCalledWith(
|
||||||
|
expect.stringContaining(
|
||||||
|
"Cache action is only supported on GHES version >= 3.5"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
delete process.env["GITHUB_SERVER_URL"];
|
||||||
});
|
});
|
||||||
|
|
||||||
test("restore on GHES with AC available ", async () => {
|
test("restore on GHES with AC available ", async () => {
|
||||||
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true);
|
|
||||||
const path = "node_modules";
|
const path = "node_modules";
|
||||||
const key = "node-test";
|
const key = "node-test";
|
||||||
testUtils.setInputs({
|
testUtils.setInputs({
|
||||||
@@ -109,20 +119,12 @@ test("restore on GHES with AC available ", async () => {
|
|||||||
enableCrossOsArchive: false
|
enableCrossOsArchive: false
|
||||||
});
|
});
|
||||||
|
|
||||||
const infoMock = jest.spyOn(core, "info");
|
jest.mocked(cache.restoreCache).mockResolvedValue(key);
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
|
||||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
|
||||||
const restoreCacheMock = jest
|
|
||||||
.spyOn(cache, "restoreCache")
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return Promise.resolve(key);
|
|
||||||
});
|
|
||||||
|
|
||||||
await restoreImpl(new StateProvider());
|
await restoreImpl(new StateProvider());
|
||||||
|
|
||||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
expect(cache.restoreCache).toHaveBeenCalledWith(
|
||||||
[path],
|
[path],
|
||||||
key,
|
key,
|
||||||
[],
|
[],
|
||||||
@@ -132,32 +134,26 @@ test("restore on GHES with AC available ", async () => {
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
expect(core.setOutput).toHaveBeenCalledTimes(1);
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true");
|
expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "true");
|
||||||
|
expect(core.info).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
||||||
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("restore with no path should fail", async () => {
|
test("restore with no path should fail", async () => {
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
|
|
||||||
await restoreImpl(new StateProvider());
|
await restoreImpl(new StateProvider());
|
||||||
expect(restoreCacheMock).toHaveBeenCalledTimes(0);
|
expect(cache.restoreCache).toHaveBeenCalledTimes(0);
|
||||||
// this input isn't necessary for restore b/c tarball contains entries relative to workspace
|
expect(core.setFailed).not.toHaveBeenCalledWith(
|
||||||
expect(failedMock).not.toHaveBeenCalledWith(
|
|
||||||
"Input required and not supplied: path"
|
"Input required and not supplied: path"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("restore with no key", async () => {
|
test("restore with no key", async () => {
|
||||||
testUtils.setInput(Inputs.Path, "node_modules");
|
testUtils.setInput(Inputs.Path, "node_modules");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
|
|
||||||
await restoreImpl(new StateProvider());
|
await restoreImpl(new StateProvider());
|
||||||
expect(restoreCacheMock).toHaveBeenCalledTimes(0);
|
expect(cache.restoreCache).toHaveBeenCalledTimes(0);
|
||||||
expect(failedMock).toHaveBeenCalledWith(
|
expect(core.setFailed).toHaveBeenCalledWith(
|
||||||
"Input required and not supplied: key"
|
"Input required and not supplied: key"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -172,46 +168,32 @@ test("restore with too many keys should fail", async () => {
|
|||||||
restoreKeys,
|
restoreKeys,
|
||||||
enableCrossOsArchive: false
|
enableCrossOsArchive: false
|
||||||
});
|
});
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
jest.mocked(cache.restoreCache).mockRejectedValue(
|
||||||
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
|
new Error("Key Validation Error: Keys are limited to a maximum of 10.")
|
||||||
await restoreImpl(new StateProvider());
|
|
||||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
|
||||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
|
||||||
[path],
|
|
||||||
key,
|
|
||||||
restoreKeys,
|
|
||||||
{
|
|
||||||
lookupOnly: false
|
|
||||||
},
|
|
||||||
false
|
|
||||||
);
|
);
|
||||||
expect(failedMock).toHaveBeenCalledWith(
|
await restoreImpl(new StateProvider());
|
||||||
|
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||||
|
expect(core.setFailed).toHaveBeenCalledWith(
|
||||||
`Key Validation Error: Keys are limited to a maximum of 10.`
|
`Key Validation Error: Keys are limited to a maximum of 10.`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("restore with large key should fail", async () => {
|
test("restore with large key should fail", async () => {
|
||||||
const path = "node_modules";
|
const path = "node_modules";
|
||||||
const key = "foo".repeat(512); // Over the 512 character limit
|
const key = "foo".repeat(512);
|
||||||
testUtils.setInputs({
|
testUtils.setInputs({
|
||||||
path: path,
|
path: path,
|
||||||
key,
|
key,
|
||||||
enableCrossOsArchive: false
|
enableCrossOsArchive: false
|
||||||
});
|
});
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
jest.mocked(cache.restoreCache).mockRejectedValue(
|
||||||
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
|
new Error(
|
||||||
await restoreImpl(new StateProvider());
|
`Key Validation Error: ${key} cannot be larger than 512 characters.`
|
||||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
)
|
||||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
|
||||||
[path],
|
|
||||||
key,
|
|
||||||
[],
|
|
||||||
{
|
|
||||||
lookupOnly: false
|
|
||||||
},
|
|
||||||
false
|
|
||||||
);
|
);
|
||||||
expect(failedMock).toHaveBeenCalledWith(
|
await restoreImpl(new StateProvider());
|
||||||
|
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||||
|
expect(core.setFailed).toHaveBeenCalledWith(
|
||||||
`Key Validation Error: ${key} cannot be larger than 512 characters.`
|
`Key Validation Error: ${key} cannot be larger than 512 characters.`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -224,20 +206,12 @@ test("restore with invalid key should fail", async () => {
|
|||||||
key,
|
key,
|
||||||
enableCrossOsArchive: false
|
enableCrossOsArchive: false
|
||||||
});
|
});
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
jest.mocked(cache.restoreCache).mockRejectedValue(
|
||||||
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
|
new Error(`Key Validation Error: ${key} cannot contain commas.`)
|
||||||
await restoreImpl(new StateProvider());
|
|
||||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
|
||||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
|
||||||
[path],
|
|
||||||
key,
|
|
||||||
[],
|
|
||||||
{
|
|
||||||
lookupOnly: false
|
|
||||||
},
|
|
||||||
false
|
|
||||||
);
|
);
|
||||||
expect(failedMock).toHaveBeenCalledWith(
|
await restoreImpl(new StateProvider());
|
||||||
|
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||||
|
expect(core.setFailed).toHaveBeenCalledWith(
|
||||||
`Key Validation Error: ${key} cannot contain commas.`
|
`Key Validation Error: ${key} cannot contain commas.`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -251,32 +225,14 @@ test("restore with no cache found", async () => {
|
|||||||
enableCrossOsArchive: false
|
enableCrossOsArchive: false
|
||||||
});
|
});
|
||||||
|
|
||||||
const infoMock = jest.spyOn(core, "info");
|
jest.mocked(cache.restoreCache).mockResolvedValue(undefined);
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
|
||||||
const restoreCacheMock = jest
|
|
||||||
.spyOn(cache, "restoreCache")
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return Promise.resolve(undefined);
|
|
||||||
});
|
|
||||||
|
|
||||||
await restoreImpl(new StateProvider());
|
await restoreImpl(new StateProvider());
|
||||||
|
|
||||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||||
[path],
|
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||||
key,
|
expect(core.info).toHaveBeenCalledWith(
|
||||||
[],
|
|
||||||
{
|
|
||||||
lookupOnly: false
|
|
||||||
},
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
|
||||||
|
|
||||||
expect(infoMock).toHaveBeenCalledWith(
|
|
||||||
`Cache not found for input keys: ${key}`
|
`Cache not found for input keys: ${key}`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -292,32 +248,14 @@ test("restore with restore keys and no cache found", async () => {
|
|||||||
enableCrossOsArchive: false
|
enableCrossOsArchive: false
|
||||||
});
|
});
|
||||||
|
|
||||||
const infoMock = jest.spyOn(core, "info");
|
jest.mocked(cache.restoreCache).mockResolvedValue(undefined);
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
|
||||||
const restoreCacheMock = jest
|
|
||||||
.spyOn(cache, "restoreCache")
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return Promise.resolve(undefined);
|
|
||||||
});
|
|
||||||
|
|
||||||
await restoreImpl(new StateProvider());
|
await restoreImpl(new StateProvider());
|
||||||
|
|
||||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||||
[path],
|
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||||
key,
|
expect(core.info).toHaveBeenCalledWith(
|
||||||
[restoreKey],
|
|
||||||
{
|
|
||||||
lookupOnly: false
|
|
||||||
},
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
|
||||||
|
|
||||||
expect(infoMock).toHaveBeenCalledWith(
|
|
||||||
`Cache not found for input keys: ${key}, ${restoreKey}`
|
`Cache not found for input keys: ${key}, ${restoreKey}`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -331,35 +269,16 @@ test("restore with cache found for key", async () => {
|
|||||||
enableCrossOsArchive: false
|
enableCrossOsArchive: false
|
||||||
});
|
});
|
||||||
|
|
||||||
const infoMock = jest.spyOn(core, "info");
|
jest.mocked(cache.restoreCache).mockResolvedValue(key);
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
|
||||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
|
||||||
const restoreCacheMock = jest
|
|
||||||
.spyOn(cache, "restoreCache")
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return Promise.resolve(key);
|
|
||||||
});
|
|
||||||
|
|
||||||
await restoreImpl(new StateProvider());
|
await restoreImpl(new StateProvider());
|
||||||
|
|
||||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||||
[path],
|
expect(core.setOutput).toHaveBeenCalledTimes(1);
|
||||||
key,
|
expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "true");
|
||||||
[],
|
expect(core.info).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
||||||
{
|
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||||
lookupOnly: false
|
|
||||||
},
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true");
|
|
||||||
|
|
||||||
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("restore with cache found for restore key", async () => {
|
test("restore with cache found for restore key", async () => {
|
||||||
@@ -373,36 +292,18 @@ test("restore with cache found for restore key", async () => {
|
|||||||
enableCrossOsArchive: false
|
enableCrossOsArchive: false
|
||||||
});
|
});
|
||||||
|
|
||||||
const infoMock = jest.spyOn(core, "info");
|
jest.mocked(cache.restoreCache).mockResolvedValue(restoreKey);
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
|
||||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
|
||||||
const restoreCacheMock = jest
|
|
||||||
.spyOn(cache, "restoreCache")
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return Promise.resolve(restoreKey);
|
|
||||||
});
|
|
||||||
|
|
||||||
await restoreImpl(new StateProvider());
|
await restoreImpl(new StateProvider());
|
||||||
|
|
||||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||||
[path],
|
expect(core.setOutput).toHaveBeenCalledTimes(1);
|
||||||
key,
|
expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "false");
|
||||||
[restoreKey],
|
expect(core.info).toHaveBeenCalledWith(
|
||||||
{
|
|
||||||
lookupOnly: false
|
|
||||||
},
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "false");
|
|
||||||
expect(infoMock).toHaveBeenCalledWith(
|
|
||||||
`Cache restored from key: ${restoreKey}`
|
`Cache restored from key: ${restoreKey}`
|
||||||
);
|
);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("restore with lookup-only set", async () => {
|
test("restore with lookup-only set", async () => {
|
||||||
@@ -414,20 +315,12 @@ test("restore with lookup-only set", async () => {
|
|||||||
lookupOnly: true
|
lookupOnly: true
|
||||||
});
|
});
|
||||||
|
|
||||||
const infoMock = jest.spyOn(core, "info");
|
jest.mocked(cache.restoreCache).mockResolvedValue(key);
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
|
||||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
|
||||||
const restoreCacheMock = jest
|
|
||||||
.spyOn(cache, "restoreCache")
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return Promise.resolve(key);
|
|
||||||
});
|
|
||||||
|
|
||||||
await restoreImpl(new StateProvider());
|
await restoreImpl(new StateProvider());
|
||||||
|
|
||||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
expect(cache.restoreCache).toHaveBeenCalledWith(
|
||||||
[path],
|
[path],
|
||||||
key,
|
key,
|
||||||
[],
|
[],
|
||||||
@@ -437,31 +330,30 @@ test("restore with lookup-only set", async () => {
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", key);
|
expect(core.saveState).toHaveBeenCalledWith("CACHE_RESULT", key);
|
||||||
expect(stateMock).toHaveBeenCalledTimes(2);
|
expect(core.saveState).toHaveBeenCalledTimes(2);
|
||||||
|
expect(core.setOutput).toHaveBeenCalledTimes(1);
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "true");
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true");
|
expect(core.info).toHaveBeenCalledWith(
|
||||||
|
|
||||||
expect(infoMock).toHaveBeenCalledWith(
|
|
||||||
`Cache found and can be restored from key: ${key}`
|
`Cache found and can be restored from key: ${key}`
|
||||||
);
|
);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("restore failure with earlyExit should call process exit", async () => {
|
test("restore failure with earlyExit should call process exit", async () => {
|
||||||
testUtils.setInput(Inputs.Path, "node_modules");
|
testUtils.setInput(Inputs.Path, "node_modules");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const processExitMock = jest
|
||||||
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
|
.spyOn(process, "exit")
|
||||||
const processExitMock = jest.spyOn(process, "exit").mockImplementation();
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
.mockImplementation((() => {}) as any);
|
||||||
|
|
||||||
// call restoreImpl with `earlyExit` set to true
|
|
||||||
await restoreImpl(new StateProvider(), true);
|
await restoreImpl(new StateProvider(), true);
|
||||||
|
|
||||||
expect(restoreCacheMock).toHaveBeenCalledTimes(0);
|
expect(cache.restoreCache).toHaveBeenCalledTimes(0);
|
||||||
expect(failedMock).toHaveBeenCalledWith(
|
expect(core.setFailed).toHaveBeenCalledWith(
|
||||||
"Input required and not supplied: key"
|
"Input required and not supplied: key"
|
||||||
);
|
);
|
||||||
expect(processExitMock).toHaveBeenCalledWith(1);
|
expect(processExitMock).toHaveBeenCalledWith(1);
|
||||||
|
processExitMock.mockRestore();
|
||||||
});
|
});
|
||||||
|
|||||||
+84
-130
@@ -1,51 +1,66 @@
|
|||||||
import * as cache from "@actions/cache";
|
import { afterEach, beforeEach, expect, jest, test } from "@jest/globals";
|
||||||
import * as core from "@actions/core";
|
|
||||||
|
|
||||||
import { Events, RefKey } from "../src/constants";
|
// Mock @actions/core
|
||||||
import { restoreOnlyRun } from "../src/restoreImpl";
|
jest.unstable_mockModule("@actions/core", () => ({
|
||||||
import * as actionUtils from "../src/utils/actionUtils";
|
getInput: jest.fn((name: string, options?: { required?: boolean }) => {
|
||||||
import * as testUtils from "../src/utils/testUtils";
|
const val =
|
||||||
|
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || "";
|
||||||
jest.mock("../src/utils/actionUtils");
|
if (options && options.required && !val) {
|
||||||
|
throw new Error(`Input required and not supplied: ${name}`);
|
||||||
beforeAll(() => {
|
|
||||||
jest.spyOn(actionUtils, "isExactKeyMatch").mockImplementation(
|
|
||||||
(key, cacheResult) => {
|
|
||||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
|
||||||
return actualUtils.isExactKeyMatch(key, cacheResult);
|
|
||||||
}
|
}
|
||||||
);
|
return val.trim();
|
||||||
|
}),
|
||||||
|
setOutput: jest.fn(),
|
||||||
|
setFailed: jest.fn(),
|
||||||
|
info: jest.fn(),
|
||||||
|
warning: jest.fn(),
|
||||||
|
debug: jest.fn(),
|
||||||
|
error: jest.fn(),
|
||||||
|
saveState: jest.fn(),
|
||||||
|
getState: jest.fn(() => ""),
|
||||||
|
isDebug: jest.fn(() => false),
|
||||||
|
exportVariable: jest.fn(),
|
||||||
|
addPath: jest.fn(),
|
||||||
|
group: jest.fn((name: string, fn: () => Promise<unknown>) => fn()),
|
||||||
|
startGroup: jest.fn(),
|
||||||
|
endGroup: jest.fn()
|
||||||
|
}));
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "isValidEvent").mockImplementation(() => {
|
// Mock @actions/cache
|
||||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
jest.unstable_mockModule("@actions/cache", () => ({
|
||||||
return actualUtils.isValidEvent();
|
restoreCache: jest.fn(),
|
||||||
});
|
saveCache: jest.fn(),
|
||||||
|
isFeatureAvailable: jest.fn(() => true),
|
||||||
jest.spyOn(actionUtils, "getInputAsArray").mockImplementation(
|
ReserveCacheError: class ReserveCacheError extends Error {
|
||||||
(name, options) => {
|
constructor(message: string) {
|
||||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
super(message);
|
||||||
return actualUtils.getInputAsArray(name, options);
|
this.name = "ReserveCacheError";
|
||||||
}
|
}
|
||||||
);
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "getInputAsBool").mockImplementation(
|
const core = await import("@actions/core");
|
||||||
(name, options) => {
|
const cache = await import("@actions/cache");
|
||||||
return jest
|
const { Events, RefKey } = await import("../src/constants");
|
||||||
.requireActual("../src/utils/actionUtils")
|
const { restoreOnlyRun } = await import("../src/restoreImpl");
|
||||||
.getInputAsBool(name, options);
|
const testUtils = await import("../src/utils/testUtils");
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.restoreAllMocks();
|
jest.clearAllMocks();
|
||||||
|
(core.getInput as jest.Mock).mockImplementation(
|
||||||
|
(name: string, options?: { required?: boolean }) => {
|
||||||
|
const val =
|
||||||
|
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] ||
|
||||||
|
"";
|
||||||
|
if (options && options.required && !val) {
|
||||||
|
throw new Error(`Input required and not supplied: ${name}`);
|
||||||
|
}
|
||||||
|
return val.trim();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
(cache.isFeatureAvailable as jest.Mock).mockReturnValue(true);
|
||||||
process.env[Events.Key] = Events.Push;
|
process.env[Events.Key] = Events.Push;
|
||||||
process.env[RefKey] = "refs/heads/feature-branch";
|
process.env[RefKey] = "refs/heads/feature-branch";
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false);
|
|
||||||
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
|
|
||||||
() => true
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@@ -63,19 +78,12 @@ test("restore with no cache found", async () => {
|
|||||||
enableCrossOsArchive: false
|
enableCrossOsArchive: false
|
||||||
});
|
});
|
||||||
|
|
||||||
const infoMock = jest.spyOn(core, "info");
|
(cache.restoreCache as jest.Mock).mockResolvedValue(undefined);
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
const outputMock = jest.spyOn(core, "setOutput");
|
|
||||||
const restoreCacheMock = jest
|
|
||||||
.spyOn(cache, "restoreCache")
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return Promise.resolve(undefined);
|
|
||||||
});
|
|
||||||
|
|
||||||
await restoreOnlyRun();
|
await restoreOnlyRun();
|
||||||
|
|
||||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
expect(cache.restoreCache).toHaveBeenCalledWith(
|
||||||
[path],
|
[path],
|
||||||
key,
|
key,
|
||||||
[],
|
[],
|
||||||
@@ -85,11 +93,10 @@ test("restore with no cache found", async () => {
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
expect(core.setOutput).toHaveBeenCalledWith("cache-primary-key", key);
|
||||||
expect(outputMock).toHaveBeenCalledTimes(1);
|
expect(core.setOutput).toHaveBeenCalledTimes(1);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||||
|
expect(core.info).toHaveBeenCalledWith(
|
||||||
expect(infoMock).toHaveBeenCalledWith(
|
|
||||||
`Cache not found for input keys: ${key}`
|
`Cache not found for input keys: ${key}`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -105,32 +112,14 @@ test("restore with restore keys and no cache found", async () => {
|
|||||||
enableCrossOsArchive: false
|
enableCrossOsArchive: false
|
||||||
});
|
});
|
||||||
|
|
||||||
const infoMock = jest.spyOn(core, "info");
|
(cache.restoreCache as jest.Mock).mockResolvedValue(undefined);
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
const outputMock = jest.spyOn(core, "setOutput");
|
|
||||||
const restoreCacheMock = jest
|
|
||||||
.spyOn(cache, "restoreCache")
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return Promise.resolve(undefined);
|
|
||||||
});
|
|
||||||
|
|
||||||
await restoreOnlyRun();
|
await restoreOnlyRun();
|
||||||
|
|
||||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
expect(core.setOutput).toHaveBeenCalledWith("cache-primary-key", key);
|
||||||
[path],
|
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||||
key,
|
expect(core.info).toHaveBeenCalledWith(
|
||||||
[restoreKey],
|
|
||||||
{
|
|
||||||
lookupOnly: false
|
|
||||||
},
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
|
||||||
|
|
||||||
expect(infoMock).toHaveBeenCalledWith(
|
|
||||||
`Cache not found for input keys: ${key}, ${restoreKey}`
|
`Cache not found for input keys: ${key}, ${restoreKey}`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -144,36 +133,17 @@ test("restore with cache found for key", async () => {
|
|||||||
enableCrossOsArchive: false
|
enableCrossOsArchive: false
|
||||||
});
|
});
|
||||||
|
|
||||||
const infoMock = jest.spyOn(core, "info");
|
(cache.restoreCache as jest.Mock).mockResolvedValue(key);
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
const outputMock = jest.spyOn(core, "setOutput");
|
|
||||||
const restoreCacheMock = jest
|
|
||||||
.spyOn(cache, "restoreCache")
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return Promise.resolve(key);
|
|
||||||
});
|
|
||||||
|
|
||||||
await restoreOnlyRun();
|
await restoreOnlyRun();
|
||||||
|
|
||||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
expect(core.setOutput).toHaveBeenCalledWith("cache-primary-key", key);
|
||||||
[path],
|
expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "true");
|
||||||
key,
|
expect(core.setOutput).toHaveBeenCalledWith("cache-matched-key", key);
|
||||||
[],
|
expect(core.setOutput).toHaveBeenCalledTimes(3);
|
||||||
{
|
expect(core.info).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
||||||
lookupOnly: false
|
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||||
},
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
|
||||||
expect(outputMock).toHaveBeenCalledWith("cache-hit", "true");
|
|
||||||
expect(outputMock).toHaveBeenCalledWith("cache-matched-key", key);
|
|
||||||
|
|
||||||
expect(outputMock).toHaveBeenCalledTimes(3);
|
|
||||||
|
|
||||||
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("restore with cache found for restore key", async () => {
|
test("restore with cache found for restore key", async () => {
|
||||||
@@ -187,36 +157,20 @@ test("restore with cache found for restore key", async () => {
|
|||||||
enableCrossOsArchive: false
|
enableCrossOsArchive: false
|
||||||
});
|
});
|
||||||
|
|
||||||
const infoMock = jest.spyOn(core, "info");
|
(cache.restoreCache as jest.Mock).mockResolvedValue(restoreKey);
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
const outputMock = jest.spyOn(core, "setOutput");
|
|
||||||
const restoreCacheMock = jest
|
|
||||||
.spyOn(cache, "restoreCache")
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return Promise.resolve(restoreKey);
|
|
||||||
});
|
|
||||||
|
|
||||||
await restoreOnlyRun();
|
await restoreOnlyRun();
|
||||||
|
|
||||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
expect(core.setOutput).toHaveBeenCalledWith("cache-primary-key", key);
|
||||||
[path],
|
expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "false");
|
||||||
key,
|
expect(core.setOutput).toHaveBeenCalledWith(
|
||||||
[restoreKey],
|
"cache-matched-key",
|
||||||
{
|
restoreKey
|
||||||
lookupOnly: false
|
|
||||||
},
|
|
||||||
false
|
|
||||||
);
|
);
|
||||||
|
expect(core.setOutput).toHaveBeenCalledTimes(3);
|
||||||
expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
expect(core.info).toHaveBeenCalledWith(
|
||||||
expect(outputMock).toHaveBeenCalledWith("cache-hit", "false");
|
|
||||||
expect(outputMock).toHaveBeenCalledWith("cache-matched-key", restoreKey);
|
|
||||||
|
|
||||||
expect(outputMock).toHaveBeenCalledTimes(3);
|
|
||||||
|
|
||||||
expect(infoMock).toHaveBeenCalledWith(
|
|
||||||
`Cache restored from key: ${restoreKey}`
|
`Cache restored from key: ${restoreKey}`
|
||||||
);
|
);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|||||||
+61
-77
@@ -1,70 +1,66 @@
|
|||||||
import * as cache from "@actions/cache";
|
import { afterEach, beforeEach, expect, jest, test } from "@jest/globals";
|
||||||
import * as core from "@actions/core";
|
|
||||||
|
|
||||||
import { Events, Inputs, RefKey } from "../src/constants";
|
// Mock @actions/core
|
||||||
import { saveRun } from "../src/saveImpl";
|
jest.unstable_mockModule("@actions/core", () => ({
|
||||||
import * as actionUtils from "../src/utils/actionUtils";
|
getInput: jest.fn((name: string, options?: { required?: boolean }) => {
|
||||||
import * as testUtils from "../src/utils/testUtils";
|
const val =
|
||||||
|
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || "";
|
||||||
jest.mock("@actions/core");
|
if (options && options.required && !val) {
|
||||||
jest.mock("@actions/cache");
|
throw new Error(`Input required and not supplied: ${name}`);
|
||||||
jest.mock("../src/utils/actionUtils");
|
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
jest.spyOn(core, "getInput").mockImplementation((name, options) => {
|
|
||||||
return jest.requireActual("@actions/core").getInput(name, options);
|
|
||||||
});
|
|
||||||
|
|
||||||
jest.spyOn(core, "getState").mockImplementation(name => {
|
|
||||||
return jest.requireActual("@actions/core").getState(name);
|
|
||||||
});
|
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "getInputAsArray").mockImplementation(
|
|
||||||
(name, options) => {
|
|
||||||
return jest
|
|
||||||
.requireActual("../src/utils/actionUtils")
|
|
||||||
.getInputAsArray(name, options);
|
|
||||||
}
|
}
|
||||||
);
|
return val.trim();
|
||||||
|
}),
|
||||||
|
setOutput: jest.fn(),
|
||||||
|
setFailed: jest.fn(),
|
||||||
|
info: jest.fn(),
|
||||||
|
warning: jest.fn(),
|
||||||
|
debug: jest.fn(),
|
||||||
|
error: jest.fn(),
|
||||||
|
saveState: jest.fn(),
|
||||||
|
getState: jest.fn(() => ""),
|
||||||
|
isDebug: jest.fn(() => false),
|
||||||
|
exportVariable: jest.fn(),
|
||||||
|
addPath: jest.fn(),
|
||||||
|
group: jest.fn((name: string, fn: () => Promise<unknown>) => fn()),
|
||||||
|
startGroup: jest.fn(),
|
||||||
|
endGroup: jest.fn()
|
||||||
|
}));
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "getInputAsInt").mockImplementation(
|
// Mock @actions/cache
|
||||||
(name, options) => {
|
jest.unstable_mockModule("@actions/cache", () => ({
|
||||||
return jest
|
restoreCache: jest.fn(),
|
||||||
.requireActual("../src/utils/actionUtils")
|
saveCache: jest.fn(),
|
||||||
.getInputAsInt(name, options);
|
isFeatureAvailable: jest.fn(() => true),
|
||||||
|
ReserveCacheError: class ReserveCacheError extends Error {
|
||||||
|
constructor(message: string) {
|
||||||
|
super(message);
|
||||||
|
this.name = "ReserveCacheError";
|
||||||
}
|
}
|
||||||
);
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "getInputAsBool").mockImplementation(
|
const core = await import("@actions/core");
|
||||||
(name, options) => {
|
const cache = await import("@actions/cache");
|
||||||
return jest
|
const { Events, Inputs, RefKey } = await import("../src/constants");
|
||||||
.requireActual("../src/utils/actionUtils")
|
const { saveRun } = await import("../src/saveImpl");
|
||||||
.getInputAsBool(name, options);
|
const testUtils = await import("../src/utils/testUtils");
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "isExactKeyMatch").mockImplementation(
|
|
||||||
(key, cacheResult) => {
|
|
||||||
return jest
|
|
||||||
.requireActual("../src/utils/actionUtils")
|
|
||||||
.isExactKeyMatch(key, cacheResult);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "isValidEvent").mockImplementation(() => {
|
|
||||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
|
||||||
return actualUtils.isValidEvent();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
(core.getInput as jest.Mock).mockImplementation(
|
||||||
|
(name: string, options?: { required?: boolean }) => {
|
||||||
|
const val =
|
||||||
|
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] ||
|
||||||
|
"";
|
||||||
|
if (options && options.required && !val) {
|
||||||
|
throw new Error(`Input required and not supplied: ${name}`);
|
||||||
|
}
|
||||||
|
return val.trim();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
(cache.isFeatureAvailable as jest.Mock).mockReturnValue(true);
|
||||||
process.env[Events.Key] = Events.Push;
|
process.env[Events.Key] = Events.Push;
|
||||||
process.env[RefKey] = "refs/heads/feature-branch";
|
process.env[RefKey] = "refs/heads/feature-branch";
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false);
|
|
||||||
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
|
|
||||||
() => true
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@@ -74,36 +70,24 @@ afterEach(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("save with valid inputs uploads a cache", async () => {
|
test("save with valid inputs uploads a cache", async () => {
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
|
|
||||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||||
const savedCacheKey = "Linux-node-";
|
const savedCacheKey = "Linux-node-";
|
||||||
|
|
||||||
jest.spyOn(core, "getState")
|
(core.getState as jest.Mock)
|
||||||
// Cache Entry State
|
.mockReturnValueOnce(primaryKey)
|
||||||
.mockImplementationOnce(() => {
|
.mockReturnValueOnce(savedCacheKey);
|
||||||
return primaryKey;
|
|
||||||
})
|
|
||||||
// Cache Key State
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return savedCacheKey;
|
|
||||||
});
|
|
||||||
|
|
||||||
const inputPath = "node_modules";
|
const inputPath = "node_modules";
|
||||||
testUtils.setInput(Inputs.Path, inputPath);
|
testUtils.setInput(Inputs.Path, inputPath);
|
||||||
testUtils.setInput(Inputs.UploadChunkSize, "4000000");
|
testUtils.setInput(Inputs.UploadChunkSize, "4000000");
|
||||||
|
|
||||||
const cacheId = 4;
|
const cacheId = 4;
|
||||||
const saveCacheMock = jest
|
(cache.saveCache as jest.Mock).mockResolvedValue(cacheId);
|
||||||
.spyOn(cache, "saveCache")
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return Promise.resolve(cacheId);
|
|
||||||
});
|
|
||||||
|
|
||||||
await saveRun();
|
await saveRun();
|
||||||
|
|
||||||
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
expect(cache.saveCache).toHaveBeenCalledTimes(1);
|
||||||
expect(saveCacheMock).toHaveBeenCalledWith(
|
expect(cache.saveCache).toHaveBeenCalledWith(
|
||||||
[inputPath],
|
[inputPath],
|
||||||
primaryKey,
|
primaryKey,
|
||||||
{
|
{
|
||||||
@@ -112,5 +96,5 @@ test("save with valid inputs uploads a cache", async () => {
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|||||||
+135
-259
@@ -1,68 +1,68 @@
|
|||||||
import * as cache from "@actions/cache";
|
import { afterEach, beforeEach, expect, jest, test } from "@jest/globals";
|
||||||
import * as core from "@actions/core";
|
|
||||||
|
|
||||||
import { Events, Inputs, RefKey } from "../src/constants";
|
// Mock @actions/core
|
||||||
import { saveImpl } from "../src/saveImpl";
|
jest.unstable_mockModule("@actions/core", () => ({
|
||||||
import { StateProvider } from "../src/stateProvider";
|
getInput: jest.fn((name: string, options?: { required?: boolean }) => {
|
||||||
import * as actionUtils from "../src/utils/actionUtils";
|
const val =
|
||||||
import * as testUtils from "../src/utils/testUtils";
|
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || "";
|
||||||
|
if (options && options.required && !val) {
|
||||||
jest.mock("@actions/core");
|
throw new Error(`Input required and not supplied: ${name}`);
|
||||||
jest.mock("@actions/cache");
|
|
||||||
jest.mock("../src/utils/actionUtils");
|
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
jest.spyOn(core, "getInput").mockImplementation((name, options) => {
|
|
||||||
return jest.requireActual("@actions/core").getInput(name, options);
|
|
||||||
});
|
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "getInputAsArray").mockImplementation(
|
|
||||||
(name, options) => {
|
|
||||||
return jest
|
|
||||||
.requireActual("../src/utils/actionUtils")
|
|
||||||
.getInputAsArray(name, options);
|
|
||||||
}
|
}
|
||||||
);
|
return val.trim();
|
||||||
|
}),
|
||||||
|
setOutput: jest.fn(),
|
||||||
|
setFailed: jest.fn(),
|
||||||
|
info: jest.fn(),
|
||||||
|
warning: jest.fn(),
|
||||||
|
debug: jest.fn(),
|
||||||
|
error: jest.fn(),
|
||||||
|
saveState: jest.fn(),
|
||||||
|
getState: jest.fn(() => ""),
|
||||||
|
isDebug: jest.fn(() => false),
|
||||||
|
exportVariable: jest.fn(),
|
||||||
|
addPath: jest.fn(),
|
||||||
|
group: jest.fn((name: string, fn: () => Promise<unknown>) => fn()),
|
||||||
|
startGroup: jest.fn(),
|
||||||
|
endGroup: jest.fn()
|
||||||
|
}));
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "getInputAsInt").mockImplementation(
|
// Mock @actions/cache
|
||||||
(name, options) => {
|
jest.unstable_mockModule("@actions/cache", () => ({
|
||||||
return jest
|
restoreCache: jest.fn(),
|
||||||
.requireActual("../src/utils/actionUtils")
|
saveCache: jest.fn(),
|
||||||
.getInputAsInt(name, options);
|
isFeatureAvailable: jest.fn(() => true),
|
||||||
|
ReserveCacheError: class ReserveCacheError extends Error {
|
||||||
|
constructor(message: string) {
|
||||||
|
super(message);
|
||||||
|
this.name = "ReserveCacheError";
|
||||||
}
|
}
|
||||||
);
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "getInputAsBool").mockImplementation(
|
const core = await import("@actions/core");
|
||||||
(name, options) => {
|
const cache = await import("@actions/cache");
|
||||||
return jest
|
const { Events, Inputs, RefKey } = await import("../src/constants");
|
||||||
.requireActual("../src/utils/actionUtils")
|
const { saveImpl } = await import("../src/saveImpl");
|
||||||
.getInputAsBool(name, options);
|
const { StateProvider } = await import("../src/stateProvider");
|
||||||
}
|
const testUtils = await import("../src/utils/testUtils");
|
||||||
);
|
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "isExactKeyMatch").mockImplementation(
|
|
||||||
(key, cacheResult) => {
|
|
||||||
return jest
|
|
||||||
.requireActual("../src/utils/actionUtils")
|
|
||||||
.isExactKeyMatch(key, cacheResult);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "isValidEvent").mockImplementation(() => {
|
|
||||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
|
||||||
return actualUtils.isValidEvent();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.restoreAllMocks();
|
jest.clearAllMocks();
|
||||||
|
(core.getInput as jest.Mock).mockImplementation(
|
||||||
|
(name: string, options?: { required?: boolean }) => {
|
||||||
|
const val =
|
||||||
|
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] ||
|
||||||
|
"";
|
||||||
|
if (options && options.required && !val) {
|
||||||
|
throw new Error(`Input required and not supplied: ${name}`);
|
||||||
|
}
|
||||||
|
return val.trim();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
(core.getState as jest.Mock).mockReturnValue("");
|
||||||
|
(cache.isFeatureAvailable as jest.Mock).mockReturnValue(true);
|
||||||
process.env[Events.Key] = Events.Push;
|
process.env[Events.Key] = Events.Push;
|
||||||
process.env[RefKey] = "refs/heads/feature-branch";
|
process.env[RefKey] = "refs/heads/feature-branch";
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false);
|
|
||||||
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
|
|
||||||
() => true
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@@ -72,99 +72,69 @@ afterEach(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("save with invalid event outputs warning", async () => {
|
test("save with invalid event outputs warning", async () => {
|
||||||
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
|
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
const invalidEvent = "commit_comment";
|
const invalidEvent = "commit_comment";
|
||||||
process.env[Events.Key] = invalidEvent;
|
process.env[Events.Key] = invalidEvent;
|
||||||
delete process.env[RefKey];
|
delete process.env[RefKey];
|
||||||
await saveImpl(new StateProvider());
|
await saveImpl(new StateProvider());
|
||||||
expect(logWarningMock).toHaveBeenCalledWith(
|
expect(core.info).toHaveBeenCalledWith(
|
||||||
`Event Validation Error: The event type ${invalidEvent} is not supported because it's not tied to a branch or tag ref.`
|
`[warning]Event Validation Error: The event type ${invalidEvent} is not supported because it's not tied to a branch or tag ref.`
|
||||||
);
|
);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("save with no primary key in state outputs warning", async () => {
|
test("save with no primary key in state outputs warning", async () => {
|
||||||
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
|
(core.getState as jest.Mock).mockReturnValue("");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
|
|
||||||
const savedCacheKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
|
||||||
jest.spyOn(core, "getState")
|
|
||||||
// Cache Entry State
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return "";
|
|
||||||
})
|
|
||||||
// Cache Key State
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return savedCacheKey;
|
|
||||||
});
|
|
||||||
const saveCacheMock = jest.spyOn(cache, "saveCache");
|
|
||||||
|
|
||||||
await saveImpl(new StateProvider());
|
await saveImpl(new StateProvider());
|
||||||
|
|
||||||
expect(saveCacheMock).toHaveBeenCalledTimes(0);
|
expect(cache.saveCache).toHaveBeenCalledTimes(0);
|
||||||
expect(logWarningMock).toHaveBeenCalledWith(`Key is not specified.`);
|
expect(core.info).toHaveBeenCalledWith(`[warning]Key is not specified.`);
|
||||||
expect(logWarningMock).toHaveBeenCalledTimes(1);
|
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("save without AC available should no-op", async () => {
|
test("save without AC available should no-op", async () => {
|
||||||
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
|
(cache.isFeatureAvailable as jest.Mock).mockReturnValue(false);
|
||||||
() => false
|
|
||||||
);
|
|
||||||
|
|
||||||
const saveCacheMock = jest.spyOn(cache, "saveCache");
|
|
||||||
|
|
||||||
await saveImpl(new StateProvider());
|
await saveImpl(new StateProvider());
|
||||||
|
|
||||||
expect(saveCacheMock).toHaveBeenCalledTimes(0);
|
expect(cache.saveCache).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("save on ghes without AC available should no-op", async () => {
|
test("save on ghes without AC available should no-op", async () => {
|
||||||
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true);
|
process.env["GITHUB_SERVER_URL"] = "https://my-ghes-server.com";
|
||||||
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
|
(cache.isFeatureAvailable as jest.Mock).mockReturnValue(false);
|
||||||
() => false
|
|
||||||
);
|
|
||||||
|
|
||||||
const saveCacheMock = jest.spyOn(cache, "saveCache");
|
|
||||||
|
|
||||||
await saveImpl(new StateProvider());
|
await saveImpl(new StateProvider());
|
||||||
|
|
||||||
expect(saveCacheMock).toHaveBeenCalledTimes(0);
|
expect(cache.saveCache).toHaveBeenCalledTimes(0);
|
||||||
|
expect(core.info).toHaveBeenCalledWith(
|
||||||
|
expect.stringContaining(
|
||||||
|
"Cache action is only supported on GHES version >= 3.5"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
delete process.env["GITHUB_SERVER_URL"];
|
||||||
});
|
});
|
||||||
|
|
||||||
test("save on GHES with AC available", async () => {
|
test("save on GHES with AC available", async () => {
|
||||||
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true);
|
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
|
|
||||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||||
const savedCacheKey = "Linux-node-";
|
const savedCacheKey = "Linux-node-";
|
||||||
|
|
||||||
jest.spyOn(core, "getState")
|
(core.getState as jest.Mock)
|
||||||
// Cache Entry State
|
.mockReturnValueOnce(primaryKey)
|
||||||
.mockImplementationOnce(() => {
|
.mockReturnValueOnce(savedCacheKey);
|
||||||
return savedCacheKey;
|
|
||||||
})
|
|
||||||
// Cache Key State
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return primaryKey;
|
|
||||||
});
|
|
||||||
|
|
||||||
const inputPath = "node_modules";
|
const inputPath = "node_modules";
|
||||||
testUtils.setInput(Inputs.Path, inputPath);
|
testUtils.setInput(Inputs.Path, inputPath);
|
||||||
testUtils.setInput(Inputs.UploadChunkSize, "4000000");
|
testUtils.setInput(Inputs.UploadChunkSize, "4000000");
|
||||||
|
|
||||||
const cacheId = 4;
|
const cacheId = 4;
|
||||||
const saveCacheMock = jest
|
(cache.saveCache as jest.Mock).mockResolvedValue(cacheId);
|
||||||
.spyOn(cache, "saveCache")
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return Promise.resolve(cacheId);
|
|
||||||
});
|
|
||||||
|
|
||||||
await saveImpl(new StateProvider());
|
await saveImpl(new StateProvider());
|
||||||
|
|
||||||
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
expect(cache.saveCache).toHaveBeenCalledTimes(1);
|
||||||
expect(saveCacheMock).toHaveBeenCalledWith(
|
expect(cache.saveCache).toHaveBeenCalledWith(
|
||||||
[inputPath],
|
[inputPath],
|
||||||
primaryKey,
|
primaryKey,
|
||||||
{
|
{
|
||||||
@@ -173,229 +143,135 @@ test("save on GHES with AC available", async () => {
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("save with exact match returns early", async () => {
|
test("save with exact match returns early", async () => {
|
||||||
const infoMock = jest.spyOn(core, "info");
|
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
|
|
||||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||||
const savedCacheKey = primaryKey;
|
|
||||||
|
|
||||||
jest.spyOn(core, "getState")
|
(core.getState as jest.Mock)
|
||||||
// Cache Entry State
|
.mockReturnValueOnce(primaryKey)
|
||||||
.mockImplementationOnce(() => {
|
.mockReturnValueOnce(primaryKey);
|
||||||
return savedCacheKey;
|
|
||||||
})
|
|
||||||
// Cache Key State
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return primaryKey;
|
|
||||||
});
|
|
||||||
const saveCacheMock = jest.spyOn(cache, "saveCache");
|
|
||||||
|
|
||||||
await saveImpl(new StateProvider());
|
await saveImpl(new StateProvider());
|
||||||
|
|
||||||
expect(saveCacheMock).toHaveBeenCalledTimes(0);
|
expect(cache.saveCache).toHaveBeenCalledTimes(0);
|
||||||
expect(infoMock).toHaveBeenCalledWith(
|
expect(core.info).toHaveBeenCalledWith(
|
||||||
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
|
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
|
||||||
);
|
);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("save with missing input outputs warning", async () => {
|
test("save with missing input outputs warning", async () => {
|
||||||
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
|
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
|
|
||||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||||
const savedCacheKey = "Linux-node-";
|
const savedCacheKey = "Linux-node-";
|
||||||
|
|
||||||
jest.spyOn(core, "getState")
|
(core.getState as jest.Mock)
|
||||||
// Cache Entry State
|
.mockReturnValueOnce(primaryKey)
|
||||||
.mockImplementationOnce(() => {
|
.mockReturnValueOnce(savedCacheKey);
|
||||||
return savedCacheKey;
|
|
||||||
})
|
|
||||||
// Cache Key State
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return primaryKey;
|
|
||||||
});
|
|
||||||
const saveCacheMock = jest.spyOn(cache, "saveCache");
|
|
||||||
|
|
||||||
await saveImpl(new StateProvider());
|
await saveImpl(new StateProvider());
|
||||||
|
|
||||||
expect(saveCacheMock).toHaveBeenCalledTimes(0);
|
expect(cache.saveCache).toHaveBeenCalledTimes(0);
|
||||||
expect(logWarningMock).toHaveBeenCalledWith(
|
expect(core.info).toHaveBeenCalledWith(
|
||||||
"Input required and not supplied: path"
|
"[warning]Input required and not supplied: path"
|
||||||
);
|
);
|
||||||
expect(logWarningMock).toHaveBeenCalledTimes(1);
|
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("save with large cache outputs warning", async () => {
|
test("save with large cache outputs warning", async () => {
|
||||||
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
|
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
|
|
||||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||||
const savedCacheKey = "Linux-node-";
|
const savedCacheKey = "Linux-node-";
|
||||||
|
|
||||||
jest.spyOn(core, "getState")
|
(core.getState as jest.Mock)
|
||||||
// Cache Entry State
|
.mockReturnValueOnce(primaryKey)
|
||||||
.mockImplementationOnce(() => {
|
.mockReturnValueOnce(savedCacheKey);
|
||||||
return savedCacheKey;
|
|
||||||
})
|
|
||||||
// Cache Key State
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return primaryKey;
|
|
||||||
});
|
|
||||||
|
|
||||||
const inputPath = "node_modules";
|
const inputPath = "node_modules";
|
||||||
testUtils.setInput(Inputs.Path, inputPath);
|
testUtils.setInput(Inputs.Path, inputPath);
|
||||||
|
|
||||||
const saveCacheMock = jest
|
(cache.saveCache as jest.Mock).mockRejectedValue(
|
||||||
.spyOn(cache, "saveCache")
|
new Error(
|
||||||
.mockImplementationOnce(() => {
|
"Cache size of ~6144 MB (6442450944 B) is over the 5GB limit, not saving cache."
|
||||||
throw new Error(
|
)
|
||||||
"Cache size of ~6144 MB (6442450944 B) is over the 5GB limit, not saving cache."
|
);
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
await saveImpl(new StateProvider());
|
await saveImpl(new StateProvider());
|
||||||
|
|
||||||
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
expect(cache.saveCache).toHaveBeenCalledTimes(1);
|
||||||
expect(saveCacheMock).toHaveBeenCalledWith(
|
expect(core.info).toHaveBeenCalledWith(
|
||||||
[inputPath],
|
"[warning]Cache size of ~6144 MB (6442450944 B) is over the 5GB limit, not saving cache."
|
||||||
primaryKey,
|
|
||||||
expect.anything(),
|
|
||||||
false
|
|
||||||
);
|
);
|
||||||
|
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||||
expect(logWarningMock).toHaveBeenCalledTimes(1);
|
|
||||||
expect(logWarningMock).toHaveBeenCalledWith(
|
|
||||||
"Cache size of ~6144 MB (6442450944 B) is over the 5GB limit, not saving cache."
|
|
||||||
);
|
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("save with reserve cache failure outputs warning", async () => {
|
test("save with reserve cache failure outputs warning", async () => {
|
||||||
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
|
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
|
|
||||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||||
const savedCacheKey = "Linux-node-";
|
const savedCacheKey = "Linux-node-";
|
||||||
|
|
||||||
jest.spyOn(core, "getState")
|
(core.getState as jest.Mock)
|
||||||
// Cache Entry State
|
.mockReturnValueOnce(primaryKey)
|
||||||
.mockImplementationOnce(() => {
|
.mockReturnValueOnce(savedCacheKey);
|
||||||
return savedCacheKey;
|
|
||||||
})
|
|
||||||
// Cache Key State
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return primaryKey;
|
|
||||||
});
|
|
||||||
|
|
||||||
const inputPath = "node_modules";
|
const inputPath = "node_modules";
|
||||||
testUtils.setInput(Inputs.Path, inputPath);
|
testUtils.setInput(Inputs.Path, inputPath);
|
||||||
|
|
||||||
const saveCacheMock = jest
|
(cache.saveCache as jest.Mock).mockRejectedValue(
|
||||||
.spyOn(cache, "saveCache")
|
new Error(
|
||||||
.mockImplementationOnce(() => {
|
`Unable to reserve cache with key ${primaryKey}, another job may be creating this cache.`
|
||||||
const actualCache = jest.requireActual("@actions/cache");
|
)
|
||||||
const error = new actualCache.ReserveCacheError(
|
);
|
||||||
`Unable to reserve cache with key ${primaryKey}, another job may be creating this cache.`
|
|
||||||
);
|
|
||||||
throw error;
|
|
||||||
});
|
|
||||||
|
|
||||||
await saveImpl(new StateProvider());
|
await saveImpl(new StateProvider());
|
||||||
|
|
||||||
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
expect(cache.saveCache).toHaveBeenCalledTimes(1);
|
||||||
expect(saveCacheMock).toHaveBeenCalledWith(
|
expect(core.info).toHaveBeenCalledWith(
|
||||||
[inputPath],
|
`[warning]Unable to reserve cache with key ${primaryKey}, another job may be creating this cache.`
|
||||||
primaryKey,
|
|
||||||
expect.anything(),
|
|
||||||
false
|
|
||||||
);
|
);
|
||||||
|
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||||
expect(logWarningMock).toHaveBeenCalledWith(
|
|
||||||
`Unable to reserve cache with key ${primaryKey}, another job may be creating this cache.`
|
|
||||||
);
|
|
||||||
expect(logWarningMock).toHaveBeenCalledTimes(1);
|
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("save with server error outputs warning", async () => {
|
test("save with server error outputs warning", async () => {
|
||||||
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
|
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
|
|
||||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||||
const savedCacheKey = "Linux-node-";
|
const savedCacheKey = "Linux-node-";
|
||||||
|
|
||||||
jest.spyOn(core, "getState")
|
(core.getState as jest.Mock)
|
||||||
// Cache Entry State
|
.mockReturnValueOnce(primaryKey)
|
||||||
.mockImplementationOnce(() => {
|
.mockReturnValueOnce(savedCacheKey);
|
||||||
return savedCacheKey;
|
|
||||||
})
|
|
||||||
// Cache Key State
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return primaryKey;
|
|
||||||
});
|
|
||||||
|
|
||||||
const inputPath = "node_modules";
|
const inputPath = "node_modules";
|
||||||
testUtils.setInput(Inputs.Path, inputPath);
|
testUtils.setInput(Inputs.Path, inputPath);
|
||||||
|
|
||||||
const saveCacheMock = jest
|
(cache.saveCache as jest.Mock).mockRejectedValue(
|
||||||
.spyOn(cache, "saveCache")
|
new Error("HTTP Error Occurred")
|
||||||
.mockImplementationOnce(() => {
|
);
|
||||||
throw new Error("HTTP Error Occurred");
|
|
||||||
});
|
|
||||||
|
|
||||||
await saveImpl(new StateProvider());
|
await saveImpl(new StateProvider());
|
||||||
|
|
||||||
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
expect(cache.saveCache).toHaveBeenCalledTimes(1);
|
||||||
expect(saveCacheMock).toHaveBeenCalledWith(
|
expect(core.info).toHaveBeenCalledWith("[warning]HTTP Error Occurred");
|
||||||
[inputPath],
|
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||||
primaryKey,
|
|
||||||
expect.anything(),
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(logWarningMock).toHaveBeenCalledTimes(1);
|
|
||||||
expect(logWarningMock).toHaveBeenCalledWith("HTTP Error Occurred");
|
|
||||||
|
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("save with valid inputs uploads a cache", async () => {
|
test("save with valid inputs uploads a cache", async () => {
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
|
|
||||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||||
const savedCacheKey = "Linux-node-";
|
const savedCacheKey = "Linux-node-";
|
||||||
|
|
||||||
jest.spyOn(core, "getState")
|
(core.getState as jest.Mock)
|
||||||
// Cache Entry State
|
.mockReturnValueOnce(primaryKey)
|
||||||
.mockImplementationOnce(() => {
|
.mockReturnValueOnce(savedCacheKey);
|
||||||
return savedCacheKey;
|
|
||||||
})
|
|
||||||
// Cache Key State
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return primaryKey;
|
|
||||||
});
|
|
||||||
|
|
||||||
const inputPath = "node_modules";
|
const inputPath = "node_modules";
|
||||||
testUtils.setInput(Inputs.Path, inputPath);
|
testUtils.setInput(Inputs.Path, inputPath);
|
||||||
testUtils.setInput(Inputs.UploadChunkSize, "4000000");
|
testUtils.setInput(Inputs.UploadChunkSize, "4000000");
|
||||||
|
|
||||||
const cacheId = 4;
|
const cacheId = 4;
|
||||||
const saveCacheMock = jest
|
(cache.saveCache as jest.Mock).mockResolvedValue(cacheId);
|
||||||
.spyOn(cache, "saveCache")
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return Promise.resolve(cacheId);
|
|
||||||
});
|
|
||||||
|
|
||||||
await saveImpl(new StateProvider());
|
await saveImpl(new StateProvider());
|
||||||
|
|
||||||
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
expect(cache.saveCache).toHaveBeenCalledTimes(1);
|
||||||
expect(saveCacheMock).toHaveBeenCalledWith(
|
expect(cache.saveCache).toHaveBeenCalledWith(
|
||||||
[inputPath],
|
[inputPath],
|
||||||
primaryKey,
|
primaryKey,
|
||||||
{
|
{
|
||||||
@@ -404,5 +280,5 @@ test("save with valid inputs uploads a cache", async () => {
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|||||||
+63
-79
@@ -1,70 +1,66 @@
|
|||||||
import * as cache from "@actions/cache";
|
import { afterEach, beforeEach, expect, jest, test } from "@jest/globals";
|
||||||
import * as core from "@actions/core";
|
|
||||||
|
|
||||||
import { Events, Inputs, RefKey } from "../src/constants";
|
// Mock @actions/core
|
||||||
import { saveOnlyRun } from "../src/saveImpl";
|
jest.unstable_mockModule("@actions/core", () => ({
|
||||||
import * as actionUtils from "../src/utils/actionUtils";
|
getInput: jest.fn((name: string, options?: { required?: boolean }) => {
|
||||||
import * as testUtils from "../src/utils/testUtils";
|
const val =
|
||||||
|
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || "";
|
||||||
jest.mock("@actions/core");
|
if (options && options.required && !val) {
|
||||||
jest.mock("@actions/cache");
|
throw new Error(`Input required and not supplied: ${name}`);
|
||||||
jest.mock("../src/utils/actionUtils");
|
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
jest.spyOn(core, "getInput").mockImplementation((name, options) => {
|
|
||||||
return jest.requireActual("@actions/core").getInput(name, options);
|
|
||||||
});
|
|
||||||
|
|
||||||
jest.spyOn(core, "setOutput").mockImplementation((key, value) => {
|
|
||||||
return jest.requireActual("@actions/core").getInput(key, value);
|
|
||||||
});
|
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "getInputAsArray").mockImplementation(
|
|
||||||
(name, options) => {
|
|
||||||
return jest
|
|
||||||
.requireActual("../src/utils/actionUtils")
|
|
||||||
.getInputAsArray(name, options);
|
|
||||||
}
|
}
|
||||||
);
|
return val.trim();
|
||||||
|
}),
|
||||||
|
setOutput: jest.fn(),
|
||||||
|
setFailed: jest.fn(),
|
||||||
|
info: jest.fn(),
|
||||||
|
warning: jest.fn(),
|
||||||
|
debug: jest.fn(),
|
||||||
|
error: jest.fn(),
|
||||||
|
saveState: jest.fn(),
|
||||||
|
getState: jest.fn(() => ""),
|
||||||
|
isDebug: jest.fn(() => false),
|
||||||
|
exportVariable: jest.fn(),
|
||||||
|
addPath: jest.fn(),
|
||||||
|
group: jest.fn((name: string, fn: () => Promise<unknown>) => fn()),
|
||||||
|
startGroup: jest.fn(),
|
||||||
|
endGroup: jest.fn()
|
||||||
|
}));
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "getInputAsInt").mockImplementation(
|
// Mock @actions/cache
|
||||||
(name, options) => {
|
jest.unstable_mockModule("@actions/cache", () => ({
|
||||||
return jest
|
restoreCache: jest.fn(),
|
||||||
.requireActual("../src/utils/actionUtils")
|
saveCache: jest.fn(),
|
||||||
.getInputAsInt(name, options);
|
isFeatureAvailable: jest.fn(() => true),
|
||||||
|
ReserveCacheError: class ReserveCacheError extends Error {
|
||||||
|
constructor(message: string) {
|
||||||
|
super(message);
|
||||||
|
this.name = "ReserveCacheError";
|
||||||
}
|
}
|
||||||
);
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "getInputAsBool").mockImplementation(
|
const core = await import("@actions/core");
|
||||||
(name, options) => {
|
const cache = await import("@actions/cache");
|
||||||
return jest
|
const { Events, Inputs, RefKey } = await import("../src/constants");
|
||||||
.requireActual("../src/utils/actionUtils")
|
const { saveOnlyRun } = await import("../src/saveImpl");
|
||||||
.getInputAsBool(name, options);
|
const testUtils = await import("../src/utils/testUtils");
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "isExactKeyMatch").mockImplementation(
|
|
||||||
(key, cacheResult) => {
|
|
||||||
return jest
|
|
||||||
.requireActual("../src/utils/actionUtils")
|
|
||||||
.isExactKeyMatch(key, cacheResult);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "isValidEvent").mockImplementation(() => {
|
|
||||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
|
||||||
return actualUtils.isValidEvent();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
(core.getInput as jest.Mock).mockImplementation(
|
||||||
|
(name: string, options?: { required?: boolean }) => {
|
||||||
|
const val =
|
||||||
|
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] ||
|
||||||
|
"";
|
||||||
|
if (options && options.required && !val) {
|
||||||
|
throw new Error(`Input required and not supplied: ${name}`);
|
||||||
|
}
|
||||||
|
return val.trim();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
(cache.isFeatureAvailable as jest.Mock).mockReturnValue(true);
|
||||||
process.env[Events.Key] = Events.Push;
|
process.env[Events.Key] = Events.Push;
|
||||||
process.env[RefKey] = "refs/heads/feature-branch";
|
process.env[RefKey] = "refs/heads/feature-branch";
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false);
|
|
||||||
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
|
|
||||||
() => true
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@@ -74,8 +70,6 @@ afterEach(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("save with valid inputs uploads a cache", async () => {
|
test("save with valid inputs uploads a cache", async () => {
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
|
||||||
|
|
||||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||||
|
|
||||||
const inputPath = "node_modules";
|
const inputPath = "node_modules";
|
||||||
@@ -84,16 +78,12 @@ test("save with valid inputs uploads a cache", async () => {
|
|||||||
testUtils.setInput(Inputs.UploadChunkSize, "4000000");
|
testUtils.setInput(Inputs.UploadChunkSize, "4000000");
|
||||||
|
|
||||||
const cacheId = 4;
|
const cacheId = 4;
|
||||||
const saveCacheMock = jest
|
(cache.saveCache as jest.Mock).mockResolvedValue(cacheId);
|
||||||
.spyOn(cache, "saveCache")
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return Promise.resolve(cacheId);
|
|
||||||
});
|
|
||||||
|
|
||||||
await saveOnlyRun();
|
await saveOnlyRun();
|
||||||
|
|
||||||
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
expect(cache.saveCache).toHaveBeenCalledTimes(1);
|
||||||
expect(saveCacheMock).toHaveBeenCalledWith(
|
expect(cache.saveCache).toHaveBeenCalledWith(
|
||||||
[inputPath],
|
[inputPath],
|
||||||
primaryKey,
|
primaryKey,
|
||||||
{
|
{
|
||||||
@@ -102,12 +92,10 @@ test("save with valid inputs uploads a cache", async () => {
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("save failing logs the warning message", async () => {
|
test("save failing logs the warning message", async () => {
|
||||||
const warningMock = jest.spyOn(core, "warning");
|
|
||||||
|
|
||||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||||
|
|
||||||
const inputPath = "node_modules";
|
const inputPath = "node_modules";
|
||||||
@@ -116,16 +104,12 @@ test("save failing logs the warning message", async () => {
|
|||||||
testUtils.setInput(Inputs.UploadChunkSize, "4000000");
|
testUtils.setInput(Inputs.UploadChunkSize, "4000000");
|
||||||
|
|
||||||
const cacheId = -1;
|
const cacheId = -1;
|
||||||
const saveCacheMock = jest
|
(cache.saveCache as jest.Mock).mockResolvedValue(cacheId);
|
||||||
.spyOn(cache, "saveCache")
|
|
||||||
.mockImplementationOnce(() => {
|
|
||||||
return Promise.resolve(cacheId);
|
|
||||||
});
|
|
||||||
|
|
||||||
await saveOnlyRun();
|
await saveOnlyRun();
|
||||||
|
|
||||||
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
expect(cache.saveCache).toHaveBeenCalledTimes(1);
|
||||||
expect(saveCacheMock).toHaveBeenCalledWith(
|
expect(cache.saveCache).toHaveBeenCalledWith(
|
||||||
[inputPath],
|
[inputPath],
|
||||||
primaryKey,
|
primaryKey,
|
||||||
{
|
{
|
||||||
@@ -134,6 +118,6 @@ test("save failing logs the warning message", async () => {
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(warningMock).toHaveBeenCalledTimes(1);
|
expect(core.warning).toHaveBeenCalledTimes(1);
|
||||||
expect(warningMock).toHaveBeenCalledWith("Cache save failed.");
|
expect(core.warning).toHaveBeenCalledWith("Cache save failed.");
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,22 +1,41 @@
|
|||||||
import * as core from "@actions/core";
|
import { afterEach, beforeEach, expect, jest, test } from "@jest/globals";
|
||||||
|
|
||||||
import { Events, RefKey, State } from "../src/constants";
|
import type { IStateProvider } from "../src/stateProvider";
|
||||||
import {
|
|
||||||
IStateProvider,
|
|
||||||
NullStateProvider,
|
|
||||||
StateProvider
|
|
||||||
} from "../src/stateProvider";
|
|
||||||
|
|
||||||
jest.mock("@actions/core");
|
// Mock @actions/core
|
||||||
|
jest.unstable_mockModule("@actions/core", () => ({
|
||||||
|
getInput: jest.fn((name: string, options?: { required?: boolean }) => {
|
||||||
|
const val =
|
||||||
|
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || "";
|
||||||
|
if (options && options.required && !val) {
|
||||||
|
throw new Error(`Input required and not supplied: ${name}`);
|
||||||
|
}
|
||||||
|
return val.trim();
|
||||||
|
}),
|
||||||
|
setOutput: jest.fn(),
|
||||||
|
setFailed: jest.fn(),
|
||||||
|
info: jest.fn(),
|
||||||
|
warning: jest.fn(),
|
||||||
|
debug: jest.fn(),
|
||||||
|
error: jest.fn(),
|
||||||
|
saveState: jest.fn(),
|
||||||
|
getState: jest.fn(() => ""),
|
||||||
|
isDebug: jest.fn(() => false),
|
||||||
|
exportVariable: jest.fn(),
|
||||||
|
addPath: jest.fn(),
|
||||||
|
group: jest.fn((name: string, fn: () => Promise<unknown>) => fn()),
|
||||||
|
startGroup: jest.fn(),
|
||||||
|
endGroup: jest.fn()
|
||||||
|
}));
|
||||||
|
|
||||||
beforeAll(() => {
|
const core = await import("@actions/core");
|
||||||
jest.spyOn(core, "getInput").mockImplementation((name, options) => {
|
const { Events, RefKey, State } = await import("../src/constants");
|
||||||
return jest.requireActual("@actions/core").getInput(name, options);
|
const { NullStateProvider, StateProvider } =
|
||||||
});
|
await import("../src/stateProvider");
|
||||||
|
|
||||||
jest.spyOn(core, "setOutput").mockImplementation((key, value) => {
|
beforeEach(() => {
|
||||||
return jest.requireActual("@actions/core").setOutput(key, value);
|
jest.clearAllMocks();
|
||||||
});
|
(core.getState as jest.Mock).mockReturnValue("");
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@@ -26,21 +45,14 @@ afterEach(() => {
|
|||||||
|
|
||||||
test("StateProvider saves states", async () => {
|
test("StateProvider saves states", async () => {
|
||||||
const states = new Map<string, string>();
|
const states = new Map<string, string>();
|
||||||
const getStateMock = jest
|
(core.getState as jest.Mock).mockImplementation(
|
||||||
.spyOn(core, "getState")
|
(key: string) => states.get(key) || ""
|
||||||
.mockImplementation(key => states.get(key) || "");
|
);
|
||||||
|
(core.saveState as jest.Mock).mockImplementation(
|
||||||
const saveStateMock = jest
|
(key: string, value: string) => {
|
||||||
.spyOn(core, "saveState")
|
|
||||||
.mockImplementation((key, value) => {
|
|
||||||
states.set(key, value);
|
states.set(key, value);
|
||||||
});
|
}
|
||||||
|
);
|
||||||
const setOutputMock = jest
|
|
||||||
.spyOn(core, "setOutput")
|
|
||||||
.mockImplementation((key, value) => {
|
|
||||||
return jest.requireActual("@actions/core").setOutput(key, value);
|
|
||||||
});
|
|
||||||
|
|
||||||
const cacheMatchedKey = "node-cache";
|
const cacheMatchedKey = "node-cache";
|
||||||
|
|
||||||
@@ -52,38 +64,19 @@ test("StateProvider saves states", async () => {
|
|||||||
|
|
||||||
expect(stateValue).toBe("stateValue");
|
expect(stateValue).toBe("stateValue");
|
||||||
expect(cacheStateValue).toBe(cacheMatchedKey);
|
expect(cacheStateValue).toBe(cacheMatchedKey);
|
||||||
expect(getStateMock).toHaveBeenCalledTimes(2);
|
expect(core.getState).toHaveBeenCalledTimes(2);
|
||||||
expect(saveStateMock).toHaveBeenCalledTimes(2);
|
expect(core.saveState).toHaveBeenCalledTimes(2);
|
||||||
expect(setOutputMock).toHaveBeenCalledTimes(0);
|
expect(core.setOutput).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("NullStateProvider saves outputs", async () => {
|
test("NullStateProvider saves outputs", async () => {
|
||||||
const getStateMock = jest
|
|
||||||
.spyOn(core, "getState")
|
|
||||||
.mockImplementation(name =>
|
|
||||||
jest.requireActual("@actions/core").getState(name)
|
|
||||||
);
|
|
||||||
|
|
||||||
const setOutputMock = jest
|
|
||||||
.spyOn(core, "setOutput")
|
|
||||||
.mockImplementation((key, value) => {
|
|
||||||
return jest.requireActual("@actions/core").setOutput(key, value);
|
|
||||||
});
|
|
||||||
|
|
||||||
const saveStateMock = jest
|
|
||||||
.spyOn(core, "saveState")
|
|
||||||
.mockImplementation((key, value) => {
|
|
||||||
return jest.requireActual("@actions/core").saveState(key, value);
|
|
||||||
});
|
|
||||||
|
|
||||||
const cacheMatchedKey = "node-cache";
|
|
||||||
const nullStateProvider: IStateProvider = new NullStateProvider();
|
const nullStateProvider: IStateProvider = new NullStateProvider();
|
||||||
nullStateProvider.setState(State.CacheMatchedKey, "outputValue");
|
nullStateProvider.setState(State.CacheMatchedKey, "outputValue");
|
||||||
nullStateProvider.setState(State.CachePrimaryKey, cacheMatchedKey);
|
nullStateProvider.setState(State.CachePrimaryKey, "node-cache");
|
||||||
nullStateProvider.getState("outputKey");
|
nullStateProvider.getState("outputKey");
|
||||||
nullStateProvider.getCacheState();
|
nullStateProvider.getCacheState();
|
||||||
|
|
||||||
expect(getStateMock).toHaveBeenCalledTimes(0);
|
expect(core.getState).toHaveBeenCalledTimes(0);
|
||||||
expect(setOutputMock).toHaveBeenCalledTimes(2);
|
expect(core.setOutput).toHaveBeenCalledTimes(2);
|
||||||
expect(saveStateMock).toHaveBeenCalledTimes(0);
|
expect(core.saveState).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|||||||
+1
-1
@@ -38,7 +38,7 @@ 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: 'node20'
|
using: 'node24'
|
||||||
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()"
|
||||||
|
|||||||
+21
-21
@@ -12,7 +12,7 @@ This document lists some of the strategies (and example workflows if possible) w
|
|||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
key: ${{ some-metadata }}-cache
|
key: ${{ some-metadata }}-cache
|
||||||
```
|
```
|
||||||
@@ -24,7 +24,7 @@ In your workflows, you can use different strategies to name your key depending o
|
|||||||
One of the most common use case is to use hash for lockfile as key. This way, same cache will be restored for a lockfile until there's a change in dependencies listed in lockfile.
|
One of the most common use case is to use hash for lockfile as key. This way, same cache will be restored for a lockfile until there's a change in dependencies listed in lockfile.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
path/to/dependencies
|
path/to/dependencies
|
||||||
@@ -37,7 +37,7 @@ One of the most common use case is to use hash for lockfile as key. This way, sa
|
|||||||
If cache is not found matching the primary key, restore keys can be used to download the closest matching cache that was recently created. This ensures that the build/install step will need to additionally fetch just a handful of newer dependencies, and hence saving build time.
|
If cache is not found matching the primary key, restore keys can be used to download the closest matching cache that was recently created. This ensures that the build/install step will need to additionally fetch just a handful of newer dependencies, and hence saving build time.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
path/to/dependencies
|
path/to/dependencies
|
||||||
@@ -54,7 +54,7 @@ The restore keys can be provided as a complete name, or a prefix, read more [her
|
|||||||
In case of workflows with matrix running for multiple Operating Systems, the caches can be stored separately for each of them. This can be used in combination with hashfiles in case multiple caches are being generated per OS.
|
In case of workflows with matrix running for multiple Operating Systems, the caches can be stored separately for each of them. This can be used in combination with hashfiles in case multiple caches are being generated per OS.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
path/to/dependencies
|
path/to/dependencies
|
||||||
@@ -73,7 +73,7 @@ Caches scoped to the particular workflow run id or run attempt can be stored and
|
|||||||
On similar lines, commit sha can be used to create a very specialized and short lived cache.
|
On similar lines, commit sha can be used to create a very specialized and short lived cache.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
path/to/dependencies
|
path/to/dependencies
|
||||||
@@ -86,7 +86,7 @@ On similar lines, commit sha can be used to create a very specialized and short
|
|||||||
Cache key can be formed by combination of more than one metadata, evaluated info.
|
Cache key can be formed by combination of more than one metadata, evaluated info.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
path/to/dependencies
|
path/to/dependencies
|
||||||
@@ -102,7 +102,7 @@ The [GitHub Context](https://docs.github.com/en/actions/learn-github-actions/con
|
|||||||
|
|
||||||
While setting paths for caching dependencies it is important to give correct path depending on the hosted runner you are using or whether the action is running in a container job. Assigning different `path` for save and restore will result in cache miss.
|
While setting paths for caching dependencies it is important to give correct path depending on the hosted runner you are using or whether the action is running in a container job. Assigning different `path` for save and restore will result in cache miss.
|
||||||
|
|
||||||
Below are GiHub hosted runner specific paths one should take care of when writing a workflow which saves/restores caches across OS.
|
Below are GitHub hosted runner specific paths one should take care of when writing a workflow which saves/restores caches across OS.
|
||||||
|
|
||||||
#### Ubuntu Paths
|
#### Ubuntu Paths
|
||||||
|
|
||||||
@@ -146,9 +146,9 @@ In case you are using a centralized job to create and save your cache that can b
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
- uses: actions/cache/restore@v4
|
- uses: actions/cache/restore@v6
|
||||||
id: cache
|
id: cache
|
||||||
with:
|
with:
|
||||||
path: path/to/dependencies
|
path: path/to/dependencies
|
||||||
@@ -171,9 +171,9 @@ You can use the output of this action to exit the workflow on cache miss. This w
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
- uses: actions/cache/restore@v4
|
- uses: actions/cache/restore@v6
|
||||||
id: cache
|
id: cache
|
||||||
with:
|
with:
|
||||||
path: path/to/dependencies
|
path: path/to/dependencies
|
||||||
@@ -194,7 +194,7 @@ steps:
|
|||||||
If you want to avoid re-computing the cache key again in `save` action, the outputs from `restore` action can be used as input to the `save` action.
|
If you want to avoid re-computing the cache key again in `save` action, the outputs from `restore` action can be used as input to the `save` action.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/cache/restore@v4
|
- uses: actions/cache/restore@v6
|
||||||
id: restore-cache
|
id: restore-cache
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
@@ -204,7 +204,7 @@ If you want to avoid re-computing the cache key again in `save` action, the outp
|
|||||||
.
|
.
|
||||||
.
|
.
|
||||||
.
|
.
|
||||||
- uses: actions/cache/save@v4
|
- uses: actions/cache/save@v6
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
path/to/dependencies
|
path/to/dependencies
|
||||||
@@ -219,7 +219,7 @@ On the other hand, the key can also be explicitly re-computed while executing th
|
|||||||
Let's say we have a restore step that computes key at runtime
|
Let's say we have a restore step that computes key at runtime
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
uses: actions/cache/restore@v4
|
uses: actions/cache/restore@v6
|
||||||
id: restore-cache
|
id: restore-cache
|
||||||
with:
|
with:
|
||||||
key: cache-${{ hashFiles('**/lockfiles') }}
|
key: cache-${{ hashFiles('**/lockfiles') }}
|
||||||
@@ -228,7 +228,7 @@ with:
|
|||||||
Case 1: Where an user would want to reuse the key as it is
|
Case 1: Where an user would want to reuse the key as it is
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
uses: actions/cache/save@v4
|
uses: actions/cache/save@v6
|
||||||
with:
|
with:
|
||||||
key: ${{ steps.restore-cache.outputs.cache-primary-key }}
|
key: ${{ steps.restore-cache.outputs.cache-primary-key }}
|
||||||
```
|
```
|
||||||
@@ -236,7 +236,7 @@ with:
|
|||||||
Case 2: Where the user would want to re-evaluate the key
|
Case 2: Where the user would want to re-evaluate the key
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
uses: actions/cache/save@v4
|
uses: actions/cache/save@v6
|
||||||
with:
|
with:
|
||||||
key: npm-cache-${{hashfiles(package-lock.json)}}
|
key: npm-cache-${{hashfiles(package-lock.json)}}
|
||||||
```
|
```
|
||||||
@@ -253,12 +253,12 @@ In case of multi-module projects, where the built artifact of one project needs
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: ./build-parent-module.sh
|
run: ./build-parent-module.sh
|
||||||
|
|
||||||
- uses: actions/cache/save@v4
|
- uses: actions/cache/save@v6
|
||||||
id: cache
|
id: cache
|
||||||
with:
|
with:
|
||||||
path: path/to/dependencies
|
path: path/to/dependencies
|
||||||
@@ -269,9 +269,9 @@ steps:
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
- uses: actions/cache/restore@v4
|
- uses: actions/cache/restore@v6
|
||||||
id: cache
|
id: cache
|
||||||
with:
|
with:
|
||||||
path: path/to/dependencies
|
path: path/to/dependencies
|
||||||
@@ -280,7 +280,7 @@ steps:
|
|||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
if: steps.cache.outputs.cache-hit != 'true'
|
if: steps.cache.outputs.cache-hit != 'true'
|
||||||
run: ./install.sh
|
run: ./install.sh
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: ./build-child-module.sh
|
run: ./build-child-module.sh
|
||||||
|
|
||||||
|
|||||||
Vendored
+79983
-50723
File diff suppressed because one or more lines are too long
Vendored
+3
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"type": "module"
|
||||||
|
}
|
||||||
Vendored
+79985
-50725
File diff suppressed because one or more lines are too long
Vendored
+3
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"type": "module"
|
||||||
|
}
|
||||||
Vendored
+79998
-50731
File diff suppressed because one or more lines are too long
Vendored
+3
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"type": "module"
|
||||||
|
}
|
||||||
Vendored
+80000
-50733
File diff suppressed because one or more lines are too long
Vendored
+3
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"type": "module"
|
||||||
|
}
|
||||||
+67
-46
@@ -1,5 +1,6 @@
|
|||||||
# Examples
|
# Examples
|
||||||
|
|
||||||
|
- [Bun](#bun)
|
||||||
- [C# - NuGet](#c---nuget)
|
- [C# - NuGet](#c---nuget)
|
||||||
- [Clojure - Lein Deps](#clojure---lein-deps)
|
- [Clojure - Lein Deps](#clojure---lein-deps)
|
||||||
- [D - DUB](#d---dub)
|
- [D - DUB](#d---dub)
|
||||||
@@ -41,12 +42,32 @@
|
|||||||
- [Swift - Mint](#swift---mint)
|
- [Swift - Mint](#swift---mint)
|
||||||
- [* - Bazel](#---bazel)
|
- [* - Bazel](#---bazel)
|
||||||
|
|
||||||
|
## Bun
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: actions/cache@v6
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.bun/install/cache
|
||||||
|
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lock') }}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Windows
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: actions/cache@v6
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~\.bun
|
||||||
|
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lock') }}
|
||||||
|
```
|
||||||
|
|
||||||
## 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
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: ~/.nuget/packages
|
path: ~/.nuget/packages
|
||||||
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
|
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
|
||||||
@@ -55,10 +76,10 @@ 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.
|
||||||
With `actions/cache@v4` you can now exclude unwanted packages with [exclude pattern](https://github.com/actions/toolkit/tree/main/packages/glob#exclude-patterns)
|
From `actions/cache@v3` onwards, you can now exclude unwanted packages with [exclude pattern](https://github.com/actions/toolkit/tree/main/packages/glob#exclude-patterns)
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
~/.nuget/packages
|
~/.nuget/packages
|
||||||
@@ -75,7 +96,7 @@ Or you could move the cache folder like below.
|
|||||||
env:
|
env:
|
||||||
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
|
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: ${{ github.workspace }}/.nuget/packages
|
path: ${{ github.workspace }}/.nuget/packages
|
||||||
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
|
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
|
||||||
@@ -87,7 +108,7 @@ steps:
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Cache lein project dependencies
|
- name: Cache lein project dependencies
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: ~/.m2/repository
|
path: ~/.m2/repository
|
||||||
key: ${{ runner.os }}-clojure-${{ hashFiles('**/project.clj') }}
|
key: ${{ runner.os }}-clojure-${{ hashFiles('**/project.clj') }}
|
||||||
@@ -101,7 +122,7 @@ steps:
|
|||||||
### POSIX
|
### POSIX
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: ~/.dub
|
path: ~/.dub
|
||||||
key: ${{ runner.os }}-dub-${{ hashFiles('**/dub.selections.json') }}
|
key: ${{ runner.os }}-dub-${{ hashFiles('**/dub.selections.json') }}
|
||||||
@@ -112,7 +133,7 @@ steps:
|
|||||||
### Windows
|
### Windows
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: ~\AppData\Local\dub
|
path: ~\AppData\Local\dub
|
||||||
key: ${{ runner.os }}-dub-${{ hashFiles('**/dub.selections.json') }}
|
key: ${{ runner.os }}-dub-${{ hashFiles('**/dub.selections.json') }}
|
||||||
@@ -125,7 +146,7 @@ steps:
|
|||||||
### Linux
|
### Linux
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
~/.deno
|
~/.deno
|
||||||
@@ -136,7 +157,7 @@ steps:
|
|||||||
### macOS
|
### macOS
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
~/.deno
|
~/.deno
|
||||||
@@ -147,7 +168,7 @@ steps:
|
|||||||
### Windows
|
### Windows
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
~\.deno
|
~\.deno
|
||||||
@@ -158,7 +179,7 @@ steps:
|
|||||||
## Elixir - Mix
|
## Elixir - Mix
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
deps
|
deps
|
||||||
@@ -170,7 +191,7 @@ steps:
|
|||||||
|
|
||||||
## Erlang - Rebar3
|
## Erlang - Rebar3
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/cache@v2
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
~/.cache/rebar3
|
~/.cache/rebar3
|
||||||
@@ -185,7 +206,7 @@ steps:
|
|||||||
### Linux
|
### Linux
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
~/.cache/go-build
|
~/.cache/go-build
|
||||||
@@ -198,7 +219,7 @@ steps:
|
|||||||
### macOS
|
### macOS
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
~/Library/Caches/go-build
|
~/Library/Caches/go-build
|
||||||
@@ -211,7 +232,7 @@ steps:
|
|||||||
### Windows
|
### Windows
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
~\AppData\Local\go-build
|
~\AppData\Local\go-build
|
||||||
@@ -227,7 +248,7 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Cache ~/.cabal/packages, ~/.cabal/store and dist-newstyle
|
- name: Cache ~/.cabal/packages, ~/.cabal/store and dist-newstyle
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
~/.cabal/packages
|
~/.cabal/packages
|
||||||
@@ -242,14 +263,14 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
|
|||||||
### Linux or macOS
|
### Linux or macOS
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
name: Cache ~/.stack
|
name: Cache ~/.stack
|
||||||
with:
|
with:
|
||||||
path: ~/.stack
|
path: ~/.stack
|
||||||
key: ${{ runner.os }}-stack-global-${{ hashFiles('stack.yaml') }}-${{ hashFiles('package.yaml') }}
|
key: ${{ runner.os }}-stack-global-${{ hashFiles('stack.yaml') }}-${{ hashFiles('package.yaml') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-stack-global-
|
${{ runner.os }}-stack-global-
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
name: Cache .stack-work
|
name: Cache .stack-work
|
||||||
with:
|
with:
|
||||||
path: .stack-work
|
path: .stack-work
|
||||||
@@ -261,16 +282,16 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
|
|||||||
### Windows
|
### Windows
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
name: Cache %APPDATA%\stack %LOCALAPPDATA%\Programs\stack
|
name: Cache %APPDATA%\stack %LOCALAPPDATA%\Programs\stack
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
~\AppData\Roaming\stack
|
~\AppData\Roaming\stack
|
||||||
~\AppData\Local\Programs\stack
|
~\AppData\Local\Programs\stack
|
||||||
key: ${{ runner.os }}-stack-global-${{ hashFiles('stack.yaml') }}-${{ hashFiles('package.yaml') }}
|
key: ${{ runner.os }}-stack-global-${{ hashFiles('stack.yaml') }}-${{ hashFiles('package.yaml') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-stack-global-
|
${{ runner.os }}-stack-global-
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
name: Cache .stack-work
|
name: Cache .stack-work
|
||||||
with:
|
with:
|
||||||
path: .stack-work
|
path: .stack-work
|
||||||
@@ -284,7 +305,7 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
|
|||||||
> **Note** Ensure no Gradle daemons are running anymore when your workflow completes. Creating the cache package might fail due to locks being held by Gradle. Refer to the [Gradle Daemon documentation](https://docs.gradle.org/current/userguide/gradle_daemon.html) on how to disable or stop the Gradle Daemons.
|
> **Note** Ensure no Gradle daemons are running anymore when your workflow completes. Creating the cache package might fail due to locks being held by Gradle. Refer to the [Gradle Daemon documentation](https://docs.gradle.org/current/userguide/gradle_daemon.html) on how to disable or stop the Gradle Daemons.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
~/.gradle/caches
|
~/.gradle/caches
|
||||||
@@ -298,7 +319,7 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Cache local Maven repository
|
- name: Cache local Maven repository
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: ~/.m2/repository
|
path: ~/.m2/repository
|
||||||
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
|
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
|
||||||
@@ -334,7 +355,7 @@ After [deprecation](https://github.blog/changelog/2022-10-11-github-actions-depr
|
|||||||
`Get npm cache directory` step can then be used with `actions/cache` as shown below
|
`Get npm cache directory` step can then be used with `actions/cache` as shown below
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
|
id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
|
||||||
with:
|
with:
|
||||||
path: ${{ steps.npm-cache-dir.outputs.dir }}
|
path: ${{ steps.npm-cache-dir.outputs.dir }}
|
||||||
@@ -347,7 +368,7 @@ After [deprecation](https://github.blog/changelog/2022-10-11-github-actions-depr
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: restore lerna
|
- name: restore lerna
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: '**/node_modules'
|
path: '**/node_modules'
|
||||||
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}
|
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}
|
||||||
@@ -361,7 +382,7 @@ The yarn cache directory will depend on your operating system and version of `ya
|
|||||||
id: yarn-cache-dir-path
|
id: yarn-cache-dir-path
|
||||||
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
|
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
|
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
|
||||||
with:
|
with:
|
||||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
||||||
@@ -379,7 +400,7 @@ The yarn 2 cache directory will depend on your config. See https://yarnpkg.com/c
|
|||||||
id: yarn-cache-dir-path
|
id: yarn-cache-dir-path
|
||||||
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
|
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
|
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
|
||||||
with:
|
with:
|
||||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
||||||
@@ -394,7 +415,7 @@ 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
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: _export
|
path: _export
|
||||||
key: ${{ runner.os }}-esy-${{ hashFiles('esy.lock/index.json') }}
|
key: ${{ runner.os }}-esy-${{ hashFiles('esy.lock/index.json') }}
|
||||||
@@ -423,7 +444,7 @@ Esy allows you to export built dependencies and import pre-built dependencies.
|
|||||||
id: composer-cache
|
id: composer-cache
|
||||||
run: |
|
run: |
|
||||||
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
|
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: ${{ steps.composer-cache.outputs.dir }}
|
path: ${{ steps.composer-cache.outputs.dir }}
|
||||||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
|
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
|
||||||
@@ -444,7 +465,7 @@ Locations:
|
|||||||
### Simple example
|
### Simple example
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: ~/.cache/pip
|
path: ~/.cache/pip
|
||||||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
|
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
|
||||||
@@ -457,7 +478,7 @@ Replace `~/.cache/pip` with the correct `path` if not using Ubuntu.
|
|||||||
### Multiple OS's in a workflow
|
### Multiple OS's in a workflow
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
if: startsWith(runner.os, 'Linux')
|
if: startsWith(runner.os, 'Linux')
|
||||||
with:
|
with:
|
||||||
path: ~/.cache/pip
|
path: ~/.cache/pip
|
||||||
@@ -465,7 +486,7 @@ Replace `~/.cache/pip` with the correct `path` if not using Ubuntu.
|
|||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-pip-
|
${{ runner.os }}-pip-
|
||||||
|
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
if: startsWith(runner.os, 'macOS')
|
if: startsWith(runner.os, 'macOS')
|
||||||
with:
|
with:
|
||||||
path: ~/Library/Caches/pip
|
path: ~/Library/Caches/pip
|
||||||
@@ -473,7 +494,7 @@ Replace `~/.cache/pip` with the correct `path` if not using Ubuntu.
|
|||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-pip-
|
${{ runner.os }}-pip-
|
||||||
|
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
if: startsWith(runner.os, 'Windows')
|
if: startsWith(runner.os, 'Windows')
|
||||||
with:
|
with:
|
||||||
path: ~\AppData\Local\pip\Cache
|
path: ~\AppData\Local\pip\Cache
|
||||||
@@ -499,7 +520,7 @@ jobs:
|
|||||||
- os: windows-latest
|
- os: windows-latest
|
||||||
path: ~\AppData\Local\pip\Cache
|
path: ~\AppData\Local\pip\Cache
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: ${{ matrix.path }}
|
path: ${{ matrix.path }}
|
||||||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
|
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
|
||||||
@@ -518,7 +539,7 @@ jobs:
|
|||||||
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
|
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: pip cache
|
- name: pip cache
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: ${{ steps.pip-cache.outputs.dir }}
|
path: ${{ steps.pip-cache.outputs.dir }}
|
||||||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
|
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
|
||||||
@@ -532,11 +553,11 @@ jobs:
|
|||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
# The actions/cache step below uses this id to get the exact python version
|
# The actions/cache step below uses this id to get the exact python version
|
||||||
id: setup-python
|
id: setup-python
|
||||||
uses: actions/setup-python@v2
|
uses: actions/setup-python@v6
|
||||||
|
|
||||||
⋮
|
⋮
|
||||||
|
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: ~/.local/share/virtualenvs
|
path: ~/.local/share/virtualenvs
|
||||||
key: ${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-pipenv-${{ hashFiles('Pipfile.lock') }}
|
key: ${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-pipenv-${{ hashFiles('Pipfile.lock') }}
|
||||||
@@ -563,7 +584,7 @@ For renv, the cache directory will vary by OS. The `RENV_PATHS_ROOT` environment
|
|||||||
cat("##[set-output name=r-version;]", R.Version()$version.string, sep = "")
|
cat("##[set-output name=r-version;]", R.Version()$version.string, sep = "")
|
||||||
shell: Rscript {0}
|
shell: Rscript {0}
|
||||||
- name: Restore Renv package cache
|
- name: Restore Renv package cache
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: ${{ env.RENV_PATHS_ROOT }}
|
path: ${{ env.RENV_PATHS_ROOT }}
|
||||||
key: ${{ steps.get-version.outputs.os-version }}-${{ steps.get-version.outputs.r-version }}-${{ inputs.cache-version }}-${{ hashFiles('renv.lock') }}
|
key: ${{ steps.get-version.outputs.os-version }}-${{ steps.get-version.outputs.r-version }}-${{ inputs.cache-version }}-${{ hashFiles('renv.lock') }}
|
||||||
@@ -589,7 +610,7 @@ whenever possible:
|
|||||||
## Rust - Cargo
|
## Rust - Cargo
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
~/.cargo/bin/
|
~/.cargo/bin/
|
||||||
@@ -604,7 +625,7 @@ whenever possible:
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Cache SBT
|
- name: Cache SBT
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
~/.ivy2/cache
|
~/.ivy2/cache
|
||||||
@@ -615,7 +636,7 @@ whenever possible:
|
|||||||
## Swift, Objective-C - Carthage
|
## Swift, Objective-C - Carthage
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: Carthage
|
path: Carthage
|
||||||
key: ${{ runner.os }}-carthage-${{ hashFiles('**/Cartfile.resolved') }}
|
key: ${{ runner.os }}-carthage-${{ hashFiles('**/Cartfile.resolved') }}
|
||||||
@@ -626,7 +647,7 @@ whenever possible:
|
|||||||
## Swift, Objective-C - CocoaPods
|
## Swift, Objective-C - CocoaPods
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: Pods
|
path: Pods
|
||||||
key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }}
|
key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }}
|
||||||
@@ -637,7 +658,7 @@ whenever possible:
|
|||||||
## Swift - Swift Package Manager
|
## Swift - Swift Package Manager
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: .build
|
path: .build
|
||||||
key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
|
key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
|
||||||
@@ -652,7 +673,7 @@ env:
|
|||||||
MINT_PATH: .mint/lib
|
MINT_PATH: .mint/lib
|
||||||
MINT_LINK_PATH: .mint/bin
|
MINT_LINK_PATH: .mint/bin
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: .mint
|
path: .mint
|
||||||
key: ${{ runner.os }}-mint-${{ hashFiles('**/Mintfile') }}
|
key: ${{ runner.os }}-mint-${{ hashFiles('**/Mintfile') }}
|
||||||
@@ -668,7 +689,7 @@ steps:
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Cache Bazel
|
- name: Cache Bazel
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
~/.cache/bazel
|
~/.cache/bazel
|
||||||
@@ -682,7 +703,7 @@ steps:
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Cache Bazel
|
- name: Cache Bazel
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
/private/var/tmp/_bazel_runner/
|
/private/var/tmp/_bazel_runner/
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
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
|
|
||||||
};
|
|
||||||
|
|
||||||
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 (!String(str).match(/^::/)) {
|
|
||||||
return processStdoutWrite(str, encoding, cb);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
export default {
|
||||||
|
clearMocks: true,
|
||||||
|
moduleFileExtensions: ["js", "ts"],
|
||||||
|
roots: ["<rootDir>/__tests__"],
|
||||||
|
testEnvironment: "node",
|
||||||
|
testMatch: ["**/*.test.ts"],
|
||||||
|
transform: {
|
||||||
|
"^.+\\.ts$": [
|
||||||
|
"ts-jest",
|
||||||
|
{
|
||||||
|
useESM: true,
|
||||||
|
diagnostics: {
|
||||||
|
ignoreCodes: [151002]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
extensionsToTreatAsEsm: [".ts"],
|
||||||
|
transformIgnorePatterns: ["node_modules/(?!(@actions)/)"],
|
||||||
|
verbose: true
|
||||||
|
};
|
||||||
Generated
+5600
-13733
File diff suppressed because it is too large
Load Diff
+26
-22
@@ -1,12 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "cache",
|
"name": "cache",
|
||||||
"version": "4.1.1",
|
"version": "6.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Cache dependencies and build outputs",
|
"description": "Cache dependencies and build outputs",
|
||||||
|
"type": "module",
|
||||||
"main": "dist/restore/index.js",
|
"main": "dist/restore/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc && ncc build -o dist/restore src/restore.ts && ncc build -o dist/save src/save.ts && ncc build -o dist/restore-only src/restoreOnly.ts && ncc build -o dist/save-only src/saveOnly.ts",
|
"build": "tsc && ncc build -o dist/restore src/restore.ts && ncc build -o dist/save src/save.ts && ncc build -o dist/restore-only src/restoreOnly.ts && ncc build -o dist/save-only src/saveOnly.ts",
|
||||||
"test": "tsc --noEmit && jest --coverage",
|
"test": "tsc --noEmit && node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage",
|
||||||
"lint": "eslint **/*.ts --cache",
|
"lint": "eslint **/*.ts --cache",
|
||||||
"format": "prettier --write **/*.ts",
|
"format": "prettier --write **/*.ts",
|
||||||
"format-check": "prettier --check **/*.ts"
|
"format-check": "prettier --check **/*.ts"
|
||||||
@@ -23,29 +24,32 @@
|
|||||||
"author": "GitHub",
|
"author": "GitHub",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/cache": "^3.2.3",
|
"@actions/cache": "^6.0.1",
|
||||||
"@actions/core": "^1.10.0",
|
"@actions/core": "^3.0.1",
|
||||||
"@actions/exec": "^1.1.1",
|
"@actions/exec": "^3.0.0",
|
||||||
"@actions/io": "^1.1.2"
|
"@actions/io": "^3.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^27.5.2",
|
"@types/jest": "^30.0.0",
|
||||||
"@types/nock": "^11.1.0",
|
"@types/nock": "^11.1.0",
|
||||||
"@types/node": "^16.18.3",
|
"@types/node": "^24.1.0",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.45.0",
|
"@typescript-eslint/eslint-plugin": "^7.2.0",
|
||||||
"@typescript-eslint/parser": "^5.45.0",
|
"@typescript-eslint/parser": "^7.2.0",
|
||||||
"@vercel/ncc": "^0.38.1",
|
"@vercel/ncc": "^0.38.3",
|
||||||
"eslint": "^8.28.0",
|
"eslint": "^8.28.0",
|
||||||
"eslint-config-prettier": "^8.5.0",
|
"eslint-config-prettier": "^9.1.2",
|
||||||
"eslint-plugin-import": "^2.26.0",
|
"eslint-plugin-import": "^2.32.0",
|
||||||
"eslint-plugin-jest": "^26.9.0",
|
"eslint-plugin-jest": "^27.9.0",
|
||||||
"eslint-plugin-prettier": "^4.2.1",
|
"eslint-plugin-prettier": "^5.5.3",
|
||||||
"eslint-plugin-simple-import-sort": "^7.0.0",
|
"eslint-plugin-simple-import-sort": "^12.1.1",
|
||||||
"jest": "^28.1.3",
|
"jest": "^30.2.0",
|
||||||
"jest-circus": "^27.5.1",
|
|
||||||
"nock": "^13.2.9",
|
"nock": "^13.2.9",
|
||||||
"prettier": "^2.8.0",
|
"prettier": "^3.6.2",
|
||||||
"ts-jest": "^28.0.8",
|
"ts-jest": "^29.4.0",
|
||||||
"typescript": "^4.9.3"
|
"ts-node": "^10.9.2",
|
||||||
|
"typescript": "^5.8.3"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=24"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+8
-8
@@ -35,9 +35,9 @@ If you are using separate jobs to create and save your cache(s) to be reused by
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
- uses: actions/cache/restore@v4
|
- uses: actions/cache/restore@v5
|
||||||
id: cache
|
id: cache
|
||||||
with:
|
with:
|
||||||
path: path/to/dependencies
|
path: path/to/dependencies
|
||||||
@@ -64,12 +64,12 @@ In case of multi-module projects, where the built artifact of one project needs
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: /build-parent-module.sh
|
run: /build-parent-module.sh
|
||||||
|
|
||||||
- uses: actions/cache/save@v4
|
- uses: actions/cache/save@v5
|
||||||
id: cache
|
id: cache
|
||||||
with:
|
with:
|
||||||
path: path/to/dependencies
|
path: path/to/dependencies
|
||||||
@@ -80,9 +80,9 @@ steps:
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
- uses: actions/cache/restore@v4
|
- uses: actions/cache/restore@v5
|
||||||
id: cache
|
id: cache
|
||||||
with:
|
with:
|
||||||
path: path/to/dependencies
|
path: path/to/dependencies
|
||||||
@@ -107,9 +107,9 @@ To fail if there is no cache hit for the primary key, leave `restore-keys` empty
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
- uses: actions/cache/restore@v4
|
- uses: actions/cache/restore@v5
|
||||||
id: cache
|
id: cache
|
||||||
with:
|
with:
|
||||||
path: path/to/dependencies
|
path: path/to/dependencies
|
||||||
|
|||||||
+1
-1
@@ -31,7 +31,7 @@ outputs:
|
|||||||
cache-matched-key:
|
cache-matched-key:
|
||||||
description: 'Key of the cache that was restored, it could either be the primary key on cache-hit or a partial/complete match of one of the restore keys'
|
description: 'Key of the cache that was restored, it could either be the primary key on cache-hit or a partial/complete match of one of the restore keys'
|
||||||
runs:
|
runs:
|
||||||
using: 'node20'
|
using: 'node24'
|
||||||
main: '../dist/restore-only/index.js'
|
main: '../dist/restore-only/index.js'
|
||||||
branding:
|
branding:
|
||||||
icon: 'archive'
|
icon: 'archive'
|
||||||
|
|||||||
+18
-16
@@ -23,7 +23,7 @@ If you are using separate jobs for generating common artifacts and sharing them
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: /install.sh
|
run: /install.sh
|
||||||
@@ -31,7 +31,7 @@ steps:
|
|||||||
- name: Build artifacts
|
- name: Build artifacts
|
||||||
run: /build.sh
|
run: /build.sh
|
||||||
|
|
||||||
- uses: actions/cache/save@v4
|
- uses: actions/cache/save@v5
|
||||||
id: cache
|
id: cache
|
||||||
with:
|
with:
|
||||||
path: path/to/dependencies
|
path: path/to/dependencies
|
||||||
@@ -47,7 +47,7 @@ Let's say we have a restore step that computes a key at runtime.
|
|||||||
#### Restore a cache
|
#### Restore a cache
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
uses: actions/cache/restore@v4
|
uses: actions/cache/restore@v5
|
||||||
id: restore-cache
|
id: restore-cache
|
||||||
with:
|
with:
|
||||||
key: cache-${{ hashFiles('**/lockfiles') }}
|
key: cache-${{ hashFiles('**/lockfiles') }}
|
||||||
@@ -55,7 +55,7 @@ with:
|
|||||||
|
|
||||||
#### Case 1 - Where a user would want to reuse the key as it is
|
#### Case 1 - Where a user would want to reuse the key as it is
|
||||||
```yaml
|
```yaml
|
||||||
uses: actions/cache/save@v4
|
uses: actions/cache/save@v5
|
||||||
with:
|
with:
|
||||||
key: ${{ steps.restore-cache.outputs.cache-primary-key }}
|
key: ${{ steps.restore-cache.outputs.cache-primary-key }}
|
||||||
```
|
```
|
||||||
@@ -63,7 +63,7 @@ with:
|
|||||||
#### Case 2 - Where the user would want to re-evaluate the key
|
#### Case 2 - Where the user would want to re-evaluate the key
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
uses: actions/cache/save@v4
|
uses: actions/cache/save@v5
|
||||||
with:
|
with:
|
||||||
key: npm-cache-${{hashfiles(package-lock.json)}}
|
key: npm-cache-${{hashfiles(package-lock.json)}}
|
||||||
```
|
```
|
||||||
@@ -79,8 +79,10 @@ To avoid saving a cache that already exists, the `cache-hit` output from a resto
|
|||||||
The `cache-primary-key` output from the restore step should also be used to ensure
|
The `cache-primary-key` output from the restore step should also be used to ensure
|
||||||
the cache key does not change during the build if it's calculated based on file contents.
|
the cache key does not change during the build if it's calculated based on file contents.
|
||||||
|
|
||||||
|
Here's an example where we imagine we're calculating a lot of prime numbers and want to cache them:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
name: Always Caching Primes
|
name: Always Caching Prime Numbers
|
||||||
|
|
||||||
on: push
|
on: push
|
||||||
|
|
||||||
@@ -89,25 +91,25 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
- name: Restore cached Primes
|
- name: Restore cached Prime Numbers
|
||||||
id: cache-primes-restore
|
id: cache-prime-numbers-restore
|
||||||
uses: actions/cache/restore@v4
|
uses: actions/cache/restore@v5
|
||||||
with:
|
with:
|
||||||
key: ${{ runner.os }}-primes
|
key: ${{ runner.os }}-prime-numbers
|
||||||
path: |
|
path: |
|
||||||
path/to/dependencies
|
path/to/dependencies
|
||||||
some/other/dependencies
|
some/other/dependencies
|
||||||
|
|
||||||
# Intermediate workflow steps
|
# Intermediate workflow steps
|
||||||
|
|
||||||
- name: Always Save Primes
|
- name: Always Save Prime Numbers
|
||||||
id: cache-primes-save
|
id: cache-prime-numbers-save
|
||||||
if: always() && steps.cache-primes-restore.outputs.cache-hit != 'true'
|
if: always() && steps.cache-prime-numbers-restore.outputs.cache-hit != 'true'
|
||||||
uses: actions/cache/save@v4
|
uses: actions/cache/save@v5
|
||||||
with:
|
with:
|
||||||
key: ${{ steps.cache-primes-restore.outputs.cache-primary-key }}
|
key: ${{ steps.cache-prime-numbers-restore.outputs.cache-primary-key }}
|
||||||
path: |
|
path: |
|
||||||
path/to/dependencies
|
path/to/dependencies
|
||||||
some/other/dependencies
|
some/other/dependencies
|
||||||
|
|||||||
+1
-1
@@ -16,7 +16,7 @@ inputs:
|
|||||||
default: 'false'
|
default: 'false'
|
||||||
required: false
|
required: false
|
||||||
runs:
|
runs:
|
||||||
using: 'node20'
|
using: 'node24'
|
||||||
main: '../dist/save-only/index.js'
|
main: '../dist/save-only/index.js'
|
||||||
branding:
|
branding:
|
||||||
icon: 'archive'
|
icon: 'archive'
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user