Skip to content

Commit a2e5d0a

Browse files
committed
feat: adds docs release type
1 parent 2f078ed commit a2e5d0a

File tree

8 files changed

+170
-28
lines changed

8 files changed

+170
-28
lines changed

.github/workflows/ci.yml

+11-11
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ jobs:
4141
steps:
4242
- uses: actions/checkout@v4
4343
- name: Install Forge
44-
uses: input-output-hk/catalyst-forge/actions/install@master
44+
uses: input-output-hk/catalyst-forge/actions/install@adds-docs-release
4545
if: ${{ inputs.forge_version != 'local' }}
4646
with:
4747
version: ${{ inputs.forge_version }}
4848
- name: Install Local Forge
49-
uses: input-output-hk/catalyst-forge/actions/install-local@master
49+
uses: input-output-hk/catalyst-forge/actions/install-local@adds-docs-release
5050
if: ${{ inputs.forge_version == 'local' }}
5151
with:
5252
earthly_token: ${{ secrets.earthly_token }}
@@ -61,14 +61,14 @@ jobs:
6161
echo "skip=false" >> $GITHUB_OUTPUT
6262
fi
6363
- name: Setup CI
64-
uses: input-output-hk/catalyst-forge/actions/setup@master
64+
uses: input-output-hk/catalyst-forge/actions/setup@adds-docs-release
6565
with:
6666
skip_docker: 'true'
6767
skip_github: 'true'
6868
skip_earthly: ${{ steps.local.outputs.skip }}
6969
- name: Discovery
7070
id: discovery
71-
uses: input-output-hk/catalyst-forge/actions/discovery@master
71+
uses: input-output-hk/catalyst-forge/actions/discovery@adds-docs-release
7272
with:
7373
filters: |
7474
${{ env.FORGE_REGEX_CHECK }}
@@ -80,7 +80,7 @@ jobs:
8080
${{ env.FORGE_REGEX_PUBLISH }}
8181
8282
check:
83-
uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master
83+
uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@adds-docs-release
8484
needs: [discover]
8585
if: (fromJson(needs.discover.outputs.earthfiles)['^check(-.*)?$'] != null) && !failure() && !cancelled()
8686
with:
@@ -92,7 +92,7 @@ jobs:
9292
earthly_token: ${{ secrets.earthly_token }}
9393

9494
build:
95-
uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master
95+
uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@adds-docs-release
9696
needs: [discover, check]
9797
if: (fromJson(needs.discover.outputs.earthfiles)['^build(-.*)?$'] != null) && !failure() && !cancelled()
9898
with:
@@ -104,7 +104,7 @@ jobs:
104104
earthly_token: ${{ secrets.earthly_token }}
105105

106106
package:
107-
uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master
107+
uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@adds-docs-release
108108
needs: [discover, check, build]
109109
if: (fromJson(needs.discover.outputs.earthfiles)['^package(-.*)?$'] != null) && !failure() && !cancelled()
110110
with:
@@ -116,7 +116,7 @@ jobs:
116116
earthly_token: ${{ secrets.earthly_token }}
117117

118118
test:
119-
uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master
119+
uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@adds-docs-release
120120
needs: [discover, check, build, package]
121121
if: (fromJson(needs.discover.outputs.earthfiles)['^test(-.*)?$'] != null) && !failure() && !cancelled()
122122
with:
@@ -128,7 +128,7 @@ jobs:
128128
earthly_token: ${{ secrets.earthly_token }}
129129

130130
docs:
131-
uses: input-output-hk/catalyst-forge/.github/workflows/docs.yml@master
131+
uses: input-output-hk/catalyst-forge/.github/workflows/docs.yml@adds-docs-release
132132
needs: [discover, check, build, test]
133133
if: (fromJson(needs.discover.outputs.earthfiles)['^docs(-.*)?$'] != null) && !failure() && !cancelled()
134134
with:
@@ -138,7 +138,7 @@ jobs:
138138
earthly_token: ${{ secrets.earthly_token }}
139139

