Skip to content

Commit afbd217

Browse files
committed
wip: adds tag support
1 parent 81cc097 commit afbd217

File tree

4 files changed

+67
-11
lines changed

4 files changed

+67
-11
lines changed

blueprint/schema/_embed/schema.cue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,13 @@ package schema
142142
}
143143
version: "1.0"
144144
#Tagging: {
145-
// Strategy contains the tagging strategy to use.
145+
// Aliases contains the aliases to use for git tags.
146+
// +optional
147+
aliases?: {
148+
[string]: string
149+
} @go(Aliases,map[string]string)
150+
151+
// Strategy contains the tagging strategy to use for containers.
146152
strategy: "commit" @go(Strategy)
147153
}
148154

blueprint/schema/schema.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,11 @@ type Secret struct {
147147
}
148148

149149
type Tagging struct {
150-
// Strategy contains the tagging strategy to use.
150+
// Aliases contains the aliases to use for git tags.
151+
// +optional
152+
Aliases map[string]string `json:"aliases"`
153+
154+
// Strategy contains the tagging strategy to use for containers.
151155
Strategy string `json:"strategy"`
152156
}
153157

blueprint/schema/schema_go_gen.cue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,11 @@ package schema
141141
}
142142

143143
#Tagging: {
144-
// Strategy contains the tagging strategy to use.
144+
// Aliases contains the aliases to use for git tags.
145+
// +optional
146+
aliases?: {[string]: string} @go(Aliases,map[string]string)
147+
148+
// Strategy contains the tagging strategy to use for containers.
145149
strategy: string @go(Strategy)
146150
}
147151

forge/actions/publish/src/main.js

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,49 @@ async function run() {
3636
return;
3737
}
3838

39+
const tags = [];
40+
const gitTag = parseGitTag(process.env.GITHUB_REF);
41+
if (gitTag !== "") {
42+
core.info(`Detected Git tag: ${gitTag}`);
43+
44+
parts = gitTag.split("/");
45+
if (parts.lenth > 1) {
46+
const path = parts.slice(0, -1).join("/");
47+
const tag = parts[parts.length - 1];
48+
const projectCleaned = project.trimStart(".").trimEnd("/");
49+
50+
core.info(`Detected mono-repo tag path=${path} tag=${tag}`);
51+
if (Object.keys(blueprint?.global?.ci?.tagging?.aliases) !== undefined) {
52+
if (blueprint.global.ci.tagging.aliases[path] === projectCleaned) {
53+
tags.push(tag);
54+
}
55+
} else if (path === projectCleaned) {
56+
tags.push(tag);
57+
} else {
58+
core.info(`Skipping tag as it does not match the project path`);
59+
}
60+
} else {
61+
core.info("Detected non mono-repo tag. Using tag as is.");
62+
tags.push(gitTag);
63+
}
64+
} else {
65+
core.info("No Git tag detected");
66+
}
67+
3968
const container = blueprint.project.container;
4069
const registries = blueprint.global.ci.registries;
41-
const tag = getTag(blueprint.global.ci.tagging.strategy);
42-
43-
core.info(`Ref: ${process.env.GITHUB_REF}`);
70+
tags.push(getTag(blueprint.global.ci.tagging.strategy));
4471

4572
for (const registry of registries) {
46-
const taggedImage = `${registry}/${container}:${tag}`;
73+
for (const tag of tags) {
74+
const taggedImage = `${registry}/${container}:${tag}`;
4775

48-
core.info(`Tagging image ${image} as ${taggedImage}`);
49-
await tagImage(image, taggedImage);
76+
core.info(`Tagging image ${image} as ${taggedImage}`);
77+
await tagImage(image, taggedImage);
5078

51-
core.info(`Pushing image ${taggedImage}`);
52-
//await pushImage(taggedImage);
79+
core.info(`Pushing image ${taggedImage}`);
80+
//await pushImage(taggedImage);
81+
}
5382
}
5483
} catch (error) {
5584
core.setFailed(error.message);
@@ -106,6 +135,19 @@ async function imageExists(name) {
106135
return result === 0;
107136
}
108137

138+
/**
139+
* Parse a Git tag from a ref. If the ref is not a tag, an empty string is returned.
140+
* @param {string} ref The ref to parse
141+
* @returns {string} The tag or an empty string
142+
*/
143+
function parseGitTag(ref) {
144+
if (ref.startsWith("refs/tags/")) {
145+
return ref.slice(10);
146+
} else {
147+
return "";
148+
}
149+
}
150+
109151
/***
110152
* Push a Docker image to a registry
111153
*/

0 commit comments

Comments
 (0)