mirror of
https://github.com/actions/cache.git
synced 2026-03-04 08:31:03 +08:00
Compare commits
11 Commits
167def4ffc
...
23a08d8e80
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
23a08d8e80 | ||
|
|
b7e8d49f17 | ||
|
|
984a21b1cb | ||
|
|
acf2f1f76a | ||
|
|
95a07c5132 | ||
|
|
90e4fae240 | ||
|
|
783accdc1c | ||
|
|
6905c11681 | ||
|
|
c5c1c31345 | ||
|
|
91afe36e0a | ||
|
|
480d890516 |
146
.github/workflows/workflow.yml
vendored
146
.github/workflows/workflow.yml
vendored
@ -90,15 +90,86 @@ 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@v5
|
uses: actions/checkout@v5
|
||||||
- name: Generate files
|
- name: Generate files
|
||||||
@ -114,15 +185,86 @@ 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@v5
|
uses: actions/checkout@v5
|
||||||
- name: Restore cache
|
- name: Restore cache
|
||||||
|
|||||||
@ -100,6 +100,8 @@ If you are using a `self-hosted` Windows runner, `GNU tar` and `zstd` are requir
|
|||||||
* `cache-hit` - A string value to indicate an exact match was found for the key.
|
* `cache-hit` - A string value to indicate an exact match was found for the key.
|
||||||
* If there's a cache hit, this will be 'true' or 'false' to indicate if there's an exact match for `key`.
|
* If there's a cache hit, this will be 'true' or 'false' to indicate if there's an exact match for `key`.
|
||||||
* If there's a cache miss, this will be an empty string.
|
* If there's a cache miss, this will be an empty string.
|
||||||
|
* `cache-primary-key` - Cache primary key passed in the input to use in subsequent steps of the workflow.
|
||||||
|
* `cache-matched-key` - 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.
|
||||||
|
|
||||||
See [Skipping steps based on cache-hit](#skipping-steps-based-on-cache-hit) for info on using this output
|
See [Skipping steps based on cache-hit](#skipping-steps-based-on-cache-hit) for info on using this output
|
||||||
|
|
||||||
|
|||||||
@ -149,7 +149,7 @@ test("restore with cache found for key", async () => {
|
|||||||
const infoMock = jest.spyOn(core, "info");
|
const infoMock = jest.spyOn(core, "info");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
const stateMock = jest.spyOn(core, "saveState");
|
||||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
const setOutputMock = jest.spyOn(core, "setOutput");
|
||||||
const restoreCacheMock = jest
|
const restoreCacheMock = jest
|
||||||
.spyOn(cache, "restoreCache")
|
.spyOn(cache, "restoreCache")
|
||||||
.mockImplementationOnce(() => {
|
.mockImplementationOnce(() => {
|
||||||
@ -173,8 +173,10 @@ test("restore with cache found for key", async () => {
|
|||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", key);
|
expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", key);
|
||||||
expect(stateMock).toHaveBeenCalledTimes(2);
|
expect(stateMock).toHaveBeenCalledTimes(2);
|
||||||
|
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
expect(setOutputMock).toHaveBeenCalledTimes(3);
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true");
|
expect(setOutputMock).toHaveBeenCalledWith("cache-hit", "true");
|
||||||
|
expect(setOutputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
||||||
|
expect(setOutputMock).toHaveBeenCalledWith("cache-matched-key", key);
|
||||||
|
|
||||||
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||||
@ -194,7 +196,7 @@ test("restore with cache found for restore key", async () => {
|
|||||||
const infoMock = jest.spyOn(core, "info");
|
const infoMock = jest.spyOn(core, "info");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
const stateMock = jest.spyOn(core, "saveState");
|
||||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
const setOutputMock = jest.spyOn(core, "setOutput");
|
||||||
const restoreCacheMock = jest
|
const restoreCacheMock = jest
|
||||||
.spyOn(cache, "restoreCache")
|
.spyOn(cache, "restoreCache")
|
||||||
.mockImplementationOnce(() => {
|
.mockImplementationOnce(() => {
|
||||||
@ -218,8 +220,10 @@ test("restore with cache found for restore key", async () => {
|
|||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", restoreKey);
|
expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", restoreKey);
|
||||||
expect(stateMock).toHaveBeenCalledTimes(2);
|
expect(stateMock).toHaveBeenCalledTimes(2);
|
||||||
|
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
expect(setOutputMock).toHaveBeenCalledTimes(3);
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "false");
|
expect(setOutputMock).toHaveBeenCalledWith("cache-hit", "false");
|
||||||
|
expect(setOutputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
||||||
|
expect(setOutputMock).toHaveBeenCalledWith("cache-matched-key", restoreKey);
|
||||||
expect(infoMock).toHaveBeenCalledWith(
|
expect(infoMock).toHaveBeenCalledWith(
|
||||||
`Cache restored from key: ${restoreKey}`
|
`Cache restored from key: ${restoreKey}`
|
||||||
);
|
);
|
||||||
@ -239,7 +243,7 @@ test("Fail restore when fail on cache miss is enabled and primary + restore keys
|
|||||||
|
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
const stateMock = jest.spyOn(core, "saveState");
|
||||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
const setOutputMock = jest.spyOn(core, "setOutput");
|
||||||
const restoreCacheMock = jest
|
const restoreCacheMock = jest
|
||||||
.spyOn(cache, "restoreCache")
|
.spyOn(cache, "restoreCache")
|
||||||
.mockImplementationOnce(() => {
|
.mockImplementationOnce(() => {
|
||||||
@ -260,7 +264,8 @@ test("Fail restore when fail on cache miss is enabled and primary + restore keys
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(0);
|
expect(setOutputMock).toHaveBeenCalledTimes(1);
|
||||||
|
expect(setOutputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
||||||
|
|
||||||
expect(failedMock).toHaveBeenCalledWith(
|
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}`
|
||||||
@ -282,7 +287,7 @@ test("restore when fail on cache miss is enabled and primary key doesn't match r
|
|||||||
const infoMock = jest.spyOn(core, "info");
|
const infoMock = jest.spyOn(core, "info");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
const stateMock = jest.spyOn(core, "saveState");
|
||||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
const setOutputMock = jest.spyOn(core, "setOutput");
|
||||||
const restoreCacheMock = jest
|
const restoreCacheMock = jest
|
||||||
.spyOn(cache, "restoreCache")
|
.spyOn(cache, "restoreCache")
|
||||||
.mockImplementationOnce(() => {
|
.mockImplementationOnce(() => {
|
||||||
@ -306,8 +311,10 @@ test("restore when fail on cache miss is enabled and primary key doesn't match r
|
|||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", restoreKey);
|
expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", restoreKey);
|
||||||
expect(stateMock).toHaveBeenCalledTimes(2);
|
expect(stateMock).toHaveBeenCalledTimes(2);
|
||||||
|
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
expect(setOutputMock).toHaveBeenCalledTimes(3);
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "false");
|
expect(setOutputMock).toHaveBeenCalledWith("cache-hit", "false");
|
||||||
|
expect(setOutputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
||||||
|
expect(setOutputMock).toHaveBeenCalledWith("cache-matched-key", restoreKey);
|
||||||
|
|
||||||
expect(infoMock).toHaveBeenCalledWith(
|
expect(infoMock).toHaveBeenCalledWith(
|
||||||
`Cache restored from key: ${restoreKey}`
|
`Cache restored from key: ${restoreKey}`
|
||||||
|
|||||||
@ -112,7 +112,7 @@ test("restore on GHES with AC available ", async () => {
|
|||||||
const infoMock = jest.spyOn(core, "info");
|
const infoMock = jest.spyOn(core, "info");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
const stateMock = jest.spyOn(core, "saveState");
|
||||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
const setOutputMock = jest.spyOn(core, "setOutput");
|
||||||
const restoreCacheMock = jest
|
const restoreCacheMock = jest
|
||||||
.spyOn(cache, "restoreCache")
|
.spyOn(cache, "restoreCache")
|
||||||
.mockImplementationOnce(() => {
|
.mockImplementationOnce(() => {
|
||||||
@ -133,8 +133,10 @@ test("restore on GHES with AC available ", async () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
expect(setOutputMock).toHaveBeenCalledTimes(3);
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true");
|
expect(setOutputMock).toHaveBeenCalledWith("cache-hit", "true");
|
||||||
|
expect(setOutputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
||||||
|
expect(setOutputMock).toHaveBeenCalledWith("cache-matched-key", key);
|
||||||
|
|
||||||
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||||
@ -334,7 +336,7 @@ test("restore with cache found for key", async () => {
|
|||||||
const infoMock = jest.spyOn(core, "info");
|
const infoMock = jest.spyOn(core, "info");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
const stateMock = jest.spyOn(core, "saveState");
|
||||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
const setOutputMock = jest.spyOn(core, "setOutput");
|
||||||
const restoreCacheMock = jest
|
const restoreCacheMock = jest
|
||||||
.spyOn(cache, "restoreCache")
|
.spyOn(cache, "restoreCache")
|
||||||
.mockImplementationOnce(() => {
|
.mockImplementationOnce(() => {
|
||||||
@ -355,8 +357,10 @@ test("restore with cache found for key", async () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
expect(setOutputMock).toHaveBeenCalledTimes(3);
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true");
|
expect(setOutputMock).toHaveBeenCalledWith("cache-hit", "true");
|
||||||
|
expect(setOutputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
||||||
|
expect(setOutputMock).toHaveBeenCalledWith("cache-matched-key", key);
|
||||||
|
|
||||||
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||||
@ -376,7 +380,7 @@ test("restore with cache found for restore key", async () => {
|
|||||||
const infoMock = jest.spyOn(core, "info");
|
const infoMock = jest.spyOn(core, "info");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
const stateMock = jest.spyOn(core, "saveState");
|
||||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
const setOutputMock = jest.spyOn(core, "setOutput");
|
||||||
const restoreCacheMock = jest
|
const restoreCacheMock = jest
|
||||||
.spyOn(cache, "restoreCache")
|
.spyOn(cache, "restoreCache")
|
||||||
.mockImplementationOnce(() => {
|
.mockImplementationOnce(() => {
|
||||||
@ -397,8 +401,10 @@ test("restore with cache found for restore key", async () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
expect(setOutputMock).toHaveBeenCalledTimes(3);
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "false");
|
expect(setOutputMock).toHaveBeenCalledWith("cache-hit", "false");
|
||||||
|
expect(setOutputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
||||||
|
expect(setOutputMock).toHaveBeenCalledWith("cache-matched-key", restoreKey);
|
||||||
expect(infoMock).toHaveBeenCalledWith(
|
expect(infoMock).toHaveBeenCalledWith(
|
||||||
`Cache restored from key: ${restoreKey}`
|
`Cache restored from key: ${restoreKey}`
|
||||||
);
|
);
|
||||||
@ -417,7 +423,7 @@ test("restore with lookup-only set", async () => {
|
|||||||
const infoMock = jest.spyOn(core, "info");
|
const infoMock = jest.spyOn(core, "info");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
const stateMock = jest.spyOn(core, "saveState");
|
const stateMock = jest.spyOn(core, "saveState");
|
||||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
const setOutputMock = jest.spyOn(core, "setOutput");
|
||||||
const restoreCacheMock = jest
|
const restoreCacheMock = jest
|
||||||
.spyOn(cache, "restoreCache")
|
.spyOn(cache, "restoreCache")
|
||||||
.mockImplementationOnce(() => {
|
.mockImplementationOnce(() => {
|
||||||
@ -441,8 +447,10 @@ test("restore with lookup-only set", async () => {
|
|||||||
expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", key);
|
expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", key);
|
||||||
expect(stateMock).toHaveBeenCalledTimes(2);
|
expect(stateMock).toHaveBeenCalledTimes(2);
|
||||||
|
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
expect(setOutputMock).toHaveBeenCalledTimes(3);
|
||||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true");
|
expect(setOutputMock).toHaveBeenCalledWith("cache-hit", "true");
|
||||||
|
expect(setOutputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
||||||
|
expect(setOutputMock).toHaveBeenCalledWith("cache-matched-key", key);
|
||||||
|
|
||||||
expect(infoMock).toHaveBeenCalledWith(
|
expect(infoMock).toHaveBeenCalledWith(
|
||||||
`Cache found and can be restored from key: ${key}`
|
`Cache found and can be restored from key: ${key}`
|
||||||
|
|||||||
@ -54,7 +54,7 @@ test("StateProvider saves states", async () => {
|
|||||||
expect(cacheStateValue).toBe(cacheMatchedKey);
|
expect(cacheStateValue).toBe(cacheMatchedKey);
|
||||||
expect(getStateMock).toHaveBeenCalledTimes(2);
|
expect(getStateMock).toHaveBeenCalledTimes(2);
|
||||||
expect(saveStateMock).toHaveBeenCalledTimes(2);
|
expect(saveStateMock).toHaveBeenCalledTimes(2);
|
||||||
expect(setOutputMock).toHaveBeenCalledTimes(0);
|
expect(setOutputMock).toHaveBeenCalledTimes(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("NullStateProvider saves outputs", async () => {
|
test("NullStateProvider saves outputs", async () => {
|
||||||
|
|||||||
@ -37,6 +37,10 @@ inputs:
|
|||||||
outputs:
|
outputs:
|
||||||
cache-hit:
|
cache-hit:
|
||||||
description: 'A boolean value to indicate an exact match was found for the primary key'
|
description: 'A boolean value to indicate an exact match was found for the primary key'
|
||||||
|
cache-primary-key:
|
||||||
|
description: 'A resolved cache key for which cache match was attempted'
|
||||||
|
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'
|
||||||
runs:
|
runs:
|
||||||
using: 'node24'
|
using: 'node24'
|
||||||
main: 'dist/restore/index.js'
|
main: 'dist/restore/index.js'
|
||||||
|
|||||||
17
dist/restore-only/index.js
vendored
17
dist/restore-only/index.js
vendored
@ -46382,21 +46382,22 @@ class StateProviderBase {
|
|||||||
class StateProvider extends StateProviderBase {
|
class StateProvider extends StateProviderBase {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(...arguments);
|
super(...arguments);
|
||||||
this.setState = core.saveState;
|
this.setState = (key, value) => { core.saveState(key, value); stateToOutput(key, value); };
|
||||||
this.getState = core.getState;
|
this.getState = core.getState;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.StateProvider = StateProvider;
|
exports.StateProvider = StateProvider;
|
||||||
|
const stateToOutputMap = new Map([
|
||||||
|
[constants_1.State.CacheMatchedKey, constants_1.Outputs.CacheMatchedKey],
|
||||||
|
[constants_1.State.CachePrimaryKey, constants_1.Outputs.CachePrimaryKey]
|
||||||
|
]);
|
||||||
|
function stateToOutput(key, value) {
|
||||||
|
core.setOutput(stateToOutputMap.get(key), value);
|
||||||
|
}
|
||||||
class NullStateProvider extends StateProviderBase {
|
class NullStateProvider extends StateProviderBase {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(...arguments);
|
super(...arguments);
|
||||||
this.stateToOutputMap = new Map([
|
this.setState = stateToOutput;
|
||||||
[constants_1.State.CacheMatchedKey, constants_1.Outputs.CacheMatchedKey],
|
|
||||||
[constants_1.State.CachePrimaryKey, constants_1.Outputs.CachePrimaryKey]
|
|
||||||
]);
|
|
||||||
this.setState = (key, value) => {
|
|
||||||
core.setOutput(this.stateToOutputMap.get(key), value);
|
|
||||||
};
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
this.getState = (key) => "";
|
this.getState = (key) => "";
|
||||||
}
|
}
|
||||||
|
|||||||
17
dist/restore/index.js
vendored
17
dist/restore/index.js
vendored
@ -46382,21 +46382,22 @@ class StateProviderBase {
|
|||||||
class StateProvider extends StateProviderBase {
|
class StateProvider extends StateProviderBase {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(...arguments);
|
super(...arguments);
|
||||||
this.setState = core.saveState;
|
this.setState = (key, value) => { core.saveState(key, value); stateToOutput(key, value); };
|
||||||
this.getState = core.getState;
|
this.getState = core.getState;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.StateProvider = StateProvider;
|
exports.StateProvider = StateProvider;
|
||||||
|
const stateToOutputMap = new Map([
|
||||||
|
[constants_1.State.CacheMatchedKey, constants_1.Outputs.CacheMatchedKey],
|
||||||
|
[constants_1.State.CachePrimaryKey, constants_1.Outputs.CachePrimaryKey]
|
||||||
|
]);
|
||||||
|
function stateToOutput(key, value) {
|
||||||
|
core.setOutput(stateToOutputMap.get(key), value);
|
||||||
|
}
|
||||||
class NullStateProvider extends StateProviderBase {
|
class NullStateProvider extends StateProviderBase {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(...arguments);
|
super(...arguments);
|
||||||
this.stateToOutputMap = new Map([
|
this.setState = stateToOutput;
|
||||||
[constants_1.State.CacheMatchedKey, constants_1.Outputs.CacheMatchedKey],
|
|
||||||
[constants_1.State.CachePrimaryKey, constants_1.Outputs.CachePrimaryKey]
|
|
||||||
]);
|
|
||||||
this.setState = (key, value) => {
|
|
||||||
core.setOutput(this.stateToOutputMap.get(key), value);
|
|
||||||
};
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
this.getState = (key) => "";
|
this.getState = (key) => "";
|
||||||
}
|
}
|
||||||
|
|||||||
17
dist/save-only/index.js
vendored
17
dist/save-only/index.js
vendored
@ -46395,21 +46395,22 @@ class StateProviderBase {
|
|||||||
class StateProvider extends StateProviderBase {
|
class StateProvider extends StateProviderBase {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(...arguments);
|
super(...arguments);
|
||||||
this.setState = core.saveState;
|
this.setState = (key, value) => { core.saveState(key, value); stateToOutput(key, value); };
|
||||||
this.getState = core.getState;
|
this.getState = core.getState;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.StateProvider = StateProvider;
|
exports.StateProvider = StateProvider;
|
||||||
|
const stateToOutputMap = new Map([
|
||||||
|
[constants_1.State.CacheMatchedKey, constants_1.Outputs.CacheMatchedKey],
|
||||||
|
[constants_1.State.CachePrimaryKey, constants_1.Outputs.CachePrimaryKey]
|
||||||
|
]);
|
||||||
|
function stateToOutput(key, value) {
|
||||||
|
core.setOutput(stateToOutputMap.get(key), value);
|
||||||
|
}
|
||||||
class NullStateProvider extends StateProviderBase {
|
class NullStateProvider extends StateProviderBase {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(...arguments);
|
super(...arguments);
|
||||||
this.stateToOutputMap = new Map([
|
this.setState = stateToOutput;
|
||||||
[constants_1.State.CacheMatchedKey, constants_1.Outputs.CacheMatchedKey],
|
|
||||||
[constants_1.State.CachePrimaryKey, constants_1.Outputs.CachePrimaryKey]
|
|
||||||
]);
|
|
||||||
this.setState = (key, value) => {
|
|
||||||
core.setOutput(this.stateToOutputMap.get(key), value);
|
|
||||||
};
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
this.getState = (key) => "";
|
this.getState = (key) => "";
|
||||||
}
|
}
|
||||||
|
|||||||
17
dist/save/index.js
vendored
17
dist/save/index.js
vendored
@ -46395,21 +46395,22 @@ class StateProviderBase {
|
|||||||
class StateProvider extends StateProviderBase {
|
class StateProvider extends StateProviderBase {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(...arguments);
|
super(...arguments);
|
||||||
this.setState = core.saveState;
|
this.setState = (key, value) => { core.saveState(key, value); stateToOutput(key, value); };
|
||||||
this.getState = core.getState;
|
this.getState = core.getState;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.StateProvider = StateProvider;
|
exports.StateProvider = StateProvider;
|
||||||
|
const stateToOutputMap = new Map([
|
||||||
|
[constants_1.State.CacheMatchedKey, constants_1.Outputs.CacheMatchedKey],
|
||||||
|
[constants_1.State.CachePrimaryKey, constants_1.Outputs.CachePrimaryKey]
|
||||||
|
]);
|
||||||
|
function stateToOutput(key, value) {
|
||||||
|
core.setOutput(stateToOutputMap.get(key), value);
|
||||||
|
}
|
||||||
class NullStateProvider extends StateProviderBase {
|
class NullStateProvider extends StateProviderBase {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(...arguments);
|
super(...arguments);
|
||||||
this.stateToOutputMap = new Map([
|
this.setState = stateToOutput;
|
||||||
[constants_1.State.CacheMatchedKey, constants_1.Outputs.CacheMatchedKey],
|
|
||||||
[constants_1.State.CachePrimaryKey, constants_1.Outputs.CachePrimaryKey]
|
|
||||||
]);
|
|
||||||
this.setState = (key, value) => {
|
|
||||||
core.setOutput(this.stateToOutputMap.get(key), value);
|
|
||||||
};
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
this.getState = (key) => "";
|
this.getState = (key) => "";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,19 +28,22 @@ class StateProviderBase implements IStateProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class StateProvider extends StateProviderBase {
|
export class StateProvider extends StateProviderBase {
|
||||||
setState = core.saveState;
|
setState = (key: string, value: string) => {
|
||||||
|
core.saveState(key, value);
|
||||||
|
stateToOutput(key, value);
|
||||||
|
};
|
||||||
getState = core.getState;
|
getState = core.getState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const stateToOutputMap = new Map<string, string>([
|
||||||
|
[State.CacheMatchedKey, Outputs.CacheMatchedKey],
|
||||||
|
[State.CachePrimaryKey, Outputs.CachePrimaryKey]
|
||||||
|
]);
|
||||||
|
function stateToOutput(key: string, value: string) {
|
||||||
|
core.setOutput(stateToOutputMap.get(key) as string, value);
|
||||||
|
}
|
||||||
export class NullStateProvider extends StateProviderBase {
|
export class NullStateProvider extends StateProviderBase {
|
||||||
stateToOutputMap = new Map<string, string>([
|
setState = stateToOutput;
|
||||||
[State.CacheMatchedKey, Outputs.CacheMatchedKey],
|
|
||||||
[State.CachePrimaryKey, Outputs.CachePrimaryKey]
|
|
||||||
]);
|
|
||||||
|
|
||||||
setState = (key: string, value: string) => {
|
|
||||||
core.setOutput(this.stateToOutputMap.get(key) as string, value);
|
|
||||||
};
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
getState = (key: string) => "";
|
getState = (key: string) => "";
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user