-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from AkihiroSuda/dev
Avoid composite action
- Loading branch information
Showing
6 changed files
with
109 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Forked from https://github.com/pyTooling/Actions/blob/v0.4.6/with-post-step/main.js | ||
// The following copyright header is from the upstream. | ||
|
||
/* ================================================================================================================== * | ||
* Authors: * | ||
* Unai Martinez-Corral * | ||
* * | ||
* ================================================================================================================== * | ||
* Copyright 2021-2022 Unai Martinez-Corral <[email protected]> * | ||
* Copyright 2022 Unai Martinez-Corral <[email protected]> * | ||
* * | ||
* 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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <<EOF | ||
FROM busybox:1 | ||
COPY buildstamp buildstamp | ||
RUN --mount=type=cache,target="$(./read-action-input cache-target)" \ | ||
--mount=type=bind,source=.,target=/var/dance-cache \ | ||
cp -p -R /var/dance-cache/. "$(./read-action-input cache-target)" || true | ||
EOF | ||
cat "$(./read-action-input scratch-dir)"/Dancefile.inject | ||
: "Inject Data into Docker Cache" | ||
docker buildx build -f "$(./read-action-input scratch-dir)"/Dancefile.inject --tag dance:inject "$(./read-action-input cache-source)" | ||
: "Clean Directories" | ||
sudo rm -rf "$(./read-action-input cache-source)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
set -eux -o pipefail | ||
: "Argv0: $0" | ||
: "Prepare Timestamp for Layer Cache Busting" | ||
date --iso=ns | tee "$(./read-action-input scratch-dir)"/buildstamp | ||
: "Prepare Dancefile to Access Caches" | ||
cat >"$(./read-action-input scratch-dir)"/Dancefile.extract <<EOF | ||
FROM busybox:1 | ||
COPY buildstamp buildstamp | ||
RUN --mount=type=cache,target="$(./read-action-input cache-target)" \ | ||
mkdir -p /var/dance-cache/ \ | ||
&& cp -p -R "$(./read-action-input cache-target)"/. /var/dance-cache/ || true | ||
EOF | ||
cat "$(./read-action-input scratch-dir)"/Dancefile.extract | ||
: "Extract Data into Docker Image" | ||
docker buildx build -f "$(./read-action-input scratch-dir)"/Dancefile.extract --tag dance:extract --load "$(./read-action-input scratch-dir)" | ||
: "Create Extraction Image" | ||
docker rm -f cache-container && docker create -ti --name cache-container dance:extract | ||
: "Unpack Docker Image into Scratch" | ||
docker cp -L cache-container:/var/dance-cache - | tar -H posix -x -C "$(./read-action-input scratch-dir)" | ||
: "Move Cache into Its Place" | ||
sudo rm -rf "$(./read-action-input cache-source)" | ||
mv "$(./read-action-input scratch-dir)"/dance-cache "$(./read-action-input cache-source)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env node | ||
// helper script for printing kebab-cased env vars. | ||
// e.g., "foo-bar" -> "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); | ||
} |