3
0
Fork 0
mirror of https://code.forgejo.org/actions/cache.git synced 2025-04-23 03:45:31 +00:00

Support AWS S3 and compatible software

This commit is contained in:
whywaita 2022-02-14 18:51:41 +09:00
parent 72d1e4fdff
commit 3922a6a550
No known key found for this signature in database
GPG key ID: 410FE9327D2F4F0E
10 changed files with 122536 additions and 26393 deletions

View file

@ -2,7 +2,14 @@ export enum Inputs {
Key = "key",
Path = "path",
RestoreKeys = "restore-keys",
UploadChunkSize = "upload-chunk-size"
UploadChunkSize = "upload-chunk-size",
AWSS3Bucket = "aws-s3-bucket",
AWSAccessKeyId = "aws-access-key-id",
AWSSecretAccessKey = "aws-secret-access-key",
AWSRegion = "aws-region",
AWSEndpoint = "aws-endpoint",
AWSS3BucketEndpoint = "aws-s3-bucket-endpoint",
AWSS3ForcePathStyle = "aws-s3-force-path-style"
}
export enum Outputs {

View file

@ -6,14 +6,6 @@ import * as utils from "./utils/actionUtils";
async function run(): Promise<void> {
try {
if (utils.isGhes()) {
utils.logWarning(
"Cache action is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details"
);
utils.setCacheHitOutput(false);
return;
}
// Validate inputs, this can cause task failure
if (!utils.isValidEvent()) {
utils.logWarning(
@ -31,12 +23,17 @@ async function run(): Promise<void> {
const cachePaths = utils.getInputAsArray(Inputs.Path, {
required: true
});
const s3BucketName = core.getInput(Inputs.AWSS3Bucket);
const s3config = utils.getInputS3ClientConfig();
try {
const cacheKey = await cache.restoreCache(
cachePaths,
primaryKey,
restoreKeys
restoreKeys,
undefined,
s3config,
s3BucketName
);
if (!cacheKey) {
core.info(

View file

@ -11,13 +11,6 @@ process.on("uncaughtException", e => utils.logWarning(e.message));
async function run(): Promise<void> {
try {
if (utils.isGhes()) {
utils.logWarning(
"Cache action is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details"
);
return;
}
if (!utils.isValidEvent()) {
utils.logWarning(
`Event Validation Error: The event type ${
@ -46,11 +39,13 @@ async function run(): Promise<void> {
const cachePaths = utils.getInputAsArray(Inputs.Path, {
required: true
});
const s3BucketName = core.getInput(Inputs.AWSS3Bucket);
const s3config = utils.getInputS3ClientConfig();
try {
await cache.saveCache(cachePaths, primaryKey, {
uploadChunkSize: utils.getInputAsInt(Inputs.UploadChunkSize)
});
}, s3config, s3BucketName);
core.info(`Cache saved with key: ${primaryKey}`);
} catch (error) {
if (error.name === cache.ValidationError.name) {

View file

@ -1,6 +1,8 @@
import * as core from "@actions/core";
import { Outputs, RefKey, State } from "../constants";
import { Inputs, Outputs, RefKey, State } from "../constants";
import {CommonPrefix, InputSerialization, S3ClientConfig} from "@aws-sdk/client-s3";
export function isGhes(): boolean {
const ghUrl = new URL(
@ -74,3 +76,25 @@ export function getInputAsInt(
}
return value;
}
export function getInputS3ClientConfig(): S3ClientConfig | undefined {
const s3BucketName = core.getInput(Inputs.AWSS3Bucket)
if (!s3BucketName) {
return undefined
}
const s3config = {
credentials: {
accessKeyId: core.getInput(Inputs.AWSAccessKeyId),
secretAccessKey: core.getInput(Inputs.AWSSecretAccessKey)
},
region: core.getInput(Inputs.AWSRegion),
endpoint: core.getInput(Inputs.AWSEndpoint),
bucketEndpoint: core.getBooleanInput(Inputs.AWSS3BucketEndpoint),
forcePathStyle: core.getBooleanInput(Inputs.AWSS3ForcePathStyle),
} as S3ClientConfig
core.debug('Enable S3 backend mode.')
return s3config
}