From 02fa69bea4b9c3bd204187fe7d6408fe1ee60453 Mon Sep 17 00:00:00 2001 From: Vincent Clemson Date: Sat, 18 Jun 2022 17:20:32 -0400 Subject: [PATCH] build action & add jobs to Tests workflow for only-restore option * add regular & proxy server jobs * run job between save & restore jobs to test that only-restore option works with consecutive restores --- .github/workflows/workflow.yml | 48 ++++++++++++++++++++ dist/restore/index.js | 4 +- dist/save/index.js | 83 ++++++++++++++++++---------------- 3 files changed, 93 insertions(+), 42 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 48f1ccb..2ba59e9 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -71,6 +71,30 @@ jobs: path: | test-cache ~/test-cache + test-only-restore: + needs: test-restore + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macOS-latest] + fail-fast: false + runs-on: ${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Restore cache + uses: ./ + with: + only-restore: true + key: test-${{ runner.os }}-${{ github.run_id }} + path: | + test-cache + ~/test-cache + - name: Verify cache files in working directory + shell: bash + run: __tests__/verify-cache-files.sh ${{ runner.os }} test-cache + - name: Verify cache files outside working directory + shell: bash + run: __tests__/verify-cache-files.sh ${{ runner.os }} ~/test-cache test-restore: needs: test-save strategy: @@ -118,6 +142,30 @@ jobs: with: key: test-proxy-${{ github.run_id }} path: test-cache + test-proxy-only-restore: + needs: test-proxy-save + runs-on: ubuntu-latest + container: + image: ubuntu:latest + options: --dns 127.0.0.1 + services: + squid-proxy: + image: datadog/squid:latest + ports: + - 3128:3128 + env: + https_proxy: http://squid-proxy:3128 + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Restore cache + uses: ./ + with: + only-restore: true + key: test-proxy-${{ github.run_id }} + path: test-cache + - name: Verify cache + run: __tests__/verify-cache-files.sh proxy test-cache test-proxy-restore: needs: test-proxy-save runs-on: ubuntu-latest diff --git a/dist/restore/index.js b/dist/restore/index.js index 9351a66..e15a582 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -4607,7 +4607,9 @@ exports.RefKey = exports.Events = exports.State = exports.Outputs = exports.Inpu var Inputs; (function (Inputs) { Inputs["Key"] = "key"; + Inputs["OnlyRestore"] = "only-restore"; Inputs["Path"] = "path"; + Inputs["Reeval"] = "reeval"; Inputs["RestoreKeys"] = "restore-keys"; Inputs["UploadChunkSize"] = "upload-chunk-size"; })(Inputs = exports.Inputs || (exports.Inputs = {})); @@ -37317,8 +37319,6 @@ function createTar(archiveFolder, sourceDirectories, compressionMethod) { ...getCompressionProgram(), '-cf', cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), - '--exclude', - cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), '-P', '-C', workingDirectory.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), diff --git a/dist/save/index.js b/dist/save/index.js index 983cb5d..3e76c65 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -4607,7 +4607,9 @@ exports.RefKey = exports.Events = exports.State = exports.Outputs = exports.Inpu var Inputs; (function (Inputs) { Inputs["Key"] = "key"; + Inputs["OnlyRestore"] = "only-restore"; Inputs["Path"] = "path"; + Inputs["Reeval"] = "reeval"; Inputs["RestoreKeys"] = "restore-keys"; Inputs["UploadChunkSize"] = "upload-chunk-size"; })(Inputs = exports.Inputs || (exports.Inputs = {})); @@ -37317,8 +37319,6 @@ function createTar(archiveFolder, sourceDirectories, compressionMethod) { ...getCompressionProgram(), '-cf', cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), - '--exclude', - cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), '-P', '-C', workingDirectory.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), @@ -46770,50 +46770,53 @@ const utils = __importStar(__webpack_require__(443)); process.on("uncaughtException", e => utils.logWarning(e.message)); function run() { return __awaiter(this, void 0, void 0, function* () { - try { - if (!utils.isCacheFeatureAvailable()) { - return; - } - if (!utils.isValidEvent()) { - utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported because it's not tied to a branch or tag ref.`); - return; - } - const state = utils.getCacheState(); - // Inputs are re-evaluted before the post action, so we want the original key used for restore - const primaryKey = core.getState(constants_1.State.CachePrimaryKey); - if (!primaryKey) { - utils.logWarning(`Error retrieving key from state.`); - return; - } - if (utils.isExactKeyMatch(primaryKey, state)) { - core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`); - return; - } - const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, { - required: true - }); + const save = !core.getBooleanInput(constants_1.Inputs.OnlyRestore); + if (save) { try { - yield cache.saveCache(cachePaths, primaryKey, { - uploadChunkSize: utils.getInputAsInt(constants_1.Inputs.UploadChunkSize) + if (!utils.isCacheFeatureAvailable()) { + return; + } + if (!utils.isValidEvent()) { + utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported because it's not tied to a branch or tag ref.`); + return; + } + const state = utils.getCacheState(); + // Inputs are re-evaluted before the post action, so we want the original key used for restore + const primaryKey = core.getState(constants_1.State.CachePrimaryKey); + if (!primaryKey) { + utils.logWarning(`Error retrieving key from state.`); + return; + } + if (utils.isExactKeyMatch(primaryKey, state)) { + core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`); + return; + } + const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, { + required: true }); - core.info(`Cache saved with key: ${primaryKey}`); + try { + yield cache.saveCache(cachePaths, primaryKey, { + uploadChunkSize: utils.getInputAsInt(constants_1.Inputs.UploadChunkSize) + }); + core.info(`Cache saved with key: ${primaryKey}`); + } + catch (error) { + const typedError = error; + if (typedError.name === cache.ValidationError.name) { + throw error; + } + else if (typedError.name === cache.ReserveCacheError.name) { + core.info(typedError.message); + } + else { + utils.logWarning(typedError.message); + } + } } catch (error) { - const typedError = error; - if (typedError.name === cache.ValidationError.name) { - throw error; - } - else if (typedError.name === cache.ReserveCacheError.name) { - core.info(typedError.message); - } - else { - utils.logWarning(typedError.message); - } + utils.logWarning(error.message); } } - catch (error) { - utils.logWarning(error.message); - } }); } run();