From 61e025e67cc443d4a1ec527e99f31adf47dcde4d Mon Sep 17 00:00:00 2001 From: Joshua Gilman Date: Thu, 24 Jul 2025 21:36:54 -0700 Subject: [PATCH 1/4] refactor(cli): always use branches for docs --- .github/workflows/ci.yml | 163 ++++++++++---------- cli/pkg/release/providers/docs.go | 33 +++-- cli/pkg/release/providers/docs_test.go | 197 +++++++++++++------------ 3 files changed, 205 insertions(+), 188 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b1fe086..15a6d261 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -75,69 +75,70 @@ jobs: ${{ env.FORGE_REGEX_RELEASE }} ${{ env.FORGE_REGEX_PUBLISH }} ${{ env.FORGE_REGEX_NIGHTLY }} - check: - uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master - needs: [discover] - if: (fromJson(needs.discover.outputs.earthfiles)['^check(-.*)?$'] != null) && !failure() && !cancelled() - with: - earthfiles: ${{ toJson(fromJson(needs.discover.outputs.earthfiles)['^check(-.*)?$']) }} - forge_version: ${{ inputs.forge_version }} - local: ${{ inputs.local }} - verbosity: ${{ inputs.verbosity }} - secrets: - earthly_token: ${{ secrets.earthly_token }} + # check: + # uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master + # needs: [discover] + # if: (fromJson(needs.discover.outputs.earthfiles)['^check(-.*)?$'] != null) && !failure() && !cancelled() + # with: + # earthfiles: ${{ toJson(fromJson(needs.discover.outputs.earthfiles)['^check(-.*)?$']) }} + # forge_version: ${{ inputs.forge_version }} + # local: ${{ inputs.local }} + # verbosity: ${{ inputs.verbosity }} + # secrets: + # earthly_token: ${{ secrets.earthly_token }} - build: - uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master - needs: [discover, check] - if: (fromJson(needs.discover.outputs.earthfiles)['^build(-.*)?$'] != null) && !failure() && !cancelled() - with: - earthfiles: ${{ toJson(fromJson(needs.discover.outputs.earthfiles)['^build(-.*)?$']) }} - forge_version: ${{ inputs.forge_version }} - local: ${{ inputs.local }} - verbosity: ${{ inputs.verbosity }} - secrets: - earthly_token: ${{ secrets.earthly_token }} + # build: + # uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master + # needs: [discover, check] + # if: (fromJson(needs.discover.outputs.earthfiles)['^build(-.*)?$'] != null) && !failure() && !cancelled() + # with: + # earthfiles: ${{ toJson(fromJson(needs.discover.outputs.earthfiles)['^build(-.*)?$']) }} + # forge_version: ${{ inputs.forge_version }} + # local: ${{ inputs.local }} + # verbosity: ${{ inputs.verbosity }} + # secrets: + # earthly_token: ${{ secrets.earthly_token }} - package: - uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master - needs: [discover, check, build] - if: (fromJson(needs.discover.outputs.earthfiles)['^package(-.*)?$'] != null) && !failure() && !cancelled() - with: - earthfiles: ${{ toJson(fromJson(needs.discover.outputs.earthfiles)['^package(-.*)?$']) }} - forge_version: ${{ inputs.forge_version }} - local: ${{ inputs.local }} - verbosity: ${{ inputs.verbosity }} - secrets: - earthly_token: ${{ secrets.earthly_token }} + # package: + # uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master + # needs: [discover, check, build] + # if: (fromJson(needs.discover.outputs.earthfiles)['^package(-.*)?$'] != null) && !failure() && !cancelled() + # with: + # earthfiles: ${{ toJson(fromJson(needs.discover.outputs.earthfiles)['^package(-.*)?$']) }} + # forge_version: ${{ inputs.forge_version }} + # local: ${{ inputs.local }} + # verbosity: ${{ inputs.verbosity }} + # secrets: + # earthly_token: ${{ secrets.earthly_token }} - test: - uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master - needs: [discover, check, build, package] - if: (fromJson(needs.discover.outputs.earthfiles)['^test(-.*)?$'] != null) && !failure() && !cancelled() - with: - earthfiles: ${{ toJson(fromJson(needs.discover.outputs.earthfiles)['^test(-.*)?$']) }} - forge_version: ${{ inputs.forge_version }} - local: ${{ inputs.local }} - verbosity: ${{ inputs.verbosity }} - secrets: - earthly_token: ${{ secrets.earthly_token }} + # test: + # uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master + # needs: [discover, check, build, package] + # if: (fromJson(needs.discover.outputs.earthfiles)['^test(-.*)?$'] != null) && !failure() && !cancelled() + # with: + # earthfiles: ${{ toJson(fromJson(needs.discover.outputs.earthfiles)['^test(-.*)?$']) }} + # forge_version: ${{ inputs.forge_version }} + # local: ${{ inputs.local }} + # verbosity: ${{ inputs.verbosity }} + # secrets: + # earthly_token: ${{ secrets.earthly_token }} - nightly: - uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master - needs: [discover, check, build, package] - if: (fromJson(needs.discover.outputs.earthfiles)['^nightly(-.*)?$'] != null) && !failure() && !cancelled() && inputs.nightly == true - with: - earthfiles: ${{ toJson(fromJson(needs.discover.outputs.earthfiles)['^nightly(-.*)?$']) }} - forge_version: ${{ inputs.forge_version }} - local: ${{ inputs.local }} - verbosity: ${{ inputs.verbosity }} - secrets: - earthly_token: ${{ secrets.earthly_token }} + # nightly: + # uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master + # needs: [discover, check, build, package] + # if: (fromJson(needs.discover.outputs.earthfiles)['^nightly(-.*)?$'] != null) && !failure() && !cancelled() && inputs.nightly == true + # with: + # earthfiles: ${{ toJson(fromJson(needs.discover.outputs.earthfiles)['^nightly(-.*)?$']) }} + # forge_version: ${{ inputs.forge_version }} + # local: ${{ inputs.local }} + # verbosity: ${{ inputs.verbosity }} + # secrets: + # earthly_token: ${{ secrets.earthly_token }} release: uses: input-output-hk/catalyst-forge/.github/workflows/release.yml@master - needs: [discover, check, build, test] + #needs: [discover, check, build, test] + needs: [discover] if: (fromJson(needs.discover.outputs.releases)[0] != null) && !failure() && !cancelled() with: releases: ${{ needs.discover.outputs.releases }} @@ -147,29 +148,29 @@ jobs: secrets: earthly_token: ${{ secrets.earthly_token }} - deploy: - uses: input-output-hk/catalyst-forge/.github/workflows/deploy.yml@master - needs: [discover, check, build, test, release] - if: (fromJson(needs.discover.outputs.deployments)[0] != null) && !failure() && !cancelled() - with: - deployments: ${{ needs.discover.outputs.deployments }} - forge_version: ${{ inputs.forge_version }} - local: ${{ inputs.local }} - verbosity: ${{ inputs.verbosity }} - secrets: - earthly_token: ${{ secrets.earthly_token }} + # deploy: + # uses: input-output-hk/catalyst-forge/.github/workflows/deploy.yml@master + # needs: [discover, check, build, test, release] + # if: (fromJson(needs.discover.outputs.deployments)[0] != null) && !failure() && !cancelled() + # with: + # deployments: ${{ needs.discover.outputs.deployments }} + # forge_version: ${{ inputs.forge_version }} + # local: ${{ inputs.local }} + # verbosity: ${{ inputs.verbosity }} + # secrets: + # earthly_token: ${{ secrets.earthly_token }} - final: - needs: [check, build, package, test, nightly, release, deploy] - if: ${{ always() && (contains(needs.*.result, 'failure') || !failure() && !cancelled()) }} - runs-on: ubuntu-latest - steps: - - name: Final - run: | - if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" ]] - then - echo "Run failed" - exit 1 - else - echo "All done" - fi \ No newline at end of file + # final: + # needs: [check, build, package, test, nightly, release, deploy] + # if: ${{ always() && (contains(needs.*.result, 'failure') || !failure() && !cancelled()) }} + # runs-on: ubuntu-latest + # steps: + # - name: Final + # run: | + # if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" ]] + # then + # echo "Run failed" + # exit 1 + # else + # echo "All done" + # fi \ No newline at end of file diff --git a/cli/pkg/release/providers/docs.go b/cli/pkg/release/providers/docs.go index 2e435c29..a45718e9 100644 --- a/cli/pkg/release/providers/docs.go +++ b/cli/pkg/release/providers/docs.go @@ -55,6 +55,14 @@ type DocsReleaser struct { // Release runs the docs release. func (r *DocsReleaser) Release() error { + // Testing + branch, err := git.GetBranch(r.ghClient, r.project.Repo) + if err != nil { + return fmt.Errorf("failed to get branch: %w", err) + } + + r.project.Blueprint.Global.Repo.DefaultBranch = branch + r.logger.Info("Running docs release target", "project", r.project.Name, "target", r.release.Target, "dir", r.workdir) if err := r.run(r.workdir); err != nil { return fmt.Errorf("failed to run docs release target: %w", err) @@ -89,7 +97,7 @@ func (r *DocsReleaser) Release() error { } r.logger.Info("Cleaning existing docs from S3", "bucket", docsConfig.Bucket, "path", s3Path) - if err := r.s3.DeleteDirectory(docsConfig.Bucket, s3Path, []string{".*/b/.*"}); err != nil { + if err := r.s3.DeleteDirectory(docsConfig.Bucket, s3Path, nil); err != nil { return fmt.Errorf("failed to clean existing docs from S3: %w", err) } @@ -111,11 +119,10 @@ func (r *DocsReleaser) Release() error { } if isDefault { - if err := r.cleanupBranches(docsConfig.Bucket, filepath.Join(s3Path, "b")); err != nil { + if err := r.cleanupBranches(docsConfig.Bucket, filepath.Dir(s3Path)); err != nil { return fmt.Errorf("failed to cleanup branches: %w", err) } } - } r.logger.Info("Docs release complete") @@ -133,8 +140,10 @@ func (r *DocsReleaser) cleanupBranches(bucket, path string) error { for _, branch := range branches { branchNames = append(branchNames, branch.Name) } + fmt.Printf("branchNames: %v\n", branchNames) children, err := r.s3.ListImmediateChildren(bucket, path) + fmt.Printf("children: %v\n", children) if err != nil { return fmt.Errorf("failed to list immediate children: %w", err) } @@ -154,25 +163,19 @@ func (r *DocsReleaser) cleanupBranches(bucket, path string) error { // generatePath generates the S3 path for the docs. func (r *DocsReleaser) generatePath(projectName string) (string, error) { docsConfig := r.project.Blueprint.Global.Ci.Release.Docs - if docsConfig.Bucket == "" { - return "", fmt.Errorf("no S3 bucket specified in global docs configuration") - } - - s3Path := projectName - if docsConfig.Path != "" { - s3Path = filepath.Join(docsConfig.Path, projectName) - } - branch, err := git.GetBranch(r.ghClient, r.project.Repo) if err != nil { return "", fmt.Errorf("failed to get branch: %w", err) } - if branch == r.project.Blueprint.Global.Repo.DefaultBranch { - return s3Path, nil + var s3Path string + if docsConfig.Path != "" { + s3Path = filepath.Join(docsConfig.Path, projectName, branch) + } else { + s3Path = filepath.Join(projectName, branch) } - return filepath.Join(s3Path, "b", branch), nil + return s3Path, nil } // isDefaultBranch returns true if the current branch is the default branch. diff --git a/cli/pkg/release/providers/docs_test.go b/cli/pkg/release/providers/docs_test.go index 26820456..ad4c1808 100644 --- a/cli/pkg/release/providers/docs_test.go +++ b/cli/pkg/release/providers/docs_test.go @@ -2,6 +2,7 @@ package providers import ( "context" + "fmt" "io" "os" "path/filepath" @@ -121,109 +122,123 @@ func TestDocsReleaserRelease(t *testing.T) { }, }, prComments: []gh.PullRequestComment{}, - branches: []gh.Branch{}, - inCI: true, - isPR: false, + branches: []gh.Branch{ + { + Name: "master", + }, + }, + inCI: true, + isPR: false, validate: func(t *testing.T, result testResult) { assert.NoError(t, result.err) - exists, err := result.s3Fs.Exists("/bucket/prefix/test/index.html") - require.NoError(t, err) - assert.True(t, exists) + result.s3Fs.Walk("/", func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } - exists, err = result.s3Fs.Exists("/bucket/prefix/test/test.html") - require.NoError(t, err) - assert.False(t, exists) + fmt.Println(path) - exists, err = result.s3Fs.Exists("/bucket/prefix/test/b/mybranch/index.html") - require.NoError(t, err) - assert.False(t, exists) + return nil + }) - content, err := result.s3Fs.ReadFile("/bucket/prefix/test/index.html") + exists, err := result.s3Fs.Exists("/bucket/prefix/test/master/index.html") require.NoError(t, err) - assert.Equal(t, "test docs", string(content)) - - assert.Equal(t, 0, result.prPost.prNumber) - assert.Equal(t, "", result.prPost.body) - }, - }, - { - name: "pr", - projectName: "project", - defaultBranch: "master", - bucket: "bucket", - prefix: "prefix", - releaseName: "test", - prNumber: 123, - curBranch: "mybranch", - files: map[string]string{ - "index.html": "test docs", - }, - s3files: map[string]string{ - "test.html": "test", - }, - prComments: []gh.PullRequestComment{}, - branches: []gh.Branch{}, - inCI: true, - isPR: true, - validate: func(t *testing.T, result testResult) { - assert.NoError(t, result.err) + assert.True(t, exists) - exists, err := result.s3Fs.Exists("/bucket/prefix/test/b/mybranch/index.html") + exists, err = result.s3Fs.Exists("/bucket/prefix/test/master/test.html") require.NoError(t, err) - assert.True(t, exists) + assert.False(t, exists) - exists, err = result.s3Fs.Exists("/bucket/prefix/test/b/mybranch/test.html") + exists, err = result.s3Fs.Exists("/bucket/prefix/test/mybranch/index.html") require.NoError(t, err) assert.False(t, exists) - content, err := result.s3Fs.ReadFile("/bucket/prefix/test/b/mybranch/index.html") + content, err := result.s3Fs.ReadFile("/bucket/prefix/test/master/index.html") require.NoError(t, err) assert.Equal(t, "test docs", string(content)) - expectedBody := ` - -## 📚 Docs Preview - -The docs for this PR can be previewed at the following URL: - -https://docs.example.com/test/b/mybranch -` - - assert.Equal(t, expectedBody, result.prPost.body) - }, - }, - { - name: "pr comment exists", - projectName: "project", - defaultBranch: "master", - bucket: "bucket", - prefix: "prefix", - releaseName: "test", - prNumber: 123, - curBranch: "mybranch", - files: map[string]string{ - "index.html": "test docs", - }, - s3files: map[string]string{ - "test.html": "test", - }, - prComments: []gh.PullRequestComment{ - { - Author: "github-actions[bot]", - Body: "", - }, - }, - branches: []gh.Branch{}, - inCI: true, - isPR: true, - validate: func(t *testing.T, result testResult) { - assert.NoError(t, result.err) - assert.Equal(t, 0, result.prPost.prNumber) assert.Equal(t, "", result.prPost.body) }, }, + // { + // name: "pr", + // projectName: "project", + // defaultBranch: "master", + // bucket: "bucket", + // prefix: "prefix", + // releaseName: "test", + // prNumber: 123, + // curBranch: "mybranch", + // files: map[string]string{ + // "index.html": "test docs", + // }, + // s3files: map[string]string{ + // "test.html": "test", + // }, + // prComments: []gh.PullRequestComment{}, + // branches: []gh.Branch{}, + // inCI: true, + // isPR: true, + // validate: func(t *testing.T, result testResult) { + // assert.NoError(t, result.err) + + // exists, err := result.s3Fs.Exists("/bucket/prefix/test/b/mybranch/index.html") + // require.NoError(t, err) + // assert.True(t, exists) + + // exists, err = result.s3Fs.Exists("/bucket/prefix/test/b/mybranch/test.html") + // require.NoError(t, err) + // assert.False(t, exists) + + // content, err := result.s3Fs.ReadFile("/bucket/prefix/test/b/mybranch/index.html") + // require.NoError(t, err) + // assert.Equal(t, "test docs", string(content)) + + // expectedBody := ` + // + // ## 📚 Docs Preview + + // The docs for this PR can be previewed at the following URL: + + // https://docs.example.com/test/b/mybranch + // ` + + // assert.Equal(t, expectedBody, result.prPost.body) + // }, + // }, + // { + // name: "pr comment exists", + // projectName: "project", + // defaultBranch: "master", + // bucket: "bucket", + // prefix: "prefix", + // releaseName: "test", + // prNumber: 123, + // curBranch: "mybranch", + // files: map[string]string{ + // "index.html": "test docs", + // }, + // s3files: map[string]string{ + // "test.html": "test", + // }, + // prComments: []gh.PullRequestComment{ + // { + // Author: "github-actions[bot]", + // Body: "", + // }, + // }, + // branches: []gh.Branch{}, + // inCI: true, + // isPR: true, + // validate: func(t *testing.T, result testResult) { + // assert.NoError(t, result.err) + + // assert.Equal(t, 0, result.prPost.prNumber) + // assert.Equal(t, "", result.prPost.body) + // }, + // }, } for _, tt := range tests { @@ -241,6 +256,7 @@ https://docs.example.com/test/b/mybranch prj.Blueprint.Global.Ci.Release.Docs.Bucket, prj.Blueprint.Global.Ci.Release.Docs.Path, tt.releaseName, + tt.curBranch, name, ) require.NoError(t, s3Fs.WriteFile(p, []byte(content), 0o644)) @@ -251,7 +267,6 @@ https://docs.example.com/test/b/mybranch prj.Blueprint.Global.Ci.Release.Docs.Bucket, prj.Blueprint.Global.Ci.Release.Docs.Path, tt.releaseName, - "b", branchFile.branch, branchFile.name, ) @@ -288,16 +303,13 @@ https://docs.example.com/test/b/mybranch bucketDir := "/" + bucket filePath := filepath.Join(bucketDir, key) + fmt.Println("deleting", filePath) _ = s3Fs.Remove(filePath) return &s3.DeleteObjectOutput{}, nil }, ListObjectsV2Func: func(ctx context.Context, params *s3.ListObjectsV2Input, optFns ...func(*s3.Options)) (*s3.ListObjectsV2Output, error) { bucket := *params.Bucket - prefix := "" - if params.Prefix != nil { - prefix = *params.Prefix - } bucketDir := "/" + bucket if params.Delimiter != nil { @@ -324,14 +336,15 @@ https://docs.example.com/test/b/mybranch } var contents []s3types.Object - _ = s3Fs.Walk(bucketDir, func(path string, info os.FileInfo, err error) error { + fmt.Println("walking", filepath.Join(bucketDir, *params.Prefix)) + _ = s3Fs.Walk(filepath.Join(bucketDir, *params.Prefix), func(path string, info os.FileInfo, err error) error { if err != nil { return nil } - relPath, _ := filepath.Rel(bucketDir, path) - if !info.IsDir() && strings.HasPrefix(relPath, prefix) { - contents = append(contents, s3types.Object{Key: &relPath}) + if !info.IsDir() { + fmt.Println("adding", path) + contents = append(contents, s3types.Object{Key: &path}) } return nil From a10a7a8387b9dee81ef218c55644c3c45117ee5f Mon Sep 17 00:00:00 2001 From: Joshua Gilman Date: Thu, 24 Jul 2025 22:02:40 -0700 Subject: [PATCH 2/4] wip: testing --- cli/pkg/release/providers/docs.go | 14 +- cli/pkg/release/providers/docs_test.go | 176 ++++++++++++------------- 2 files changed, 86 insertions(+), 104 deletions(-) diff --git a/cli/pkg/release/providers/docs.go b/cli/pkg/release/providers/docs.go index a45718e9..fd157178 100644 --- a/cli/pkg/release/providers/docs.go +++ b/cli/pkg/release/providers/docs.go @@ -55,14 +55,6 @@ type DocsReleaser struct { // Release runs the docs release. func (r *DocsReleaser) Release() error { - // Testing - branch, err := git.GetBranch(r.ghClient, r.project.Repo) - if err != nil { - return fmt.Errorf("failed to get branch: %w", err) - } - - r.project.Blueprint.Global.Repo.DefaultBranch = branch - r.logger.Info("Running docs release target", "project", r.project.Name, "target", r.release.Target, "dir", r.workdir) if err := r.run(r.workdir); err != nil { return fmt.Errorf("failed to run docs release target: %w", err) @@ -108,6 +100,7 @@ func (r *DocsReleaser) Release() error { } if github.InCI() { + r.logger.Info("Posting comment", "url", docsConfig.Url, "project", projectName) url := r.project.Blueprint.Global.Ci.Release.Docs.Url if err := r.postComment(url, projectName); err != nil { return fmt.Errorf("failed to post comment: %w", err) @@ -119,6 +112,7 @@ func (r *DocsReleaser) Release() error { } if isDefault { + r.logger.Info("Cleaning up branches from S3", "bucket", docsConfig.Bucket, "path", filepath.Dir(s3Path)) if err := r.cleanupBranches(docsConfig.Bucket, filepath.Dir(s3Path)); err != nil { return fmt.Errorf("failed to cleanup branches: %w", err) } @@ -140,13 +134,13 @@ func (r *DocsReleaser) cleanupBranches(bucket, path string) error { for _, branch := range branches { branchNames = append(branchNames, branch.Name) } - fmt.Printf("branchNames: %v\n", branchNames) + r.logger.Info("Repo branches", "branches", branchNames) children, err := r.s3.ListImmediateChildren(bucket, path) - fmt.Printf("children: %v\n", children) if err != nil { return fmt.Errorf("failed to list immediate children: %w", err) } + r.logger.Info("Docs branches", "branches", children) for _, child := range children { if !slices.Contains(branchNames, child) { diff --git a/cli/pkg/release/providers/docs_test.go b/cli/pkg/release/providers/docs_test.go index ad4c1808..dacc8a57 100644 --- a/cli/pkg/release/providers/docs_test.go +++ b/cli/pkg/release/providers/docs_test.go @@ -2,7 +2,6 @@ package providers import ( "context" - "fmt" "io" "os" "path/filepath" @@ -132,16 +131,6 @@ func TestDocsReleaserRelease(t *testing.T) { validate: func(t *testing.T, result testResult) { assert.NoError(t, result.err) - result.s3Fs.Walk("/", func(path string, info os.FileInfo, err error) error { - if err != nil { - return err - } - - fmt.Println(path) - - return nil - }) - exists, err := result.s3Fs.Exists("/bucket/prefix/test/master/index.html") require.NoError(t, err) assert.True(t, exists) @@ -162,83 +151,83 @@ func TestDocsReleaserRelease(t *testing.T) { assert.Equal(t, "", result.prPost.body) }, }, - // { - // name: "pr", - // projectName: "project", - // defaultBranch: "master", - // bucket: "bucket", - // prefix: "prefix", - // releaseName: "test", - // prNumber: 123, - // curBranch: "mybranch", - // files: map[string]string{ - // "index.html": "test docs", - // }, - // s3files: map[string]string{ - // "test.html": "test", - // }, - // prComments: []gh.PullRequestComment{}, - // branches: []gh.Branch{}, - // inCI: true, - // isPR: true, - // validate: func(t *testing.T, result testResult) { - // assert.NoError(t, result.err) - - // exists, err := result.s3Fs.Exists("/bucket/prefix/test/b/mybranch/index.html") - // require.NoError(t, err) - // assert.True(t, exists) - - // exists, err = result.s3Fs.Exists("/bucket/prefix/test/b/mybranch/test.html") - // require.NoError(t, err) - // assert.False(t, exists) - - // content, err := result.s3Fs.ReadFile("/bucket/prefix/test/b/mybranch/index.html") - // require.NoError(t, err) - // assert.Equal(t, "test docs", string(content)) - - // expectedBody := ` - // - // ## 📚 Docs Preview - - // The docs for this PR can be previewed at the following URL: - - // https://docs.example.com/test/b/mybranch - // ` - - // assert.Equal(t, expectedBody, result.prPost.body) - // }, - // }, - // { - // name: "pr comment exists", - // projectName: "project", - // defaultBranch: "master", - // bucket: "bucket", - // prefix: "prefix", - // releaseName: "test", - // prNumber: 123, - // curBranch: "mybranch", - // files: map[string]string{ - // "index.html": "test docs", - // }, - // s3files: map[string]string{ - // "test.html": "test", - // }, - // prComments: []gh.PullRequestComment{ - // { - // Author: "github-actions[bot]", - // Body: "", - // }, - // }, - // branches: []gh.Branch{}, - // inCI: true, - // isPR: true, - // validate: func(t *testing.T, result testResult) { - // assert.NoError(t, result.err) - - // assert.Equal(t, 0, result.prPost.prNumber) - // assert.Equal(t, "", result.prPost.body) - // }, - // }, + { + name: "pr", + projectName: "project", + defaultBranch: "master", + bucket: "bucket", + prefix: "prefix", + releaseName: "test", + prNumber: 123, + curBranch: "mybranch", + files: map[string]string{ + "index.html": "test docs", + }, + s3files: map[string]string{ + "test.html": "test", + }, + prComments: []gh.PullRequestComment{}, + branches: []gh.Branch{}, + inCI: true, + isPR: true, + validate: func(t *testing.T, result testResult) { + assert.NoError(t, result.err) + + exists, err := result.s3Fs.Exists("/bucket/prefix/test/mybranch/index.html") + require.NoError(t, err) + assert.True(t, exists) + + exists, err = result.s3Fs.Exists("/bucket/prefix/test/mybranch/test.html") + require.NoError(t, err) + assert.False(t, exists) + + content, err := result.s3Fs.ReadFile("/bucket/prefix/test/mybranch/index.html") + require.NoError(t, err) + assert.Equal(t, "test docs", string(content)) + + expectedBody := ` + +## 📚 Docs Preview + +The docs for this PR can be previewed at the following URL: + +https://docs.example.com/test/b/mybranch +` + + assert.Equal(t, expectedBody, result.prPost.body) + }, + }, + { + name: "pr comment exists", + projectName: "project", + defaultBranch: "master", + bucket: "bucket", + prefix: "prefix", + releaseName: "test", + prNumber: 123, + curBranch: "mybranch", + files: map[string]string{ + "index.html": "test docs", + }, + s3files: map[string]string{ + "test.html": "test", + }, + prComments: []gh.PullRequestComment{ + { + Author: "github-actions[bot]", + Body: "", + }, + }, + branches: []gh.Branch{}, + inCI: true, + isPR: true, + validate: func(t *testing.T, result testResult) { + assert.NoError(t, result.err) + + assert.Equal(t, 0, result.prPost.prNumber) + assert.Equal(t, "", result.prPost.body) + }, + }, } for _, tt := range tests { @@ -303,7 +292,6 @@ func TestDocsReleaserRelease(t *testing.T) { bucketDir := "/" + bucket filePath := filepath.Join(bucketDir, key) - fmt.Println("deleting", filePath) _ = s3Fs.Remove(filePath) return &s3.DeleteObjectOutput{}, nil @@ -320,13 +308,14 @@ func TestDocsReleaserRelease(t *testing.T) { return err } - if info.IsDir() { + if !info.IsDir() { return nil } p1 := strings.TrimPrefix(path, "/"+tt.bucket+"/") if strings.HasPrefix(p1, *params.Prefix) { - prefixes = append(prefixes, s3types.CommonPrefix{Prefix: &p1}) + prefix := strings.TrimPrefix(p1, *params.Prefix) + prefixes = append(prefixes, s3types.CommonPrefix{Prefix: &prefix}) } return nil }) @@ -336,15 +325,14 @@ func TestDocsReleaserRelease(t *testing.T) { } var contents []s3types.Object - fmt.Println("walking", filepath.Join(bucketDir, *params.Prefix)) _ = s3Fs.Walk(filepath.Join(bucketDir, *params.Prefix), func(path string, info os.FileInfo, err error) error { if err != nil { return nil } if !info.IsDir() { - fmt.Println("adding", path) - contents = append(contents, s3types.Object{Key: &path}) + p := strings.TrimPrefix(path, bucketDir+"/") + contents = append(contents, s3types.Object{Key: &p}) } return nil From 9d30217f517e908070192a482bd5ba004b1a4b11 Mon Sep 17 00:00:00 2001 From: Joshua Gilman Date: Thu, 24 Jul 2025 22:02:54 -0700 Subject: [PATCH 3/4] wip: cleanup --- .github/workflows/ci.yml | 163 +++++++++++++++++++-------------------- 1 file changed, 81 insertions(+), 82 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 15a6d261..1b1fe086 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -75,70 +75,69 @@ jobs: ${{ env.FORGE_REGEX_RELEASE }} ${{ env.FORGE_REGEX_PUBLISH }} ${{ env.FORGE_REGEX_NIGHTLY }} - # check: - # uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master - # needs: [discover] - # if: (fromJson(needs.discover.outputs.earthfiles)['^check(-.*)?$'] != null) && !failure() && !cancelled() - # with: - # earthfiles: ${{ toJson(fromJson(needs.discover.outputs.earthfiles)['^check(-.*)?$']) }} - # forge_version: ${{ inputs.forge_version }} - # local: ${{ inputs.local }} - # verbosity: ${{ inputs.verbosity }} - # secrets: - # earthly_token: ${{ secrets.earthly_token }} + check: + uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master + needs: [discover] + if: (fromJson(needs.discover.outputs.earthfiles)['^check(-.*)?$'] != null) && !failure() && !cancelled() + with: + earthfiles: ${{ toJson(fromJson(needs.discover.outputs.earthfiles)['^check(-.*)?$']) }} + forge_version: ${{ inputs.forge_version }} + local: ${{ inputs.local }} + verbosity: ${{ inputs.verbosity }} + secrets: + earthly_token: ${{ secrets.earthly_token }} - # build: - # uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master - # needs: [discover, check] - # if: (fromJson(needs.discover.outputs.earthfiles)['^build(-.*)?$'] != null) && !failure() && !cancelled() - # with: - # earthfiles: ${{ toJson(fromJson(needs.discover.outputs.earthfiles)['^build(-.*)?$']) }} - # forge_version: ${{ inputs.forge_version }} - # local: ${{ inputs.local }} - # verbosity: ${{ inputs.verbosity }} - # secrets: - # earthly_token: ${{ secrets.earthly_token }} + build: + uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master + needs: [discover, check] + if: (fromJson(needs.discover.outputs.earthfiles)['^build(-.*)?$'] != null) && !failure() && !cancelled() + with: + earthfiles: ${{ toJson(fromJson(needs.discover.outputs.earthfiles)['^build(-.*)?$']) }} + forge_version: ${{ inputs.forge_version }} + local: ${{ inputs.local }} + verbosity: ${{ inputs.verbosity }} + secrets: + earthly_token: ${{ secrets.earthly_token }} - # package: - # uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master - # needs: [discover, check, build] - # if: (fromJson(needs.discover.outputs.earthfiles)['^package(-.*)?$'] != null) && !failure() && !cancelled() - # with: - # earthfiles: ${{ toJson(fromJson(needs.discover.outputs.earthfiles)['^package(-.*)?$']) }} - # forge_version: ${{ inputs.forge_version }} - # local: ${{ inputs.local }} - # verbosity: ${{ inputs.verbosity }} - # secrets: - # earthly_token: ${{ secrets.earthly_token }} + package: + uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master + needs: [discover, check, build] + if: (fromJson(needs.discover.outputs.earthfiles)['^package(-.*)?$'] != null) && !failure() && !cancelled() + with: + earthfiles: ${{ toJson(fromJson(needs.discover.outputs.earthfiles)['^package(-.*)?$']) }} + forge_version: ${{ inputs.forge_version }} + local: ${{ inputs.local }} + verbosity: ${{ inputs.verbosity }} + secrets: + earthly_token: ${{ secrets.earthly_token }} - # test: - # uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master - # needs: [discover, check, build, package] - # if: (fromJson(needs.discover.outputs.earthfiles)['^test(-.*)?$'] != null) && !failure() && !cancelled() - # with: - # earthfiles: ${{ toJson(fromJson(needs.discover.outputs.earthfiles)['^test(-.*)?$']) }} - # forge_version: ${{ inputs.forge_version }} - # local: ${{ inputs.local }} - # verbosity: ${{ inputs.verbosity }} - # secrets: - # earthly_token: ${{ secrets.earthly_token }} + test: + uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master + needs: [discover, check, build, package] + if: (fromJson(needs.discover.outputs.earthfiles)['^test(-.*)?$'] != null) && !failure() && !cancelled() + with: + earthfiles: ${{ toJson(fromJson(needs.discover.outputs.earthfiles)['^test(-.*)?$']) }} + forge_version: ${{ inputs.forge_version }} + local: ${{ inputs.local }} + verbosity: ${{ inputs.verbosity }} + secrets: + earthly_token: ${{ secrets.earthly_token }} - # nightly: - # uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master - # needs: [discover, check, build, package] - # if: (fromJson(needs.discover.outputs.earthfiles)['^nightly(-.*)?$'] != null) && !failure() && !cancelled() && inputs.nightly == true - # with: - # earthfiles: ${{ toJson(fromJson(needs.discover.outputs.earthfiles)['^nightly(-.*)?$']) }} - # forge_version: ${{ inputs.forge_version }} - # local: ${{ inputs.local }} - # verbosity: ${{ inputs.verbosity }} - # secrets: - # earthly_token: ${{ secrets.earthly_token }} + nightly: + uses: input-output-hk/catalyst-forge/.github/workflows/run.yml@master + needs: [discover, check, build, package] + if: (fromJson(needs.discover.outputs.earthfiles)['^nightly(-.*)?$'] != null) && !failure() && !cancelled() && inputs.nightly == true + with: + earthfiles: ${{ toJson(fromJson(needs.discover.outputs.earthfiles)['^nightly(-.*)?$']) }} + forge_version: ${{ inputs.forge_version }} + local: ${{ inputs.local }} + verbosity: ${{ inputs.verbosity }} + secrets: + earthly_token: ${{ secrets.earthly_token }} release: uses: input-output-hk/catalyst-forge/.github/workflows/release.yml@master - #needs: [discover, check, build, test] - needs: [discover] + needs: [discover, check, build, test] if: (fromJson(needs.discover.outputs.releases)[0] != null) && !failure() && !cancelled() with: releases: ${{ needs.discover.outputs.releases }} @@ -148,29 +147,29 @@ jobs: secrets: earthly_token: ${{ secrets.earthly_token }} - # deploy: - # uses: input-output-hk/catalyst-forge/.github/workflows/deploy.yml@master - # needs: [discover, check, build, test, release] - # if: (fromJson(needs.discover.outputs.deployments)[0] != null) && !failure() && !cancelled() - # with: - # deployments: ${{ needs.discover.outputs.deployments }} - # forge_version: ${{ inputs.forge_version }} - # local: ${{ inputs.local }} - # verbosity: ${{ inputs.verbosity }} - # secrets: - # earthly_token: ${{ secrets.earthly_token }} + deploy: + uses: input-output-hk/catalyst-forge/.github/workflows/deploy.yml@master + needs: [discover, check, build, test, release] + if: (fromJson(needs.discover.outputs.deployments)[0] != null) && !failure() && !cancelled() + with: + deployments: ${{ needs.discover.outputs.deployments }} + forge_version: ${{ inputs.forge_version }} + local: ${{ inputs.local }} + verbosity: ${{ inputs.verbosity }} + secrets: + earthly_token: ${{ secrets.earthly_token }} - # final: - # needs: [check, build, package, test, nightly, release, deploy] - # if: ${{ always() && (contains(needs.*.result, 'failure') || !failure() && !cancelled()) }} - # runs-on: ubuntu-latest - # steps: - # - name: Final - # run: | - # if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" ]] - # then - # echo "Run failed" - # exit 1 - # else - # echo "All done" - # fi \ No newline at end of file + final: + needs: [check, build, package, test, nightly, release, deploy] + if: ${{ always() && (contains(needs.*.result, 'failure') || !failure() && !cancelled()) }} + runs-on: ubuntu-latest + steps: + - name: Final + run: | + if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" ]] + then + echo "Run failed" + exit 1 + else + echo "All done" + fi \ No newline at end of file From 1c59c0465daee2dcba156ee9fda84909695e93d7 Mon Sep 17 00:00:00 2001 From: Joshua Gilman Date: Thu, 24 Jul 2025 22:13:50 -0700 Subject: [PATCH 4/4] wip: fixes url --- cli/pkg/release/providers/docs.go | 7 +------ cli/pkg/release/providers/docs_test.go | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/cli/pkg/release/providers/docs.go b/cli/pkg/release/providers/docs.go index fd157178..2a30d07e 100644 --- a/cli/pkg/release/providers/docs.go +++ b/cli/pkg/release/providers/docs.go @@ -208,12 +208,7 @@ func (r *DocsReleaser) postComment(baseURL, name string) error { return fmt.Errorf("failed to get branch: %w", err) } - var docURL string - if branch == r.project.Blueprint.Global.Repo.DefaultBranch { - docURL, err = url.JoinPath(baseURL, name) - } else { - docURL, err = url.JoinPath(baseURL, name, "b", branch) - } + docURL, err := url.JoinPath(baseURL, name, branch) if err != nil { return fmt.Errorf("failed to join URL path: %w", err) } diff --git a/cli/pkg/release/providers/docs_test.go b/cli/pkg/release/providers/docs_test.go index dacc8a57..844ea8ca 100644 --- a/cli/pkg/release/providers/docs_test.go +++ b/cli/pkg/release/providers/docs_test.go @@ -191,7 +191,7 @@ func TestDocsReleaserRelease(t *testing.T) { The docs for this PR can be previewed at the following URL: -https://docs.example.com/test/b/mybranch +https://docs.example.com/test/mybranch ` assert.Equal(t, expectedBody, result.prPost.body)