140140
release:
141-
uses: input-output-hk/catalyst-forge/.github/workflows/release.yml@master
141+
uses: input-output-hk/catalyst-forge/.github/workflows/release.yml@adds-docs-release
142142
needs: [discover, check, build, test]
143143
if: (fromJson(needs.discover.outputs.releases)[0] != null) && !failure() && !cancelled()
144144
with:
@@ -150,7 +150,7 @@ jobs:
150150
earthly_token: ${{ secrets.earthly_token }}
151151

152152
deploy:
153-
uses: input-output-hk/catalyst-forge/.github/workflows/deploy.yml@master
153+
uses: input-output-hk/catalyst-forge/.github/workflows/deploy.yml@adds-docs-release
154154
needs: [discover, check, build, test, release]
155155
if: (fromJson(needs.discover.outputs.deployments)[0] != null) && github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && !failure() && !cancelled()
156156
with:

.github/workflows/deploy.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ jobs:
4141
steps:
4242
- uses: actions/checkout@v4
4343
- name: Install Forge
44-
uses: input-output-hk/catalyst-forge/actions/install@master
44+
uses: input-output-hk/catalyst-forge/actions/install@adds-docs-release
4545
if: ${{ inputs.forge_version != 'local' }}
4646
with:
4747
version: ${{ inputs.forge_version }}
4848
- name: Install Local Forge
49-
uses: input-output-hk/catalyst-forge/actions/install-local@master
49+
uses: input-output-hk/catalyst-forge/actions/install-local@adds-docs-release
5050
if: ${{ inputs.forge_version == 'local' }}
5151
with:
5252
earthly_token: ${{ secrets.earthly_token }}
@@ -61,11 +61,11 @@ jobs:
6161
echo "skip=false" >> $GITHUB_OUTPUT
6262
fi
6363
- name: Setup CI
64-
uses: input-output-hk/catalyst-forge/actions/setup@master
64+
uses: input-output-hk/catalyst-forge/actions/setup@adds-docs-release
6565
with:
6666
skip_earthly: ${{ steps.local.outputs.skip }}
6767
- name: Deploy
68-
uses: input-output-hk/catalyst-forge/actions/run@master
68+
uses: input-output-hk/catalyst-forge/actions/run@adds-docs-release
6969
with:
7070
command: deploy push
7171
args: ${{ matrix.deployment }}

.github/workflows/docs.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ jobs:
4444
steps:
4545
- uses: actions/checkout@v4
4646
- name: Install Forge
47-
uses: input-output-hk/catalyst-forge/actions/install@master
47+
uses: input-output-hk/catalyst-forge/actions/install@adds-docs-release
4848
if: ${{ inputs.forge_version != 'local' }}
4949
with:
5050
version: ${{ inputs.forge_version }}
5151
- name: Install Local Forge
52-
uses: input-output-hk/catalyst-forge/actions/install-local@master
52+
uses: input-output-hk/catalyst-forge/actions/install-local@adds-docs-release
5353
if: ${{ inputs.forge_version == 'local' }}
5454
with:
5555
earthly_token: ${{ secrets.earthly_token }}
@@ -64,11 +64,11 @@ jobs:
6464
echo "skip=false" >> $GITHUB_OUTPUT
6565
fi
6666
- name: Setup CI
67-
uses: input-output-hk/catalyst-forge/actions/setup@master
67+
uses: input-output-hk/catalyst-forge/actions/setup@adds-docs-release
6868
with:
6969
skip_earthly: ${{ steps.local.outputs.skip }}
7070
- name: Run
71-
uses: input-output-hk/catalyst-forge/actions/run@master
71+
uses: input-output-hk/catalyst-forge/actions/run@adds-docs-release
7272
with:
7373
command: run
7474
args: --artifact ${{ env.OUTPUT }} ${{ matrix.earthfile }}

