diff --git a/README.md b/README.md index 1b20a8c..2114250 100644 --- a/README.md +++ b/README.md @@ -71,4 +71,4 @@ Thanks to [Alexander Pravdin](https://github.com/speller) for the basic idea in v2.x unifies `reproducible-containers/buildkit-cache-dance/inject` and `reproducible-containers/buildkit-cache-dance/extract` into a single `reproducible-containers/buildkit-cache-dance` action. -However, v2.x seems unstable: [`[v2] "post" steps are executed in a random order`](https://github.com/reproducible-containers/buildkit-cache-dance/issues/1) +v2.x is still experimental. diff --git a/action.yml b/action.yml index 61cbe94..4dbeae9 100644 --- a/action.yml +++ b/action.yml @@ -11,48 +11,6 @@ inputs: default: scratch description: "Where the action is stores some temporary files for its processing. Default: `scratch`" runs: - using: composite - steps: - - uses: pyTooling/Actions/with-post-step@adef08d3bdef092282614f3b683897cefae82ee3 # v0.4.6 - with: - main: |- - set -eux - # Clean Directories - rm -Rf ${{ inputs.scratch-dir }} && mkdir -p ${{ inputs.scratch-dir }} ${{ inputs.cache-source }} - # Prepare Timestamp for Layer Cache Busting - date --iso=ns | tee ${{ inputs.cache-source }}/buildstamp - # Prepare Dancefile to Access Caches - cat > ${{ inputs.scratch-dir }}/Dancefile.inject < ${{ inputs.scratch-dir }}/Dancefile.extract < * + * Copyright 2022 Unai Martinez-Corral * + * * + * Licensed under the Apache License, Version 2.0 (the "License"); * + * you may not use this file except in compliance with the License. * + * You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, software * + * distributed under the License is distributed on an "AS IS" BASIS, * + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * + * See the License for the specific language governing permissions and * + * limitations under the License. * + * * + * SPDX-License-Identifier: Apache-2.0 * + * ================================================================================================================== * + * * + * Context: * + * * https://github.com/docker/login-action/issues/72 * + * * https://github.com/actions/runner/issues/1478 * + * ================================================================================================================== */ +const { spawn } = require("child_process"); +const { appendFileSync } = require("fs"); +const { EOL } = require("os"); + +function run(cmd) { + const subprocess = spawn(cmd, { stdio: "inherit", shell: false }); + subprocess.on("exit", (exitCode) => { + process.exitCode = exitCode; + }); +} + +const key = "POST" + +if ( process.env[`STATE_${key}`] !== undefined ) { // Are we in the 'post' step? + run("./post"); +} else { // Otherwise, this is the main step + appendFileSync(process.env.GITHUB_STATE, `${key}=true${EOL}`); + run("./main"); +} diff --git a/main b/main new file mode 100755 index 0000000..c5c5587 --- /dev/null +++ b/main @@ -0,0 +1,20 @@ +#!/bin/bash +set -eux -o pipefail +: "Argv0: $0" +: "Clean Directories" +rm -Rf "$(./read-action-input scratch-dir)" && mkdir -p "$(./read-action-input scratch-dir)" "$(./read-action-input cache-source)" +: "Prepare Timestamp for Layer Cache Busting" +date --iso=ns | tee "$(./read-action-input cache-source)"/buildstamp +: "Prepare Dancefile to Access Caches" +cat >"$(./read-action-input scratch-dir)"/Dancefile.inject <"$(./read-action-input scratch-dir)"/Dancefile.extract < "INPUT_FOO-BAR". +// +// This does not need to be implemented in nodejs, +// but reimplementing this in sh is hard. + +const arg = process.argv[2]; // Equates to "$1" in sh +const k = "INPUT_" + arg.toUpperCase(); +const v = process.env[k]; +if ( v !== undefined ) { + console.log(v); +}