Skip to content

Commit

Permalink
refactor: simplifies tagging (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgilman authored Oct 22, 2024
1 parent 64d5f7e commit 6ab15e2
Show file tree
Hide file tree
Showing 37 changed files with 389 additions and 793 deletions.
7 changes: 4 additions & 3 deletions actions/install/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33070,7 +33070,8 @@ const core = __nccwpck_require__(2186);
const github = __nccwpck_require__(5438);
const tc = __nccwpck_require__(7784);

const projectName = "cli";
const assetPrefix = "forge-cli";
const releaseName = "forge-cli";
const repoOwner = "input-output-hk";
const repoName = "catalyst-forge";

Expand Down Expand Up @@ -33139,7 +33140,7 @@ function getAssetName() {
throw new Error(`Unsupported platform: ${platform}`);
}

return `${projectName}-${platformSuffix}.tar.gz`;
return `${assetPrefix}-${platformSuffix}.tar.gz`;
}

/**
Expand Down Expand Up @@ -33187,7 +33188,7 @@ async function getVersionedAsset(octokit, version) {
const releases = await getReleases(octokit);

const targetRelease = releases.find(
(r) => r.tag_name === `${projectName}/v${version}`,
(r) => r.tag_name === `${releaseName}/v${version}`,
);
if (!targetRelease) {
throw new Error(`Version ${version} not found`);
Expand Down
2 changes: 1 addition & 1 deletion actions/install/dist/index.js.map

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions actions/install/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const core = require("@actions/core");
const github = require("@actions/github");
const tc = require("@actions/tool-cache");

const projectName = "cli";
const assetPrefix = "forge-cli";
const releaseName = "forge-cli";
const repoOwner = "input-output-hk";
const repoName = "catalyst-forge";

Expand Down Expand Up @@ -71,7 +72,7 @@ function getAssetName() {
throw new Error(`Unsupported platform: ${platform}`);
}

return `${projectName}-${platformSuffix}.tar.gz`;
return `${assetPrefix}-${platformSuffix}.tar.gz`;
}

/**
Expand Down Expand Up @@ -119,7 +120,7 @@ async function getVersionedAsset(octokit, version) {
const releases = await getReleases(octokit);

const targetRelease = releases.find(
(r) => r.tag_name === `${projectName}/v${version}`,
(r) => r.tag_name === `${releaseName}/v${version}`,
);
if (!targetRelease) {
throw new Error(`Version ${version} not found`);
Expand Down
8 changes: 0 additions & 8 deletions blueprint.cue
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ global: {
"^build(-.*)?$",
"^package(-.*)?$",
"^test(-.*)?$",
"^release(-.*)?$",
"^publish(-.*)?$",
]
registries: [
ci.providers.aws.registry,
Expand Down Expand Up @@ -49,12 +47,6 @@ global: {
path: "GITHUB_TOKEN"
},
]
tagging: {
aliases: {
forge: "cli"
}
strategy: "commit"
}
}
deployment: {
registry: ci.providers.aws.registry
Expand Down
22 changes: 0 additions & 22 deletions cli/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,3 @@ github:
--version=$version) bin/forge

SAVE ARTIFACT bin/forge forge

docker:
FROM debian:bookworm-slim
WORKDIR /workspace

ARG container="forge"
ARG tag="latest"
ARG version="dev"

ARG TARGETOS
ARG TARGETARCH
ARG USERPLATFORM

COPY \
--platform=$USERPLATFORM \
(+build/forge \
--GOOS=$TARGETOS \
--GOARCH=$TARGETARCH \
--version=$version) /usr/local/bin/forge

ENTRYPOINT ["/usr/local/bin/forge"]
SAVE IMAGE ${container}:${tag}
20 changes: 3 additions & 17 deletions cli/blueprint.cue
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
version: "1.0"
project: {
name: "forge"
name: "forge-cli"
ci: targets: {
docker: {
args: {
version: string | *"dev" @forge(name="GIT_TAG")
}
platforms: [
"linux/amd64",
"linux/arm64",
]
}
github: {
args: {
version: string | *"dev" @forge(name="GIT_TAG")
Expand All @@ -25,16 +16,11 @@ project: {
test: retries: 3
}
release: {
docker: {
on: {
merge: {}
tag: {}
}
config: {}
}
github: {
on: tag: {}
config: {
name: string | *"dev" @forge(name="GIT_TAG")
prefix: project.name
token: {
provider: "env"
path: "GITHUB_TOKEN"
Expand Down
53 changes: 0 additions & 53 deletions cli/cmd/cmds/tag.go

This file was deleted.

1 change: 0 additions & 1 deletion cli/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ var cli struct {
Run cmds.RunCmd `kong:"cmd" help:"Run an Earthly target."`
Scan cmds.ScanCmd `kong:"cmd" help:"Scan for Earthfiles."`
Secret cmds.SecretCmd `kong:"cmd" help:"Manage secrets."`
Tag cmds.TagCmd `kong:"cmd" help:"Generate a tag for a project."`
Validate cmds.ValidateCmd `kong:"cmd" help:"Validates a project."`
Version VersionCmd `kong:"cmd" help:"Print the version."`

Expand Down
3 changes: 3 additions & 0 deletions cli/cmd/testdata/run/1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ test
Image ./dir1+test output as test
-- earthly_stdout.txt --
Image ./dir1+test output as test
-- dir1/blueprint.cue --
version: "1.0.0"
project: name: "dir1"
-- dir1/Earthfile --
VERSION 0.8

Expand Down
3 changes: 3 additions & 0 deletions cli/cmd/testdata/run/2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Artifact ./dir1+test output as test
-- earthly_stdout.txt --
Image ./dir1+test output as test
Artifact ./dir1+test output as test
-- dir1/blueprint.cue --
version: "1.0.0"
project: name: "dir1"
-- dir1/Earthfile --
VERSION 0.8

Expand Down
3 changes: 3 additions & 0 deletions cli/cmd/testdata/run/3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ Artifact ./dir1+test output as test
-- earthly_stdout.txt --
Image ./dir1+test output as test
Artifact ./dir1+test output as test
-- dir1/blueprint.cue --
version: "1.0.0"
project: name: "dir1"
-- dir1/Earthfile --
VERSION 0.8

Expand Down
3 changes: 3 additions & 0 deletions cli/cmd/testdata/run/4.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ Artifact ./dir1+test output as test
-- earthly_stdout.txt --
Image ./dir1+test output as test
Artifact ./dir1+test output as test
-- dir1/blueprint.cue --
version: "1.0.0"
project: name: "dir1"
-- dir1/Earthfile --
VERSION 0.8

Expand Down
4 changes: 3 additions & 1 deletion cli/cmd/testdata/scan/1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ cmp stdout golden.txt
["./dir1","./dir2"]
-- dir1/blueprint.cue --
version: "1.0"
project: name: "dir1"
-- dir2/blueprint.cue --
version: "1.0"
version: "1.0"
project: name: "dir2"
1 change: 1 addition & 0 deletions cli/cmd/testdata/scan/2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ cmpenv stdout golden_2_ci.txt
["$WORK+bar","$WORK+foo"]
-- blueprint.cue --
version: "1.0"
project: name: "foo"
-- Earthfile --
VERSION 0.7

Expand Down
7 changes: 5 additions & 2 deletions cli/cmd/testdata/scan/3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ exec forge --ci scan --earthfile .
cmp stdout golden_ci.txt

-- golden.txt --
{".":["foo","bar"],"./dir1":["foo","bar"],"./dir1/dir2":["foo","bar"],"./dir3/dir4/dir5":["foo"]}
{"./dir1":["foo","bar"],"./dir1/dir2":["foo","bar"],"./dir3/dir4/dir5":["foo"]}
-- golden_ci.txt --
[".+bar",".+foo","./dir1+bar","./dir1+foo","./dir1/dir2+bar","./dir1/dir2+foo","./dir3/dir4/dir5+foo"]
["./dir1+bar","./dir1+foo","./dir1/dir2+bar","./dir1/dir2+foo","./dir3/dir4/dir5+foo"]
-- blueprint.cue --
version: "1.0"
-- Earthfile --
Expand All @@ -22,6 +22,7 @@ bar:
LET bar = baz
-- dir1/blueprint.cue --
version: "1.0"
project: name: "dir1"
-- dir1/Earthfile --
VERSION 0.7

Expand All @@ -32,6 +33,7 @@ bar:
LET bar = baz
-- dir1/dir2/blueprint.cue --
version: "1.0"
project: name: "dir1-dir2"
-- dir1/dir2/Earthfile --
VERSION 0.7

Expand All @@ -42,6 +44,7 @@ bar:
LET bar = baz
-- dir3/dir4/dir5/blueprint.cue --
version: "1.0"
project: name: "dir3-dir4-dir5"
-- dir3/dir4/dir5/Earthfile --
VERSION 0.7

Expand Down
19 changes: 2 additions & 17 deletions cli/pkg/events/tag.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,17 @@
package events

import (
"fmt"
"log/slog"

"cuelang.org/go/cue"
"github.com/input-output-hk/catalyst-forge/lib/project/project"
)

// TagEvent fires when a tag is pushed.
// TagEvent fires when a git tag is present.
type TagEvent struct {
logger *slog.Logger
}

func (t *TagEvent) Firing(p *project.Project, config cue.Value) (bool, error) {
if p.TagInfo == nil {
return false, fmt.Errorf("tag info not available")
}

if p.TagInfo.Git == "" {
t.logger.Debug("no git tag found")
return false, nil
}

matches, err := p.TagMatches()
if err != nil {
return false, fmt.Errorf("failed to check tag matches: %w", err)
}

return matches, nil
return p.Tag != nil, nil
}
34 changes: 10 additions & 24 deletions cli/pkg/events/tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,28 @@ import (
func TestTagEventFiring(t *testing.T) {
tests := []struct {
name string
tagInfo *project.TagInfo
tag *project.ProjectTag
projectPath string
gitRoot string
expected bool
expectErr bool
}{
{
name: "firing",
tagInfo: &project.TagInfo{
Git: "v1.0.0",
tag: &project.ProjectTag{
Full: "test/v1.0.0",
Project: "test",
Version: "v1.0.0",
},
expected: true,
expectErr: false,
},
{
name: "not firing",
tagInfo: &project.TagInfo{
Git: "foo/v1.0.0",
},
name: "not firing",
tag: nil,
expected: false,
expectErr: false,
},
{
name: "no git tag",
tagInfo: &project.TagInfo{
Git: "",
},
expected: false,
expectErr: false,
},
{
name: "no tag info",
tagInfo: nil,
expected: false,
expectErr: true,
},
}

for _, tt := range tests {
Expand All @@ -59,10 +45,10 @@ func TestTagEventFiring(t *testing.T) {
nil,
nil,
"test",
tt.projectPath,
tt.gitRoot,
"",
"",
schema.Blueprint{},
tt.tagInfo,
tt.tag,
)

event := TagEvent{
Expand Down
Loading

0 comments on commit 6ab15e2

Please sign in to comment.