diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index c0d12727c..ca2a9ae36 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,7 +1,7 @@ { "name": "hof cli", "image": "mcr.microsoft.com/devcontainers/universal:2", - "postCreateCommand": "make hof \u0026\u0026 hof mod tidy\necho \"hallo! you can now work on hof code, just type 'make hof' to rebuild\"", + "postCreateCommand": "sudo rm -rf /usr/local/hugo", "customizations": { "vscode": { "extensions": [ diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 802232a9b..3468b3de0 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -4,6 +4,8 @@ name: docs paths: - docs/** - ci/gha/docs.cue +env: + HOF_TELEMETRY_DISABLED: "1" jobs: docs: runs-on: ubuntu-latest diff --git a/.github/workflows/fmt.yml b/.github/workflows/fmt.yml index ed40d1c3c..0917fe707 100644 --- a/.github/workflows/fmt.yml +++ b/.github/workflows/fmt.yml @@ -5,15 +5,20 @@ name: fmt paths: - lib/fmt/** - formatters/** - - ci/gha/fmt.* + - ci/gha/fmt.cue + - .github/workflows/fmt.yml pull_request: paths: - lib/fmt/** - formatters/** - - ci/gha/fmt.* + - ci/gha/fmt.cue + - .github/workflows/fmt.yml +env: + HOF_TELEMETRY_DISABLED: "1" jobs: formatter: runs-on: ubuntu-latest + environment: hof mod testing strategy: fail-fast: false matrix: @@ -41,6 +46,11 @@ jobs: platforms: arm64 - name: Set up Docker BuildX uses: docker/setup-buildx-action@v2 + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.HOF_DOCKER_USER }} + password: ${{ secrets.HOF_DOCKER_TOKEN }} - name: Build Image uses: docker/build-push-action@v3 with: diff --git a/.github/workflows/hof.yml b/.github/workflows/hof.yml index 84f0cf6de..69557fd81 100644 --- a/.github/workflows/hof.yml +++ b/.github/workflows/hof.yml @@ -49,23 +49,34 @@ jobs: run: go mod download - name: Build CLI run: go install ./cmd/hof - - name: Set up Docker BuildX - if: ${{ !startsWith( runner.os, 'macos') }} - uses: docker/setup-buildx-action@v2 + - name: Set up Docker + uses: crazy-max/ghaction-setup-docker@v1 + with: + version: 23.0.1 + if: ${{ startsWith( runner.os, 'macos') }} + - name: Setup Docker MacOS var + run: echo "DOCKER_HOST="unix://$HOME/.colima/default/docker.sock"" >> $GITHUB_ENV + if: ${{ startsWith( runner.os, 'macos') }} + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.HOF_DOCKER_USER }} + password: ${{ secrets.HOF_DOCKER_TOKEN }} - name: Test Compatibility - if: ${{ !startsWith( runner.os, 'macos') }} run: |- docker version + docker info + docker context ls go run test/docker/main.go - name: Build Formatters run: |- make formatters + docker images hof fmt start hof fmt info - if: ${{ !startsWith( runner.os, 'macos') }} + docker ps -a - name: test/self env: - HOFMOD_SSHKEY: ${{secrets.HOFMOD_SSHKEY}} GITHUB_TOKEN: ${{secrets.HOFMOD_TOKEN}} run: |- # self: gen -> diff @@ -80,43 +91,38 @@ jobs: git diff --exit-code - name: test/gen env: - HOFMOD_SSHKEY: ${{secrets.HOFMOD_SSHKEY}} GITHUB_TOKEN: ${{secrets.HOFMOD_TOKEN}} run: hof flow @test/gen ./test.cue - name: test/render env: - HOFMOD_SSHKEY: ${{secrets.HOFMOD_SSHKEY}} GITHUB_TOKEN: ${{secrets.HOFMOD_TOKEN}} run: hof flow @test/render ./test.cue - name: test/create env: - HOFMOD_SSHKEY: ${{secrets.HOFMOD_SSHKEY}} GITHUB_TOKEN: ${{secrets.HOFMOD_TOKEN}} run: hof flow @test/create ./test.cue - name: test/structural env: - HOFMOD_SSHKEY: ${{secrets.HOFMOD_SSHKEY}} GITHUB_TOKEN: ${{secrets.HOFMOD_TOKEN}} run: hof flow @test/st ./test.cue - name: test/flow env: - HOFMOD_SSHKEY: ${{secrets.HOFMOD_SSHKEY}} GITHUB_TOKEN: ${{secrets.HOFMOD_TOKEN}} run: hof flow -f test/flow ./test.cue - name: test/mod run: hof flow -f test/mod ./test.cue env: + HOFMOD_SSHKEY: ${{secrets.HOFMOD_SSHKEY}} GITLAB_TOKEN: ${{secrets.GITLAB_TOKEN}} BITBUCKET_USERNAME: hofstadter - HOFMOD_SSHKEY: ${{secrets.HOFMOD_SSHKEY}} - BITBUCKET_PASSWORD: ${{secrets.BITBUCKET_TOKEN}} GITHUB_TOKEN: ${{secrets.HOFMOD_TOKEN}} + BITBUCKET_PASSWORD: ${{secrets.BITBUCKET_TOKEN}} - name: test/fmt run: |- + docker ps -a hof fmt info hof flow -f test/fmt ./test.cue - if: ${{ !startsWith( runner.os, 'macos') }} env: - HOFMOD_SSHKEY: ${{secrets.HOFMOD_SSHKEY}} + HOF_FMT_DEBUG: "1" GITHUB_TOKEN: ${{secrets.HOFMOD_TOKEN}} services: {} diff --git a/.github/workflows/release-docs.yml b/.github/workflows/release-docs.yml index 1ad926fc7..8f7b1290f 100644 --- a/.github/workflows/release-docs.yml +++ b/.github/workflows/release-docs.yml @@ -13,6 +13,8 @@ name: release (docs) options: - next - prod +env: + HOF_TELEMETRY_DISABLED: "1" jobs: docs: runs-on: ubuntu-latest diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cd2cc1582..c400aef91 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,6 +3,8 @@ name: release (hof) push: tags: - v* +env: + HOF_TELEMETRY_DISABLED: "1" jobs: goreleaser: environment: hof mod testing diff --git a/ci/devc/devcontainer.cue b/ci/devc/devcontainer.cue index 49fc56f13..2bef6f7fe 100644 --- a/ci/devc/devcontainer.cue +++ b/ci/devc/devcontainer.cue @@ -3,8 +3,7 @@ name: "hof cli" image: "mcr.microsoft.com/devcontainers/universal:2" postCreateCommand: """ -make hof && hof mod tidy -echo "hallo! you can now work on hof code, just type 'make hof' to rebuild" +sudo rm -rf /usr/local/hugo """ customizations: { diff --git a/ci/gha/common/steps.cue b/ci/gha/common/steps.cue index 1b7277c46..2c0041d1f 100644 --- a/ci/gha/common/steps.cue +++ b/ci/gha/common/steps.cue @@ -79,7 +79,7 @@ Steps: { } } - docker: { + buildx: { qemu: { name: "Set up QEMU" uses: "docker/setup-qemu-action@v2" @@ -93,15 +93,6 @@ Steps: { uses: "docker/setup-buildx-action@v2" } - login: { - name: "Login to Docker Hub" - uses: "docker/login-action@v2" - with: { - username: "${{ secrets.HOF_DOCKER_USER }}" - password: "${{ secrets.HOF_DOCKER_TOKEN }}" - } - } - formatters: { name: "Build Image" uses: "docker/build-push-action@v3" @@ -115,14 +106,42 @@ Steps: { ], ",") } } + } + + docker: { + setup: { + name: "Set up Docker" + uses: "crazy-max/ghaction-setup-docker@v1" + with: { + version: "23.0.1" + } + "if": "${{ startsWith( runner.os, 'macos') }}" + } + macos: { + name: "Setup Docker MacOS var" + run: """ + echo "DOCKER_HOST=\"unix://$HOME/.colima/default/docker.sock\"" >> $GITHUB_ENV + """ + "if": "${{ startsWith( runner.os, 'macos') }}" + } + + login: { + name: "Login to Docker Hub" + uses: "docker/login-action@v2" + with: { + username: "${{ secrets.HOF_DOCKER_USER }}" + password: "${{ secrets.HOF_DOCKER_TOKEN }}" + } + } compat: { name: "Test Compatibility" run: """ docker version + docker info + docker context ls go run test/docker/main.go """ - } } diff --git a/ci/gha/common/vars.cue b/ci/gha/common/vars.cue index c2933f7d7..ae17381a1 100644 --- a/ci/gha/common/vars.cue +++ b/ci/gha/common/vars.cue @@ -7,7 +7,7 @@ Formatters: [ ] Versions: { - docker: "20.x" | ["20.x", "23.x"] + docker: "23.0.1" go: "1.20.x" | ["1.19.x", "1.20.x"] os: "ubuntu-latest" | ["ubuntu-latest", "macos-latest"] } diff --git a/ci/gha/docs.cue b/ci/gha/docs.cue index 074dd4cc9..2b0352b57 100644 --- a/ci/gha/docs.cue +++ b/ci/gha/docs.cue @@ -11,6 +11,7 @@ ghacue.#Workflow & { on: push: { paths: ["docs/**", "ci/gha/docs.cue"] } + env: HOF_TELEMETRY_DISABLED: "1" jobs: { docs: { diff --git a/ci/gha/fmt.cue b/ci/gha/fmt.cue index 88453e7e3..5e30406ff 100644 --- a/ci/gha/fmt.cue +++ b/ci/gha/fmt.cue @@ -9,13 +9,15 @@ ghacue.#Workflow & { name: "fmt" _on: ["push", "pull_request"] - _paths: ["lib/fmt/**", "formatters/**","ci/gha/fmt.*"] + _paths: ["lib/fmt/**", "formatters/**", "ci/gha/fmt.cue", ".github/workflows/fmt.yml"] on: { for evt in _on { (evt): paths: _paths } } on: workflow_dispatch: {} + env: HOF_TELEMETRY_DISABLED: "1" jobs: formatter: { "runs-on": "ubuntu-latest" + environment: "hof mod testing" strategy: { "fail-fast": false matrix: formatter: common.Formatters @@ -24,9 +26,10 @@ ghacue.#Workflow & { steps: [ common.Steps.checkout, common.Steps.vars, - common.Steps.docker.qemu, - common.Steps.docker.setup, - common.Steps.docker.formatters, + common.Steps.buildx.qemu, + common.Steps.buildx.setup, + common.Steps.docker.login, + common.Steps.buildx.formatters, ] } } diff --git a/ci/gha/hof.cue b/ci/gha/hof.cue index 4f471b4ad..d4e9e9e76 100644 --- a/ci/gha/hof.cue +++ b/ci/gha/hof.cue @@ -30,20 +30,19 @@ ghacue.#Workflow & { name: "Build CLI" run: "go install ./cmd/hof" }, - common.Steps.docker.setup & { - "if": "${{ !startsWith( runner.os, 'macos') }}" - }, - common.Steps.docker.compat & { - "if": "${{ !startsWith( runner.os, 'macos') }}" - }, + common.Steps.docker.setup, + common.Steps.docker.macos, + common.Steps.docker.login, + common.Steps.docker.compat, { name: "Build Formatters" run: """ make formatters + docker images hof fmt start hof fmt info + docker ps -a """ - "if": "${{ !startsWith( runner.os, 'macos') }}" }, ] + #TestSteps } @@ -51,7 +50,6 @@ ghacue.#Workflow & { #TestSteps: [...{ env: { - HOFMOD_SSHKEY: "${{secrets.HOFMOD_SSHKEY}}" GITHUB_TOKEN: "${{secrets.HOFMOD_TOKEN}}" } }] @@ -101,6 +99,7 @@ ghacue.#Workflow & { hof flow -f test/mod ./test.cue """ env: { + HOFMOD_SSHKEY: "${{secrets.HOFMOD_SSHKEY}}" GITLAB_TOKEN: "${{secrets.GITLAB_TOKEN}}" BITBUCKET_USERNAME: "hofstadter" BITBUCKET_PASSWORD: "${{secrets.BITBUCKET_TOKEN}}" @@ -109,8 +108,11 @@ ghacue.#Workflow & { // should probably be last? name: "test/fmt" run: """ + docker ps -a hof fmt info hof flow -f test/fmt ./test.cue """ - "if": "${{ !startsWith( runner.os, 'macos') }}" + env: { + HOF_FMT_DEBUG: "1" + } }] diff --git a/ci/gha/release-docs.cue b/ci/gha/release-docs.cue index 5034ce12a..46fb7a69e 100644 --- a/ci/gha/release-docs.cue +++ b/ci/gha/release-docs.cue @@ -24,6 +24,7 @@ ghacue.#Workflow & { } } } + env: HOF_TELEMETRY_DISABLED: "1" jobs: { docs: { diff --git a/ci/gha/release.cue b/ci/gha/release.cue index 93603d650..e6622c4f0 100644 --- a/ci/gha/release.cue +++ b/ci/gha/release.cue @@ -11,6 +11,7 @@ ghacue.#Workflow & { on: push: { tags: ["v*"] } + env: HOF_TELEMETRY_DISABLED: "1" jobs: { goreleaser: { @@ -19,8 +20,8 @@ ghacue.#Workflow & { steps: [ common.Steps.checkout, common.Steps.vars, - common.Steps.docker.qemu, - common.Steps.docker.setup, + common.Steps.buildx.qemu, + common.Steps.buildx.setup, common.Steps.docker.login, common.Steps.go.setup, common.Steps.go.deps, @@ -38,10 +39,10 @@ ghacue.#Workflow & { steps: [ common.Steps.checkout, common.Steps.vars, - common.Steps.docker.qemu, - common.Steps.docker.setup, + common.Steps.buildx.qemu, + common.Steps.buildx.setup, common.Steps.docker.login, - common.Steps.docker.formatters & { with: push: true }, + common.Steps.buildx.formatters & { with: push: true }, ] } } diff --git a/docs/README.md b/docs/README.md index 764fb222f..f193dec68 100644 --- a/docs/README.md +++ b/docs/README.md @@ -8,7 +8,8 @@ Documentation website for _Hofstadter. You'll need a recent version of [Hugo](https://gohugo.io) __extended__ from https://github.com/gohugoio/hugo/releases. (make sure to get the "hugo_extended_..." version for your system) ```sh -make dev +make first +make run of make run.codespace ``` You should now be able to edit pages live. Hugo will print a link for previewing. diff --git a/docs/code/hof-schemas/create/create.cue b/docs/code/hof-schemas/create/create.cue index 6544fd5dc..3d331746f 100644 --- a/docs/code/hof-schemas/create/create.cue +++ b/docs/code/hof-schemas/create/create.cue @@ -7,6 +7,10 @@ package create // it's contents should likely align with the prompt nesting Input: {...} + // extra args provided by user when calling `hof create [args]` + // Filled by hof, you can map these to inputs however you like + Args: [...string] + // Init time inputs and prompts // if an entry will is already set by flags, it will be skipped Prompt: [...#Question] diff --git a/docs/code/hof-schemas/gen/generator.cue b/docs/code/hof-schemas/gen/generator.cue index d0189ff63..76ee48243 100644 --- a/docs/code/hof-schemas/gen/generator.cue +++ b/docs/code/hof-schemas/gen/generator.cue @@ -61,7 +61,7 @@ import ( Partials: [...#Templates] | *[#Templates & {Globs: ["./partials/**/*"], TrimPrefix: "./partials/"}] // Statics are copied directly into the output, bypassing the rendering - Statics: [...#Statics] | *[#Statics & {Globs: ["./static/**/*"], TrimPrefix: "./static/"}] + Statics: [...#Statics] | *[#Statics & {Globs: ["./statics/**/*"], TrimPrefix: "./statics/"}] // The following mirror their non-embedded versions // however they have the content as a string in CUE diff --git a/docs/code/hof-schemas/gen/template.cue b/docs/code/hof-schemas/gen/template.cue index 495d6b417..157371803 100644 --- a/docs/code/hof-schemas/gen/template.cue +++ b/docs/code/hof-schemas/gen/template.cue @@ -8,7 +8,7 @@ package gen } #SubdirTemplates: { - #subdir: string + #subdir: string | *"." Templates: [{ Globs: ["\(#subdir)/templates/**/*"] TrimPrefix: "\(#subdir)/templates/" diff --git a/docs/hack/make/run.inc b/docs/hack/make/run.inc index 8909f89d3..1ac4707db 100644 --- a/docs/hack/make/run.inc +++ b/docs/hack/make/run.inc @@ -1,11 +1,12 @@ -# run locally in dev mode -.PHONY: dev +.PHONY: dev stg codespace + dev: config.yaml @hugo serve --bind 0.0.0.0 --buildDrafts --buildFuture --disableFastRender -# run locally in prd mode -.PHONY: prd stg: config.yaml @hugo serve --bind 0.0.0.0 --disableFastRender +codespace: config.yaml + @hugo serve --baseUrl=/ --appendPort=false --bind 0.0.0.0 --buildDrafts --buildFuture --disableFastRender + diff --git a/formatters/test/00_test.go b/formatters/test/00_test.go index 8eb5c3c15..790046b35 100644 --- a/formatters/test/00_test.go +++ b/formatters/test/00_test.go @@ -10,8 +10,10 @@ import ( func envSetup(env *runtime.Env) error { env.Vars = append(env.Vars, "HOF_TELEMETRY_DISABLED=1") + env.Vars = append(env.Vars, "DOCKER_HOST=" + os.Getenv("DOCKER_HOST")) env.Vars = append(env.Vars, "GITHUB_TOKEN=" + os.Getenv("GITHUB_TOKEN")) env.Vars = append(env.Vars, "HOF_FMT_VERSION=" + os.Getenv("HOF_FMT_VERSION")) + env.Vars = append(env.Vars, "HOF_FMT_DEBUG=" + os.Getenv("HOF_FMT_DEBUG")) return nil } diff --git a/lib/docker/client.go b/lib/docker/client.go index 5769747bd..838a0ac1d 100644 --- a/lib/docker/client.go +++ b/lib/docker/client.go @@ -13,6 +13,7 @@ func InitDockerClient() (err error) { dockerClient, err = client.NewClientWithOpts( client.FromEnv, client.WithAPIVersionNegotiation(), + client.WithHostFromEnv(), ) if err != nil { return fmt.Errorf("error: hof fmt requires docker\n%w", err) diff --git a/lib/docker/containers.go b/lib/docker/containers.go index 68c802d46..a26033fae 100644 --- a/lib/docker/containers.go +++ b/lib/docker/containers.go @@ -30,7 +30,7 @@ func GetContainers(ref string) ([]types.Container, error) { ) } -func StartContainer(ref, name string) error { +func StartContainer(ref, name string, env []string) error { // just try to pull, if already present this will not be noticed err := MaybePullImage(ref) if err != nil { @@ -50,6 +50,7 @@ func StartContainer(ref, name string) error { // todo, maybe walk back versions? (dirty -> latest release) &container.Config{ Image: ref, + Env: env, }, // hostConfig diff --git a/lib/fmt/cmd.go b/lib/fmt/cmd.go index a4d60b0f8..78020af06 100644 --- a/lib/fmt/cmd.go +++ b/lib/fmt/cmd.go @@ -5,7 +5,6 @@ import ( "os" "path/filepath" "strings" - "time" "github.com/olekukonko/tablewriter" @@ -184,6 +183,7 @@ func Start(fmtr string) error { err := docker.StartContainer( fmt.Sprintf("hofstadter/fmt-%s:%s", name, ver), fmt.Sprintf("hof-fmt-%s", name), + fmtrEnvs[name], ) if err != nil { fmt.Println(err) @@ -193,11 +193,12 @@ func Start(fmtr string) error { return docker.StartContainer( fmt.Sprintf("hofstadter/fmt-%s:%s", fmtr, ver), fmt.Sprintf("hof-fmt-%s", fmtr), + fmtrEnvs[fmtr], ) } // TODO, add alive command and wait for ready - time.Sleep(2000*time.Millisecond) + // time.Sleep(2000*time.Millisecond) return nil } diff --git a/lib/fmt/fmtrs.go b/lib/fmt/fmtrs.go index 9d96fb901..d1932bffc 100644 --- a/lib/fmt/fmtrs.go +++ b/lib/fmt/fmtrs.go @@ -9,6 +9,7 @@ import ( "net/http" "os" "path/filepath" + "strconv" "strings" "cuelang.org/go/cue" @@ -29,6 +30,7 @@ var defaultVersion = "dirty" var FORMAT_DISABLED = false var DOCKER_FORMAT_DISABLED = false +var debug = false func init() { v := verinfo.Version @@ -36,6 +38,16 @@ func init() { defaultVersion = "v" + v } + ds := os.Getenv("HOF_FMT_DEBUG") + if ds != "" { + dv, err := strconv.ParseBool(ds) + if err != nil { + fmt.Println("Error parsing HOF_FMT_DEBUG:", err) + } else { + debug = dv + } + } + ov := os.Getenv("HOF_FMT_VERSION") if ov != "" { defaultVersion = ov @@ -46,18 +58,30 @@ func init() { formatters[fmtr] = &Formatter{Name: fmtr, Version: defaultVersion} } - val := os.Getenv("HOF_FORMAT_DISABLED") - if val == "true" || val == "1" { - FORMAT_DISABLED=true - DOCKER_FORMAT_DISABLED=true + val := os.Getenv("HOF_FMT_DISABLED") + if val != "" { + dv, err := strconv.ParseBool(ds) + if err != nil { + fmt.Println("Error parsing HOF_FMT_DISABLED:", err) + } else { + FORMAT_DISABLED=dv + DOCKER_FORMAT_DISABLED=dv + } } // gracefully init images / containers err := Init() if err != nil { + if debug { + fmt.Println("fmt init error:", err) + } DOCKER_FORMAT_DISABLED=true } + if debug { + fmt.Println("FORMAT_DISABLED", FORMAT_DISABLED) + fmt.Println("DOCKER_FORMAT_DISABLED", DOCKER_FORMAT_DISABLED) + } } func Init() error { @@ -98,6 +122,14 @@ var fmtrNames = []string{ "prettier", } +var fmtrEnvs = map[string][]string{ + "black": nil, + "csharpier": nil, + "prettier": []string{ + "PRETTIER_RUBY_TIMEOUT_MS=10000", + }, +} + // Map file extensions to formatters var extToFmtr = map[string]string { // python @@ -348,6 +380,10 @@ func FormatSource(filename string, content []byte, fmtrName string, config inter url := "http://localhost:" + fmtr.Port + if debug { + fmt.Printf("fmt calling (%s) %s\n", fmtrTool, url) + } + req, err := http.NewRequest("POST", url, bytes.NewBuffer(bs)) req.Header.Set("Content-Type", "application/json; charset=UTF-8") @@ -368,6 +404,7 @@ func FormatSource(filename string, content []byte, fmtrName string, config inter return content, fmt.Errorf("error while formatting %s", filename) } + fmt.Println(" lens:", len(content), len(body), resp.StatusCode, string(body)) content = body if !bytes.HasSuffix(content, []byte{'\n'}) { diff --git a/test/docker/main.go b/test/docker/main.go index d84ddbda3..c4673e327 100644 --- a/test/docker/main.go +++ b/test/docker/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "os" "github.com/hofstadter-io/hof/lib/docker" ) @@ -13,13 +14,13 @@ func main() { err := docker.InitDockerClient() if err != nil { fmt.Println("Error Initializing Client:", err) - return + os.Exit(1) } client, server, err := docker.GetVersion() if err != nil { fmt.Println("Error getting versions:", err) - return + os.Exit(1) } fmt.Println("client: ", client) @@ -30,13 +31,13 @@ func main() { err = docker.PullImage(img) if err != nil { fmt.Println("Error pulling image:", err) - return + os.Exit(1) } images, err := docker.GetImages(img) if err != nil { fmt.Println("Error detailing image:", err) - return + os.Exit(1) } for _, image := range images {