Skip to content

Commit

Permalink
wip: testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgilman committed Sep 10, 2024
1 parent aa7d2d5 commit 901257e
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 34 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ jobs:
uses: ./forge/actions/publish
with:
image: "${{ env.CONTAINER }}:${{ env.TAG }}"
project: ${{ steps.parse.outputs.project }}
project: ${{ steps.parse.outputs.project }}
target: ${{ steps.parse.outputs.target }}
3 changes: 3 additions & 0 deletions forge/actions/publish/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ inputs:
description: If true, will always publish images, even on pushes to the non-default branch
required: false
default: "false"
target:
description: The Earthly target that was run
required: true

runs:
using: node20
Expand Down
55 changes: 39 additions & 16 deletions forge/actions/publish/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30441,20 +30441,47 @@ const github = __nccwpck_require__(5438);

async function run() {
try {
const project = core.getInput("project", { required: true });
const image = core.getInput("image", { required: true });
const project = core.getInput("project");
const image = core.getInput("image");
const skip_branch_check = core.getBooleanInput("skip_branch_check");
const target = core.getInput("target");

const exists = await imageExists(image);
if (!exists) {
core.error(
`Unable to find image '${image}' in the local Docker daemon. Did you add a 'container' and 'tag' argument to your target?`,
{
file: `${project}/Earthfile`,
},
const blueprint = await getBlueprint(project);
const targetConfig = blueprint.project?.ci?.targets?.[target];
let platforms = [];
if (
targetConfig !== undefined &&
targetConfig.platforms !== undefined &&
targetConfig.platforms.length > 0
) {
core.info(
`Detected multi-platform build for platforms: ${targetConfig.platforms.join(", ")}`,
);
core.setFailed(`Unable to find image: ${image}`);
return;
platforms = targetConfig.platforms;
}

const images = {};
if (platforms.length > 0) {
for (const platform of platforms) {
images[platform] = `${image}_${platform.replace("/", "_")}`;
}
} else {
images["default"] = image;
}

for (const image in images) {
core.info(`Validating image ${image} exists`);
const exists = await imageExists(image);
if (!exists) {
core.error(
`Unable to find image '${image}' in the local Docker daemon. Did you add a 'container' and 'tag' argument to your target?`,
{
file: `${project}/Earthfile`,
},
);
core.setFailed(`Unable to find image: ${image}`);
return;
}
}

const currentBranch = github.context.ref.replace("refs/heads/", "");
Expand All @@ -30464,8 +30491,6 @@ async function run() {
return;
}

const blueprint = await getBlueprint(project);

if (blueprint?.project?.container === undefined) {
core.warning(
`Project '${project}' does not have a container defined. Skipping publish`,
Expand All @@ -30476,7 +30501,7 @@ async function run() {
blueprint?.global?.ci?.registries.length === 0
) {
core.warning(
`The repository does not have any registries defined. Skipping publish`,
`The repository does not have any container registries defined. Skipping publish`,
);
return;
}
Expand Down Expand Up @@ -30548,8 +30573,6 @@ async function imageExists(name) {
silent: true,
});

console.log(`Result: ${result}`);

return result === 0;
}

Expand Down
2 changes: 1 addition & 1 deletion forge/actions/publish/dist/index.js.map

Large diffs are not rendered by default.

55 changes: 39 additions & 16 deletions forge/actions/publish/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,47 @@ const github = require("@actions/github");

async function run() {
try {
const project = core.getInput("project", { required: true });
const image = core.getInput("image", { required: true });
const project = core.getInput("project");
const image = core.getInput("image");
const skip_branch_check = core.getBooleanInput("skip_branch_check");
const target = core.getInput("target");

const exists = await imageExists(image);
if (!exists) {
core.error(
`Unable to find image '${image}' in the local Docker daemon. Did you add a 'container' and 'tag' argument to your target?`,
{
file: `${project}/Earthfile`,
},
const blueprint = await getBlueprint(project);
const targetConfig = blueprint.project?.ci?.targets?.[target];
let platforms = [];
if (
targetConfig !== undefined &&
targetConfig.platforms !== undefined &&
targetConfig.platforms.length > 0
) {
core.info(
`Detected multi-platform build for platforms: ${targetConfig.platforms.join(", ")}`,
);
core.setFailed(`Unable to find image: ${image}`);
return;
platforms = targetConfig.platforms;
}

const images = {};
if (platforms.length > 0) {
for (const platform of platforms) {
images[platform] = `${image}_${platform.replace("/", "_")}`;
}
} else {
images["default"] = image;
}

for (const image in images) {
core.info(`Validating image ${image} exists`);
const exists = await imageExists(image);
if (!exists) {
core.error(
`Unable to find image '${image}' in the local Docker daemon. Did you add a 'container' and 'tag' argument to your target?`,
{
file: `${project}/Earthfile`,
},
);
core.setFailed(`Unable to find image: ${image}`);
return;
}
}

const currentBranch = github.context.ref.replace("refs/heads/", "");
Expand All @@ -27,8 +54,6 @@ async function run() {
return;
}

const blueprint = await getBlueprint(project);

if (blueprint?.project?.container === undefined) {
core.warning(
`Project '${project}' does not have a container defined. Skipping publish`,
Expand All @@ -39,7 +64,7 @@ async function run() {
blueprint?.global?.ci?.registries.length === 0
) {
core.warning(
`The repository does not have any registries defined. Skipping publish`,
`The repository does not have any container registries defined. Skipping publish`,
);
return;
}
Expand Down Expand Up @@ -111,8 +136,6 @@ async function imageExists(name) {
silent: true,
});

console.log(`Result: ${result}`);

return result === 0;
}

Expand Down
3 changes: 3 additions & 0 deletions forge/cli/blueprint.cue
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
version: "1.0"
project: {
name: "forge"
ci: targets: {
publish: platforms: ["linux/amd64", "linux/arm64"]
}
}

0 comments on commit 901257e

Please sign in to comment.