.github/workflows/release.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ jobs:
4545
steps:
4646
- uses: actions/checkout@v4
4747
- name: Install Forge
48-
uses: input-output-hk/catalyst-forge/actions/install@master
48+
uses: input-output-hk/catalyst-forge/actions/install@adds-docs-release
4949
if: ${{ inputs.forge_version != 'local' }}
5050
with:
5151
version: ${{ inputs.forge_version }}
5252
- name: Install Local Forge
53-
uses: input-output-hk/catalyst-forge/actions/install-local@master
53+
uses: input-output-hk/catalyst-forge/actions/install-local@adds-docs-release
5454
if: ${{ inputs.forge_version == 'local' }}
5555
with:
5656
earthly_token: ${{ secrets.earthly_token }}
@@ -65,11 +65,11 @@ jobs:
6565
echo "skip=false" >> $GITHUB_OUTPUT
6666
fi
6767
- name: Setup CI
68-
uses: input-output-hk/catalyst-forge/actions/setup@master
68+
uses: input-output-hk/catalyst-forge/actions/setup@adds-docs-release
6969
with:
7070
skip_earthly: ${{ steps.local.outputs.skip }}
7171
- name: Release
72-
uses: input-output-hk/catalyst-forge/actions/run@master
72+
uses: input-output-hk/catalyst-forge/actions/run@adds-docs-release
7373
with:
7474
command: release
7575
args: ${{ matrix.release.project }} ${{ matrix.release.name }}

.github/workflows/run.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ jobs:
4242
steps:
4343
- uses: actions/checkout@v4
4444
- name: Install Forge
45-
uses: input-output-hk/catalyst-forge/actions/install@master
45+
uses: input-output-hk/catalyst-forge/actions/install@adds-docs-release
4646
if: ${{ inputs.forge_version != 'local' }}
4747
with:
4848
version: ${{ inputs.forge_version }}
4949
- name: Install Local Forge
50-
uses: input-output-hk/catalyst-forge/actions/install-local@master
50+
uses: input-output-hk/catalyst-forge/actions/install-local@adds-docs-release
5151
if: ${{ inputs.forge_version == 'local' }}
5252
with:
5353
earthly_token: ${{ secrets.earthly_token }}
@@ -62,11 +62,11 @@ jobs:
6262
echo "skip=false" >> $GITHUB_OUTPUT
6363
fi
6464
- name: Setup CI
65-
uses: input-output-hk/catalyst-forge/actions/setup@master
65+
uses: input-output-hk/catalyst-forge/actions/setup@adds-docs-release
6666
with:
6767
skip_earthly: ${{ steps.local.outputs.skip }}
6868
- name: Run
69-
uses: input-output-hk/catalyst-forge/actions/run@master
69+
uses: input-output-hk/catalyst-forge/actions/run@adds-docs-release
7070
with:
7171
command: run
7272
args: ${{ matrix.earthfile }}

