Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use env #40

Merged
merged 7 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions .github/workflows/test-env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: test-env

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
create-minio-bucket:
runs-on: ubuntu-latest
steps:
- run: |
wget -q https://dl.min.io/client/mc/release/linux-amd64/mc
chmod a+x mc
./mc mb play/actions-cache || exit 0

test-save:
needs: create-minio-bucket
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Generate files in working directory
shell: bash
run: src/create-cache-files.sh ${{ runner.os }} test-cache
- name: Generate files outside working directory
shell: bash
run: src/create-cache-files.sh ${{ runner.os }} ~/test-cache
- name: Save cache
uses: ./
env:
AWS_ACCESS_KEY_ID: "Q3AM3UQ867SPQQA43P2F"
AWS_SECRET_ACCESS_KEY: "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"
# AWS_SESSION_TOKEN: "xxx"
AWS_REGION: "us-east-1"
with:
endpoint: play.min.io
bucket: actions-cache
use-fallback: false
key: test-${{ runner.os }}-${{ github.run_id }}
path: |
test-cache
~/test-cache

test-restore:
needs: test-save
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Restore cache
uses: ./
env:
AWS_ACCESS_KEY_ID: "Q3AM3UQ867SPQQA43P2F"
AWS_SECRET_ACCESS_KEY: "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"
# AWS_SESSION_TOKEN: "xxx"
AWS_REGION: "us-east-1"
with:
endpoint: play.min.io
bucket: actions-cache
key: test-${{ runner.os }}-${{ github.run_id }}
path: |
test-cache
~/test-cache
- name: Verify cache files in working directory
shell: bash
run: src/verify-cache-files.sh ${{ runner.os }} test-cache
- name: Verify cache files outside working directory
shell: bash
run: src/verify-cache-files.sh ${{ runner.os }} ~/test-cache
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: "20.x"
- name: Install Yarn
run: npm install -g yarn
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v2
- uses: actions/cache@v3
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,25 @@ jobs:
${{ runner.os }}-yarn-
```

You can also set env instead of using `with`:

```yaml
- uses: tespkg/actions-cache@v1
env:
AWS_ACCESS_KEY_ID: "Q3AM3UQ867SPQQA43P2F"
AWS_SECRET_ACCESS_KEY: "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"
# AWS_SESSION_TOKEN: "xxx"
AWS_REGION: "us-east-1"
with:
endpoint: play.min.io
bucket: actions-cache
use-fallback: false
key: test-${{ runner.os }}-${{ github.run_id }}
path: |
test-cache
~/test-cache
```

## Restore keys

`restore-keys` works similar to how github's `@actions/cache@v2` works: It search each item in `restore-keys`
Expand Down
31 changes: 22 additions & 9 deletions dist/restore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102639,9 +102639,10 @@ function restoreCache() {
try {
// Inputs are re-evaluted before the post action, so we want to store the original values
core.saveState(state_1.State.PrimaryKey, key);
core.saveState(state_1.State.AccessKey, core.getInput("accessKey"));
core.saveState(state_1.State.SecretKey, core.getInput("secretKey"));
core.saveState(state_1.State.SessionToken, core.getInput("sessionToken"));
core.saveState(state_1.State.AccessKey, (0, utils_1.getInput)("accessKey", "AWS_ACCESS_KEY_ID"));
core.saveState(state_1.State.SecretKey, (0, utils_1.getInput)("secretKey", "AWS_SECRET_ACCESS_KEY"));
core.saveState(state_1.State.SessionToken, (0, utils_1.getInput)("sessionToken", "AWS_SESSION_TOKEN"));
core.saveState(state_1.State.Region, (0, utils_1.getInput)("region", "AWS_REGION"));
const mc = (0, utils_1.newMinio)();
const compressionMethod = yield utils.getCompressionMethod();
const cacheFileName = utils.getCacheFileName(compressionMethod);
Expand Down Expand Up @@ -102705,6 +102706,7 @@ var State;
State["AccessKey"] = "access-key";
State["SecretKey"] = "secret-key";
State["SessionToken"] = "session-token";
State["Region"] = "region";
})(State || (exports.State = State = {}));


Expand Down Expand Up @@ -102748,7 +102750,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.isExactKeyMatch = exports.saveMatchedKey = exports.listObjects = exports.findObject = exports.setCacheSizeOutput = exports.setCacheHitOutput = exports.formatSize = exports.getInputAsInt = exports.getInputAsArray = exports.getInputAsBoolean = exports.newMinio = exports.isGhes = void 0;
exports.isExactKeyMatch = exports.saveMatchedKey = exports.listObjects = exports.findObject = exports.setCacheSizeOutput = exports.setCacheHitOutput = exports.formatSize = exports.getInputAsInt = exports.getInputAsArray = exports.getInputAsBoolean = exports.newMinio = exports.getInput = exports.isGhes = void 0;
const utils = __importStar(__nccwpck_require__(1518));
const core = __importStar(__nccwpck_require__(2186));
const minio = __importStar(__nccwpck_require__(8308));
Expand All @@ -102758,15 +102760,26 @@ function isGhes() {
return ghUrl.hostname.toUpperCase() !== "GITHUB.COM";
}
exports.isGhes = isGhes;
function newMinio({ accessKey, secretKey, sessionToken, } = {}) {
function getInput(key, envKey) {
let result;
if (envKey) {
result = process.env[envKey];
}
if (result === undefined) {
result = core.getInput(key);
}
return result;
}
exports.getInput = getInput;
function newMinio({ accessKey, secretKey, sessionToken, region, } = {}) {
return new minio.Client({
endPoint: core.getInput("endpoint"),
port: getInputAsInt("port"),
useSSL: !getInputAsBoolean("insecure"),
accessKey: accessKey !== null && accessKey !== void 0 ? accessKey : core.getInput("accessKey"),
secretKey: secretKey !== null && secretKey !== void 0 ? secretKey : core.getInput("secretKey"),
sessionToken: sessionToken !== null && sessionToken !== void 0 ? sessionToken : core.getInput("sessionToken"),
region: core.getInput("region"),
accessKey: accessKey !== null && accessKey !== void 0 ? accessKey : getInput("accessKey", "AWS_ACCESS_KEY_ID"),
secretKey: secretKey !== null && secretKey !== void 0 ? secretKey : getInput("secretKey", "AWS_SECRET_ACCESS_KEY"),
sessionToken: sessionToken !== null && sessionToken !== void 0 ? sessionToken : getInput("sessionToken", "AWS_SESSION_TOKEN"),
region: region !== null && region !== void 0 ? region : getInput("region", "AWS_REGION"),
});
}
exports.newMinio = newMinio;
Expand Down
25 changes: 19 additions & 6 deletions dist/save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102646,6 +102646,7 @@ function saveCache() {
accessKey: core.getState(state_1.State.AccessKey),
secretKey: core.getState(state_1.State.SecretKey),
sessionToken: core.getState(state_1.State.SessionToken),
region: core.getState(state_1.State.Region),
});
const compressionMethod = yield utils.getCompressionMethod();
const cachePaths = yield utils.resolvePaths(paths);
Expand Down Expand Up @@ -102705,6 +102706,7 @@ var State;
State["AccessKey"] = "access-key";
State["SecretKey"] = "secret-key";
State["SessionToken"] = "session-token";
State["Region"] = "region";
})(State || (exports.State = State = {}));


Expand Down Expand Up @@ -102748,7 +102750,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.isExactKeyMatch = exports.saveMatchedKey = exports.listObjects = exports.findObject = exports.setCacheSizeOutput = exports.setCacheHitOutput = exports.formatSize = exports.getInputAsInt = exports.getInputAsArray = exports.getInputAsBoolean = exports.newMinio = exports.isGhes = void 0;
exports.isExactKeyMatch = exports.saveMatchedKey = exports.listObjects = exports.findObject = exports.setCacheSizeOutput = exports.setCacheHitOutput = exports.formatSize = exports.getInputAsInt = exports.getInputAsArray = exports.getInputAsBoolean = exports.newMinio = exports.getInput = exports.isGhes = void 0;
const utils = __importStar(__nccwpck_require__(1518));
const core = __importStar(__nccwpck_require__(2186));
const minio = __importStar(__nccwpck_require__(8308));
Expand All @@ -102758,15 +102760,26 @@ function isGhes() {
return ghUrl.hostname.toUpperCase() !== "GITHUB.COM";
}
exports.isGhes = isGhes;
function newMinio({ accessKey, secretKey, sessionToken, } = {}) {
function getInput(key, envKey) {
let result;
if (envKey) {
result = process.env[envKey];
}
if (result === undefined) {
result = core.getInput(key);
}
return result;
}
exports.getInput = getInput;
function newMinio({ accessKey, secretKey, sessionToken, region, } = {}) {
return new minio.Client({
endPoint: core.getInput("endpoint"),
port: getInputAsInt("port"),
useSSL: !getInputAsBoolean("insecure"),
accessKey: accessKey !== null && accessKey !== void 0 ? accessKey : core.getInput("accessKey"),
secretKey: secretKey !== null && secretKey !== void 0 ? secretKey : core.getInput("secretKey"),
sessionToken: sessionToken !== null && sessionToken !== void 0 ? sessionToken : core.getInput("sessionToken"),
region: core.getInput("region"),
accessKey: accessKey !== null && accessKey !== void 0 ? accessKey : getInput("accessKey", "AWS_ACCESS_KEY_ID"),
secretKey: secretKey !== null && secretKey !== void 0 ? secretKey : getInput("secretKey", "AWS_SECRET_ACCESS_KEY"),
sessionToken: sessionToken !== null && sessionToken !== void 0 ? sessionToken : getInput("sessionToken", "AWS_SESSION_TOKEN"),
region: region !== null && region !== void 0 ? region : getInput("region", "AWS_REGION"),
});
}
exports.newMinio = newMinio;
Expand Down
8 changes: 5 additions & 3 deletions src/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
setCacheHitOutput,
setCacheSizeOutput,
saveMatchedKey,
getInput,
} from "./utils";

process.on("uncaughtException", (e) => core.info("warning: " + e.message));
Expand All @@ -29,9 +30,10 @@ async function restoreCache() {
try {
// Inputs are re-evaluted before the post action, so we want to store the original values
core.saveState(State.PrimaryKey, key);
core.saveState(State.AccessKey, core.getInput("accessKey"));
core.saveState(State.SecretKey, core.getInput("secretKey"));
core.saveState(State.SessionToken, core.getInput("sessionToken"));
core.saveState(State.AccessKey, getInput("accessKey", "AWS_ACCESS_KEY_ID"));
core.saveState(State.SecretKey, getInput("secretKey", "AWS_SECRET_ACCESS_KEY"));
core.saveState(State.SessionToken, getInput("sessionToken", "AWS_SESSION_TOKEN"));
core.saveState(State.Region, getInput("region", "AWS_REGION"));

const mc = newMinio();

Expand Down
1 change: 1 addition & 0 deletions src/save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ async function saveCache() {
accessKey: core.getState(State.AccessKey),
secretKey: core.getState(State.SecretKey),
sessionToken: core.getState(State.SessionToken),
region: core.getState(State.Region),
});

const compressionMethod = await utils.getCompressionMethod();
Expand Down
1 change: 1 addition & 0 deletions src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export enum State {
"AccessKey" = "access-key",
"SecretKey" = "secret-key",
"SessionToken" = "session-token",
"Region" = "region"
}
21 changes: 17 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,36 @@ export function isGhes(): boolean {
return ghUrl.hostname.toUpperCase() !== "GITHUB.COM";
}

export function getInput(key: string, envKey?: string) {
let result;
if (envKey) {
result = process.env[envKey]
}
if (result === undefined) {
result = core.getInput(key);
}
return result;
}

export function newMinio({
accessKey,
secretKey,
sessionToken,
region,
}: {
accessKey?: string;
secretKey?: string;
sessionToken?: string;
region?: string;
} = {}) {
return new minio.Client({
endPoint: core.getInput("endpoint"),
port: getInputAsInt("port"),
useSSL: !getInputAsBoolean("insecure"),
accessKey: accessKey ?? core.getInput("accessKey"),
secretKey: secretKey ?? core.getInput("secretKey"),
sessionToken: sessionToken ?? core.getInput("sessionToken"),
region: core.getInput("region"),
accessKey: accessKey ?? getInput("accessKey", "AWS_ACCESS_KEY_ID"),
secretKey: secretKey ?? getInput("secretKey", "AWS_SECRET_ACCESS_KEY"),
sessionToken: sessionToken ?? getInput("sessionToken", "AWS_SESSION_TOKEN"),
region: region ?? getInput("region", "AWS_REGION"),
});
}

Expand Down
Loading