cli/pkg/release/providers/docs.go

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
package providers
2+
3+
import (
4+
"fmt"
5+
"log/slog"
6+
"path/filepath"
7+
8+
"github.com/input-output-hk/catalyst-forge/cli/pkg/earthly"
9+
"github.com/input-output-hk/catalyst-forge/cli/pkg/events"
10+
"github.com/input-output-hk/catalyst-forge/cli/pkg/run"
11+
"github.com/input-output-hk/catalyst-forge/lib/project/project"
12+
"github.com/input-output-hk/catalyst-forge/lib/project/schema"
13+
"github.com/input-output-hk/catalyst-forge/lib/project/secrets"
14+
"github.com/spf13/afero"
15+
)
16+
17+
type DocsReleaserConfig struct {
18+
Token schema.Secret `json:"token"`
19+
}
20+
21+
type DocsReleaser struct {
22+
config DocsReleaserConfig
23+
force bool
24+
fs afero.Fs
25+
handler events.EventHandler
26+
logger *slog.Logger
27+
project project.Project
28+
release schema.Release
29+
releaseName string
30+
runner run.ProjectRunner
31+
token string
32+
workdir string
33+
}
34+
35+
func (r *DocsReleaser) Release() error {
36+
r.logger.Info("Running release target", "project", r.project.Name, "target", r.release.Target, "dir", r.workdir)
37+
if err := r.run(r.workdir); err != nil {
38+
return fmt.Errorf("failed to run release target: %w", err)
39+
}
40+
41+
if err := r.validateArtifacts(r.workdir); err != nil {
42+
return fmt.Errorf("failed to validate artifacts: %w", err)
43+
}
44+
45+
if !r.handler.Firing(&r.project, r.project.GetReleaseEvents(r.releaseName)) && !r.force {
46+
r.logger.Info("No release event is firing, skipping release")
47+
return nil
48+
}
49+
50+
return nil
51+
}
52+
53+
// run runs the release target.
54+
func (r *DocsReleaser) run(path string) error {
55+
return r.runner.RunTarget(
56+
r.release.Target,
57+
earthly.WithArtifact(path),
58+
)
59+
}
60+
61+
func (r *DocsReleaser) validateArtifacts(path string) error {
62+
r.logger.Info("Validating artifacts")
63+
path = filepath.Join(path, earthly.GetBuildPlatform())
64+
exists, err := afero.DirExists(r.fs, path)
65+
if err != nil {
66+
return fmt.Errorf("failed to check if output folder exists: %w", err)
67+
} else if !exists {
68+
return fmt.Errorf("unable to find output folder for platform: %s", path)
69+
}
70+
71+
children, err := afero.ReadDir(r.fs, path)
72+
if err != nil {
73+
return fmt.Errorf("failed to read output folder: %w", err)
74+
}
75+
76+
if len(children) == 0 {
77+
return fmt.Errorf("no artifacts found")
78+
}
79+
80+
return nil
81+
}
82+
83+
func NewDocsReleaser(
84+
ctx run.RunContext,
85+
project project.Project,
86+
name string,
87+
force bool,
88+
) (*DocsReleaser, error) {
89+
release, ok := project.Blueprint.Project.Release[name]
90+
if !ok {
91+
return nil, fmt.Errorf("unknown release: %s", name)
92+
}
93+
94+
var config DocsReleaserConfig
95+
if err := parseConfig(&project, name, &config); err != nil {
96+
return nil, fmt.Errorf("failed to parse release config: %w", err)
97+
}
98+
99+
token, err := secrets.GetSecret(&config.Token, &ctx.SecretStore, ctx.Logger)
100+
if err != nil {
101+
return nil, fmt.Errorf("failed to get GitHub token: %w", err)
102+
}
103+
104+
fs := afero.NewOsFs()
105+
workdir, err := afero.TempDir(fs, "", "catalyst-forge-")
106+
if err != nil {
107+
return nil, fmt.Errorf("failed to create temporary directory: %w", err)
108+
}
109+
110+
handler := events.NewDefaultEventHandler(ctx.Logger)
111+
runner := run.NewDefaultProjectRunner(ctx, &project)
112+
return &DocsReleaser{
113+
config: config,
114+
force: force,
115+
fs: fs,
116+
handler: &handler,
117+
logger: ctx.Logger,
118+
project: project,
119+
release: release,
120+
releaseName: name,
121+
runner: &runner,
122+
token: token,
123+
workdir: workdir,
124+
}, nil
125+
}

cli/pkg/release/releaser.go

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type ReleaserType string
1212

1313
const (
1414
ReleaserTypeDocker ReleaserType = "docker"
15+
ReleaserTypeDocs ReleaserType = "docs"
1516
ReleaserTypeGithub ReleaserType = "github"
1617
ReleaserTypeTimoni ReleaserType = "timoni"
1718
)
@@ -47,6 +48,9 @@ func NewDefaultReleaserStore() *ReleaserStore {
4748
ReleaserTypeDocker: func(ctx run.RunContext, project project.Project, name string, force bool) (Releaser, error) {
4849
return providers.NewDockerReleaser(ctx, project, name, force)
4950
},
51+
ReleaserTypeDocs: func(ctx run.RunContext, project project.Project, name string, force bool) (Releaser, error) {
52+
return providers.NewDocsReleaser(ctx, project, name, force)
53+
},
5054
ReleaserTypeGithub: func(ctx run.RunContext, project project.Project, name string, force bool) (Releaser, error) {
5155
return providers.NewGithubReleaser(ctx, project, name, force)
5256
},

docs/blueprint.cue

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,15 @@
11
version: "1.0.0"
2-
project: name: "forge-docs"
2+
project: {
3+
name: "forge-docs"
4+
release: {
5+
docs: {
6+
on: merge: {}
7+
config: {
8+
token: {
9+
provider: "env"
10+
path: "GITHUB_TOKEN"
11+
}
12+
}
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)