From 3cec1efc9c2fe50bdbd98fe60c47d7b293b53db5 Mon Sep 17 00:00:00 2001 From: Tony Worm Date: Sat, 25 Feb 2023 21:07:15 -0500 Subject: [PATCH] hof/docs: ci work --- .github/workflows/docs.yml | 22 +-- .github/workflows/release-docs.yml | 63 +++++++- ci/gha/common/steps.cue | 55 +++++++ ci/gha/docs.cue | 34 +---- ci/gha/release-docs.cue | 52 ++++++- docs/.gitignore | 9 +- docs/Makefile | 14 +- docs/ci/cuelm.cue | 2 +- docs/code/Makefile | 5 + docs/code/cmd-help/hof | 2 +- docs/code/cmd-help/mod | 135 +++++++----------- docs/code/first-example/Makefile | 9 +- docs/code/first-example/data-layer/Makefile | 1 - .../data-layer/cue.mod/module.cue | 4 +- .../first-example/data-layer/cue.mod/sums.cue | 4 +- .../simple-server/cue.mod/module.cue | 4 +- .../simple-server/cue.mod/sums.cue | 4 +- docs/code/first-example/web-client/Makefile | 1 - .../content/templates/index-init.html | 1 + .../web-client/cue.mod/module.cue | 4 +- .../first-example/web-client/cue.mod/sums.cue | 4 +- .../web-client/partials/footer.html | 5 + .../web-client/partials/header.html | 13 ++ .../web-client/partials/navbar.html | 17 +++ .../web-client/partials/resource-form.html | 9 ++ .../web-client/partials/resource-modal.html | 21 +++ .../web-client/templates/index.html | 11 ++ .../web-client/templates/resource.html | 20 +++ docs/code/flow/Makefile | 1 - docs/content/code-generation/data-files.md | 10 ++ .../template-writing/_index.md | 6 +- .../template-writing/helpers.md | 5 + .../first-example/adding-features/_index.md | 3 +- docs/content/getting-started/create.md | 2 +- docs/content/reference/hof-gen/_index.md | 2 - .../reference/hof-gen/adhoc-file-gen.md | 2 +- docs/hack/deps.sh | 21 +++ docs/hack/make/code.inc | 4 +- docs/hack/make/deps.inc | 19 +-- docs/hack/make/extern.inc | 2 +- docs/hack/make/publish.inc | 38 ++--- docs/hack/make/test.inc | 2 +- .../authd/sshconfig/vendor__priv_github.txt | 2 +- .../authd/sshkey/vendor__priv_all.txt | 8 +- lib/mod/testdata/noauth_deps.txt | 20 +++ lib/repos/cache/fetch.go | 22 +-- lib/repos/git/fetch.go | 5 + script/runtime/cmd_env.go | 8 +- 48 files changed, 494 insertions(+), 213 deletions(-) create mode 100644 docs/code/Makefile delete mode 100644 docs/code/first-example/data-layer/Makefile delete mode 100644 docs/code/first-example/web-client/Makefile create mode 100644 docs/code/first-example/web-client/content/templates/index-init.html create mode 100644 docs/code/first-example/web-client/partials/footer.html create mode 100644 docs/code/first-example/web-client/partials/header.html create mode 100644 docs/code/first-example/web-client/partials/navbar.html create mode 100644 docs/code/first-example/web-client/partials/resource-form.html create mode 100644 docs/code/first-example/web-client/partials/resource-modal.html create mode 100644 docs/code/first-example/web-client/templates/index.html create mode 100644 docs/code/first-example/web-client/templates/resource.html delete mode 100644 docs/code/flow/Makefile create mode 100644 docs/content/code-generation/data-files.md create mode 100755 docs/hack/deps.sh create mode 100644 lib/mod/testdata/noauth_deps.txt diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index f50f4b2d9..802232a9b 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -8,6 +8,14 @@ jobs: docs: runs-on: ubuntu-latest steps: + - run: |- + mkdir tmp + cd tmp + wget https://github.com/cue-lang/cue/releases/download/v0.5.0-beta.5/cue_v0.5.0-beta.5_linux_amd64.tar.gz -O cue.tar.gz + tar -xf cue.tar.gz + sudo mv cue /usr/local/bin/cue + cd ../ + rm -rf tmp - name: Install Go uses: actions/setup-go@v3 with: @@ -39,18 +47,16 @@ jobs: - name: Build hof run: go install ./cmd/hof - name: Setup - run: "cd docs\nmake first " - - name: Test - run: |- - cd docs - make test - - name: Build run: |- + hof fmt start prettier@v0.6.8-beta.6 cd docs - make build - - name: Check + hof mod link + make deps + - name: Test run: |- cd docs + make gen + make test make run & make broken-link strategy: {} diff --git a/.github/workflows/release-docs.yml b/.github/workflows/release-docs.yml index ac7f83655..1ad926fc7 100644 --- a/.github/workflows/release-docs.yml +++ b/.github/workflows/release-docs.yml @@ -2,11 +2,43 @@ name: release (docs) "on": push: tags: - - docs-* + - docs-** + workflow_dispatch: + inputs: + deploy: + description: where to deploy + required: true + default: next + type: choice + options: + - next + - prod jobs: docs: runs-on: ubuntu-latest + environment: hof docs steps: + - run: |- + mkdir tmp + cd tmp + wget https://github.com/cue-lang/cue/releases/download/v0.5.0-beta.5/cue_v0.5.0-beta.5_linux_amd64.tar.gz -O cue.tar.gz + tar -xf cue.tar.gz + sudo mv cue /usr/local/bin/cue + cd ../ + rm -rf tmp + - name: Install Go + uses: actions/setup-go@v3 + with: + go-version: 1.20.x + - uses: actions/cache@v3 + with: + path: |- + ~/go/pkg/mod + ~/.cache/go-build + ~/Library/Caches/go-build + ~\AppData\Local\go-build + key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }} + restore-keys: ${{ runner.os }}-go-${{ matrix.go-version }}- - name: Checkout code uses: actions/checkout@v3 - name: Setup Vars @@ -20,7 +52,34 @@ jobs: fi echo "HOF_SHA=${SHA}" >> $GITHUB_ENV echo "HOF_TAG=${TAG}" >> $GITHUB_ENV - - name: Setup + - name: Fetch Go deps + run: go mod download + - name: Build hof run: go install ./cmd/hof + - name: Setup + run: |- + hof fmt start prettier@v0.6.8-beta.6 + cd docs + hof mod link + make deps + - name: Build + run: |- + cd docs + make gen + make hugo.next + - name: GCloud Auth + uses: google-github-actions/auth@v1 + with: + credentials_json: ${{ secrets.HOF_GCLOUD_JSON }} + - name: GCloud Setup + uses: google-github-actions/setup-gcloud@v1 + - name: Docker Auth + run: gcloud auth configure-docker + - name: Image + run: |- + cd docs + make docker + make push + make deploy.next.view strategy: {} services: {} diff --git a/ci/gha/common/steps.cue b/ci/gha/common/steps.cue index 94b1e4461..1b7277c46 100644 --- a/ci/gha/common/steps.cue +++ b/ci/gha/common/steps.cue @@ -24,6 +24,21 @@ Steps: { """ } + cue: { + install: { + #ver: string | *"v0.5.0-beta.5" + run: """ + mkdir tmp + cd tmp + wget https://github.com/cue-lang/cue/releases/download/\(#ver)/cue_\(#ver)_linux_amd64.tar.gz -O cue.tar.gz + tar -xf cue.tar.gz + sudo mv cue /usr/local/bin/cue + cd ../ + rm -rf tmp + """ + } + } + go: { setup: { #ver: string | *(string & Versions.go) @@ -110,5 +125,45 @@ Steps: { } } + + gcloud: { + auth: { + name: "GCloud Auth" + uses: "google-github-actions/auth@v1" + with: credentials_json: "${{ secrets.HOF_GCLOUD_JSON }}" + } + setup: { + name: "GCloud Setup" + uses: "google-github-actions/setup-gcloud@v1" + } + + dockerAuth: { + name: "Docker Auth" + run: """ + gcloud auth configure-docker + """ + } + } + + hof: { + install: { + name: "Build hof" + run: "go install ./cmd/hof" + } + } + + docs: { + + setup: { + name: "Setup" + run: """ + hof fmt start prettier@v0.6.8-beta.6 + cd docs + hof mod link + make deps + """ + } + + } } diff --git a/ci/gha/docs.cue b/ci/gha/docs.cue index e4817d545..074dd4cc9 100644 --- a/ci/gha/docs.cue +++ b/ci/gha/docs.cue @@ -15,44 +15,25 @@ ghacue.#Workflow & { jobs: { docs: { "runs-on": "ubuntu-latest" - // environment: "hof docs" steps: [ + // general setup + common.Steps.cue.install, common.Steps.go.setup & { #ver: "1.20.x" }, common.Steps.go.cache, common.Steps.checkout, common.Steps.vars, common.Steps.go.deps, - { - name: "Build hof" - run: "go install ./cmd/hof" - }, - { - name: "Setup" - run: """ - cd docs - make first - """ - }, + common.Steps.hof.install, + + // dev build site & test + common.Steps.docs.setup, { name: "Test" run: """ cd docs + make gen make test - """ - }, - { - name: "Build" - run: """ - cd docs - make build - """ - }, - - { - name: "Check" - run: """ - cd docs make run & make broken-link """ @@ -61,4 +42,3 @@ ghacue.#Workflow & { } } } - diff --git a/ci/gha/release-docs.cue b/ci/gha/release-docs.cue index 1a2c34c75..5034ce12a 100644 --- a/ci/gha/release-docs.cue +++ b/ci/gha/release-docs.cue @@ -8,23 +8,65 @@ import ( ghacue.#Workflow & { name: "release (docs)" - on: push: { - tags: ["docs-*"] + on: { + push: { + tags: ["docs-**"] + } + workflow_dispatch: { + inputs: { + deploy: { + description: "where to deploy" + required: true + default: "next" + type: "choice" + options: ["next", "prod"] + } + } + } } jobs: { docs: { "runs-on": "ubuntu-latest" - // environment: "hof docs" + environment: "hof docs" steps: [ + // general setup + common.Steps.cue.install, + common.Steps.go.setup & { #ver: "1.20.x" }, + common.Steps.go.cache, common.Steps.checkout, common.Steps.vars, + common.Steps.go.deps, + common.Steps.hof.install, + + // prod build site & image + common.Steps.docs.setup, { - name: "Setup" - run: "go install ./cmd/hof" + name: "Build" + + run: """ + cd docs + make gen + make hugo.next + """ }, + // gcloud auth setup + common.Steps.gcloud.auth, + common.Steps.gcloud.setup, + common.Steps.gcloud.dockerAuth, + + // push image & deploy + { + name: "Image" + run: """ + cd docs + make docker + make push + make deploy.next.view + """ + }, ] } } diff --git a/docs/.gitignore b/docs/.gitignore index 589d2f263..66b47f870 100644 --- a/docs/.gitignore +++ b/docs/.gitignore @@ -1,7 +1,14 @@ /dist/ /resources/ -/code/*.html + +# ignore html files generatied from cue files /code/**/*.html +# remember html files we manually write for examples +!/code/**/templates/*.html +!/code/**/templates/**/*.html +!/code/**/partials/*.html +!/code/**/partials/**/*.html + # /code/flow/examples/ # /code/flow/schemas/ /cue.mod/pkg/ diff --git a/docs/Makefile b/docs/Makefile index 542ee77e1..3975545b0 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -1,7 +1,7 @@ include ./hack/make/*.inc -TAG = $(shell git rev-parse --short HEAD | tr -d "\n") -PROJECT = "hof-io--develop" +COMMIT = $(shell git rev-parse --short HEAD | tr -d "\n") +PROJECT = "hof-io--develop" help: @cat Makefile @@ -11,15 +11,13 @@ run: dev lint: fmt broken-link test: verify -.PHONY: fmt broken-link code highlight +.PHONY: fmt broken-link highlight fmt: cuefmt gofmt broken-link: blc.dev -examples: gen highlight: highlight-cue # build the world and push to production -.PHONY: first setup publish -first: deps setup -setup: config.yaml extern code highlight -publish: setup build deploy +.PHONY: first gen +first: deps gen +gen: config.yaml extern examples highlight diff --git a/docs/ci/cuelm.cue b/docs/ci/cuelm.cue index 041185d97..4a2133056 100644 --- a/docs/ci/cuelm.cue +++ b/docs/ci/cuelm.cue @@ -20,7 +20,7 @@ Update: schema.#List & { #Site: { _Values: { - name: "hof-docs" + name: string | *"hof-docs" @tag(name) namespace: "websites" registry: "us.gcr.io/hof-io--develop" diff --git a/docs/code/Makefile b/docs/code/Makefile new file mode 100644 index 000000000..295119e5f --- /dev/null +++ b/docs/code/Makefile @@ -0,0 +1,5 @@ +gen: + make -C first-example gen + +test: + make -C first-example test diff --git a/docs/code/cmd-help/hof b/docs/code/cmd-help/hof index 5488957ee..80892cd55 100644 --- a/docs/code/cmd-help/hof +++ b/docs/code/cmd-help/hof @@ -11,7 +11,7 @@ Main commands: gen modular and composable code gen: CUE & data + templates = _ flow run CUE pipelines with the hof/flow DAG engine fmt format any code and manage the formatters - mod go style dependency management for CUE + mod CUE dependency management based on Go mods Additional commands: help help about any command diff --git a/docs/code/cmd-help/mod b/docs/code/cmd-help/mod index 8fe533db4..4658dda6c 100644 --- a/docs/code/cmd-help/mod +++ b/docs/code/cmd-help/mod @@ -1,65 +1,31 @@ -hof mod is a flexible tool and library based on Go mods. - -Use and create module systems with Minimum Version Selection (MVS) semantics -and manage dependencies go mod style. Mix any set of language, code bases, -git repositories, package managers, and subdirectories. - - -### Features - -- Based on go mods MVS system, aiming for 100% reproducible builds. -- Recursive dependencies, version resolution, and code instrospection. -- Custom module systems with custom file names and vendor directories. -- Control configuration for naming, vendoring, and other behaviors. -- Polyglot support for multiple module systems and multiple languages within one tool. -- Works with any git system and supports the main features from go mods. -- Convert other vendor and module systems to MVS or just manage their files with MVS. -- Private repository support for GitHub, GitLab, Bitbucket, and git+SSH. - - -### Usage - -# Print known languages in the current directory -hof mod info - -# Initialize this folder as a module -hof mod init - -# Add your requirements -vim .mods # go.mod like file - -# Pull in dependencies, no args discovers by *.mods and runs all -hof mod vendor [langs...] - -# See all of the commands -hof mod help - +hof mod is CUE dependency management based on Go mods. ### Module File The module file holds the requirements for project. -It has the same format as a go.mod file. +It is found in cue.mod/module.cue --- -# These are like golang import paths -# i.e. github.com/hofstadter-io/hof -module - -# Information about the module type / version -# some systems that take this into account -# go = 1.14 - = - -# Required dependencies section -require ( - # - github.com/hof-lang/cuemod--cli-golang v0.0.0 # This is latest on HEAD - github.com/hof-lang/cuemod--cli-golang v0.1.5 # This is a tag v0.1.5 (can omit 'v' in tag, but not here) -) - -# replace => [version] -replace github.com/hof-lang/cuemod--cli-golang => github.com/hofstadter-io/hofmod-cli-golang v0.2.0 -replace github.com/hof-lang/cuemod--cli-golang => ../../cuelibs/cuemod--cli-golang +// These are like golang import paths +// i.e. github.com/hofstadter-io/hof +module: "" +cue: "v0.5.0" + +// Required dependencies section +require: { + // "": "" + "github.com/hofstadter-io/ghacue": "v0.2.0" + "github.com/hofstadter-io/hofmod-cli": "v0.8.1" +} + +// Indirect dependencies (managed by hof) +indirect: { ... } + +// Replace dependencies with local or remote +replace: { + "github.com/hofstadter-io/ghacue": "github.com/myorg/ghacue": "v0.4.2" + "github.com/hofstadter-io/hofmod-cli": "../mods/clie" +} --- @@ -67,41 +33,50 @@ replace github.com/hof-lang/cuemod--cli-golang => ../../cuelibs/cuemod--cli-gola hof mod prefers authenticated requests when fetching dependencies. This increase rate limits with hosts and supports private modules. -Both token and sshkey base methods are supported. +Both token and sshkey base methods are supported, with preferences: -If you are using credentials, then private modules can be transparent. -An ENV VAR like GOPRIVATE and CUEPRIVATE can be used to require credentials. +1. Matching entry in .netrc -The following ENV VARS are used to set credentials. +2. ENV VARS for well known hosts. -GITHUB_TOKEN -GITLAB_TOKEN -BITBUCKET_TOKEN or BITBUCKET_USERNAME / BITBUCKET_PASSWORD * + GITHUB_TOKEN + GITLAB_TOKEN + BITBUCKET_USERNAME / BITBUCKET_PASSWORD or BITBUCKET_TOKEN -SSH keys will be looked up in the following ~/.ssh/config, /etc/ssh/config, ~/.ssh/in_rsa + The bitbucket method will depend on the account type and enterprise license. -You can configure the SSH key with +3. SSH keys -HOF_SSHUSR and HOF_SSHKEY + the following are searched: ~/.ssh/config, /etc/ssh/config, ~/.ssh/in_rsa -* The bitbucket method will depend on the account type and enterprise license. + You can configure the SSH key with HOF_SSHUSR and HOF_SSHKEY -### Custom Module Systems +### Usage -.mvsconfig.cue allows you to define custom module systems. -With some simple configuration, you can create and control -and vendored module system based on go mods. -You can also define global configurations. +# Initialize this folder as a module (github.com/org/repo) +hof mod init -See the ./lib/mod/langs in the repository for examples. +# Add or update a dependency +hof mod get github.com/hofstadter-io/hof@latest +hof mod get github.com/hofstadter-io/hof@v0.6.8 +hof mod get github.com/hofstadter-io/hof@v0.6.8-beta.6 -### Motivation +# Tidy module files +hof mod tidy -- MVS has better semantics for vendoring and gets us closer to 100% reproducible builds. -- JS and Python can have MVS while still using the remainder of the tool chains. -- Prototype for cuelang module and vendor management. -- We need a module system for our [hof-lang](https://hof-lang.org) project. +# symlink dependencies from local cache +hof mod link + +# copy dependency code from local cache +hof mod vendor + +# update dependencies +hof mod get github.com/hofstadter-io/hof@latest +hof mod get all@latest + +# print help +hof mod help Usage: hof mod [command] @@ -112,12 +87,12 @@ Aliases: Available Commands: get add a new dependency to the current module init initialize a new module in the current directory + link symlink dependencies to cue.mod/pkg tidy recalculate dependencies and update mod files vendor copy dependencies to cue.mod/pkg Flags: - -h, --help help for mod - -u, --update update dependencies while processing + -h, --help help for mod Global Flags: -p, --package string the Cue package context to use during execution diff --git a/docs/code/first-example/Makefile b/docs/code/first-example/Makefile index 0ac633052..c8fa23470 100644 --- a/docs/code/first-example/Makefile +++ b/docs/code/first-example/Makefile @@ -1,5 +1,8 @@ .PHONY: gen gen: - cd simple-server && hof mod tidy && hof gen ./examples/ - cd data-layer && hof mod tidy && hof gen ./examples/ - cd web-client && hof mod tidy && hof gen ./examples/ + cd simple-server && hof mod link && hof gen ./examples/ + cd data-layer && hof mod link && hof gen ./examples/ + cd web-client && hof mod link && hof gen ./examples/ + +test: gen + git diff --exit-code diff --git a/docs/code/first-example/data-layer/Makefile b/docs/code/first-example/data-layer/Makefile deleted file mode 100644 index 1734d40f9..000000000 --- a/docs/code/first-example/data-layer/Makefile +++ /dev/null @@ -1 +0,0 @@ -include ../../make.inc diff --git a/docs/code/first-example/data-layer/cue.mod/module.cue b/docs/code/first-example/data-layer/cue.mod/module.cue index 7618f4322..1c5ef5744 100644 --- a/docs/code/first-example/data-layer/cue.mod/module.cue +++ b/docs/code/first-example/data-layer/cue.mod/module.cue @@ -2,10 +2,10 @@ module: "hof.io/docs/example" cue: "0.5.0" require: { - "github.com/hofstadter-io/hof": "v0.6.8-beta.5" + "github.com/hofstadter-io/hof": "v0.6.8-beta.6" } indirect: { "github.com/hofstadter-io/ghacue": "v0.2.0" - "github.com/hofstadter-io/hofmod-cli": "v0.8.0" + "github.com/hofstadter-io/hofmod-cli": "v0.8.1" } diff --git a/docs/code/first-example/data-layer/cue.mod/sums.cue b/docs/code/first-example/data-layer/cue.mod/sums.cue index 6feb684ee..83508d931 100644 --- a/docs/code/first-example/data-layer/cue.mod/sums.cue +++ b/docs/code/first-example/data-layer/cue.mod/sums.cue @@ -1,5 +1,5 @@ sums: { "github.com/hofstadter-io/ghacue": "v0.2.0": ["h1:SRQO1Mj2w41v5cgGXYIZ6KP3XRGOv3TaBY0DwG2Slfg="] - "github.com/hofstadter-io/hof": "v0.6.8-beta.5": ["h1:GjPeRH+r9KVfCFBgv4Zq3A9GiHVbuqkDXWaAQ2MGSmk="] - "github.com/hofstadter-io/hofmod-cli": "v0.8.0": ["h1:0XtTwF4MC/BNxOSMiAQGCBT9945K+JnkCFP/ymASRGo="] + "github.com/hofstadter-io/hof": "v0.6.8-beta.6": ["h1:fsT5BijPf4SDsVf4Ca5rdoM5nIUxPfPg1sqXInndFiI="] + "github.com/hofstadter-io/hofmod-cli": "v0.8.1": ["h1:NFixNFvKRB7VftEqUiK31AnddCTIijgupu+gfoqlRVw="] } diff --git a/docs/code/first-example/simple-server/cue.mod/module.cue b/docs/code/first-example/simple-server/cue.mod/module.cue index 7618f4322..1c5ef5744 100644 --- a/docs/code/first-example/simple-server/cue.mod/module.cue +++ b/docs/code/first-example/simple-server/cue.mod/module.cue @@ -2,10 +2,10 @@ module: "hof.io/docs/example" cue: "0.5.0" require: { - "github.com/hofstadter-io/hof": "v0.6.8-beta.5" + "github.com/hofstadter-io/hof": "v0.6.8-beta.6" } indirect: { "github.com/hofstadter-io/ghacue": "v0.2.0" - "github.com/hofstadter-io/hofmod-cli": "v0.8.0" + "github.com/hofstadter-io/hofmod-cli": "v0.8.1" } diff --git a/docs/code/first-example/simple-server/cue.mod/sums.cue b/docs/code/first-example/simple-server/cue.mod/sums.cue index 6feb684ee..83508d931 100644 --- a/docs/code/first-example/simple-server/cue.mod/sums.cue +++ b/docs/code/first-example/simple-server/cue.mod/sums.cue @@ -1,5 +1,5 @@ sums: { "github.com/hofstadter-io/ghacue": "v0.2.0": ["h1:SRQO1Mj2w41v5cgGXYIZ6KP3XRGOv3TaBY0DwG2Slfg="] - "github.com/hofstadter-io/hof": "v0.6.8-beta.5": ["h1:GjPeRH+r9KVfCFBgv4Zq3A9GiHVbuqkDXWaAQ2MGSmk="] - "github.com/hofstadter-io/hofmod-cli": "v0.8.0": ["h1:0XtTwF4MC/BNxOSMiAQGCBT9945K+JnkCFP/ymASRGo="] + "github.com/hofstadter-io/hof": "v0.6.8-beta.6": ["h1:fsT5BijPf4SDsVf4Ca5rdoM5nIUxPfPg1sqXInndFiI="] + "github.com/hofstadter-io/hofmod-cli": "v0.8.1": ["h1:NFixNFvKRB7VftEqUiK31AnddCTIijgupu+gfoqlRVw="] } diff --git a/docs/code/first-example/web-client/Makefile b/docs/code/first-example/web-client/Makefile deleted file mode 100644 index 1734d40f9..000000000 --- a/docs/code/first-example/web-client/Makefile +++ /dev/null @@ -1 +0,0 @@ -include ../../make.inc diff --git a/docs/code/first-example/web-client/content/templates/index-init.html b/docs/code/first-example/web-client/content/templates/index-init.html new file mode 100644 index 000000000..64174ecd1 --- /dev/null +++ b/docs/code/first-example/web-client/content/templates/index-init.html @@ -0,0 +1 @@ +

Welcome to the {{ $.SERVER.Name }} client

diff --git a/docs/code/first-example/web-client/cue.mod/module.cue b/docs/code/first-example/web-client/cue.mod/module.cue index 7618f4322..1c5ef5744 100644 --- a/docs/code/first-example/web-client/cue.mod/module.cue +++ b/docs/code/first-example/web-client/cue.mod/module.cue @@ -2,10 +2,10 @@ module: "hof.io/docs/example" cue: "0.5.0" require: { - "github.com/hofstadter-io/hof": "v0.6.8-beta.5" + "github.com/hofstadter-io/hof": "v0.6.8-beta.6" } indirect: { "github.com/hofstadter-io/ghacue": "v0.2.0" - "github.com/hofstadter-io/hofmod-cli": "v0.8.0" + "github.com/hofstadter-io/hofmod-cli": "v0.8.1" } diff --git a/docs/code/first-example/web-client/cue.mod/sums.cue b/docs/code/first-example/web-client/cue.mod/sums.cue index 6feb684ee..83508d931 100644 --- a/docs/code/first-example/web-client/cue.mod/sums.cue +++ b/docs/code/first-example/web-client/cue.mod/sums.cue @@ -1,5 +1,5 @@ sums: { "github.com/hofstadter-io/ghacue": "v0.2.0": ["h1:SRQO1Mj2w41v5cgGXYIZ6KP3XRGOv3TaBY0DwG2Slfg="] - "github.com/hofstadter-io/hof": "v0.6.8-beta.5": ["h1:GjPeRH+r9KVfCFBgv4Zq3A9GiHVbuqkDXWaAQ2MGSmk="] - "github.com/hofstadter-io/hofmod-cli": "v0.8.0": ["h1:0XtTwF4MC/BNxOSMiAQGCBT9945K+JnkCFP/ymASRGo="] + "github.com/hofstadter-io/hof": "v0.6.8-beta.6": ["h1:fsT5BijPf4SDsVf4Ca5rdoM5nIUxPfPg1sqXInndFiI="] + "github.com/hofstadter-io/hofmod-cli": "v0.8.1": ["h1:NFixNFvKRB7VftEqUiK31AnddCTIijgupu+gfoqlRVw="] } diff --git a/docs/code/first-example/web-client/partials/footer.html b/docs/code/first-example/web-client/partials/footer.html new file mode 100644 index 000000000..9a998d822 --- /dev/null +++ b/docs/code/first-example/web-client/partials/footer.html @@ -0,0 +1,5 @@ + + + + + diff --git a/docs/code/first-example/web-client/partials/header.html b/docs/code/first-example/web-client/partials/header.html new file mode 100644 index 000000000..e5478672a --- /dev/null +++ b/docs/code/first-example/web-client/partials/header.html @@ -0,0 +1,13 @@ + + + + + + + + + {{ .SERVER.Name }} + + + + diff --git a/docs/code/first-example/web-client/partials/navbar.html b/docs/code/first-example/web-client/partials/navbar.html new file mode 100644 index 000000000..46f646682 --- /dev/null +++ b/docs/code/first-example/web-client/partials/navbar.html @@ -0,0 +1,17 @@ + diff --git a/docs/code/first-example/web-client/partials/resource-form.html b/docs/code/first-example/web-client/partials/resource-form.html new file mode 100644 index 000000000..d3cd80042 --- /dev/null +++ b/docs/code/first-example/web-client/partials/resource-form.html @@ -0,0 +1,9 @@ +{{ $R := $.RESOURCE }} + diff --git a/docs/code/first-example/web-client/partials/resource-modal.html b/docs/code/first-example/web-client/partials/resource-modal.html new file mode 100644 index 000000000..c20e07e68 --- /dev/null +++ b/docs/code/first-example/web-client/partials/resource-modal.html @@ -0,0 +1,21 @@ +{{ $R := $.RESOURCE }} + + + + + diff --git a/docs/code/first-example/web-client/templates/index.html b/docs/code/first-example/web-client/templates/index.html new file mode 100644 index 000000000..b30fb06ea --- /dev/null +++ b/docs/code/first-example/web-client/templates/index.html @@ -0,0 +1,11 @@ +{{ template "header.html" . }} +
+ {{ template "navbar.html" . }} + +
+
+ Welcome to the {{ $.SERVER.Name }} client +
+
+
+{{ template "footer.html" . }} diff --git a/docs/code/first-example/web-client/templates/resource.html b/docs/code/first-example/web-client/templates/resource.html new file mode 100644 index 000000000..227a4fd51 --- /dev/null +++ b/docs/code/first-example/web-client/templates/resource.html @@ -0,0 +1,20 @@ +{{ template "header.html" . }} +
+ {{ template "navbar.html" . }} + +
+
+

+ {{ $.RESOURCE.Name }}s + {{ template "resource-modal.html" . }} +

+
+
+
+      
+
+
+
+ + +{{ template "footer.html" . }} diff --git a/docs/code/flow/Makefile b/docs/code/flow/Makefile deleted file mode 100644 index 821cacca3..000000000 --- a/docs/code/flow/Makefile +++ /dev/null @@ -1 +0,0 @@ -include ../make.inc diff --git a/docs/content/code-generation/data-files.md b/docs/content/code-generation/data-files.md new file mode 100644 index 000000000..32df713bb --- /dev/null +++ b/docs/content/code-generation/data-files.md @@ -0,0 +1,10 @@ +--- +title: "Data Files" +weight: 50 +--- + +How to work with data files in hof gen + +- data placement - `hof gen data.json@MyGen.In gen.cue` +- data generation - using datafile config in #File +- data formatting - on by default, stable key order diff --git a/docs/content/code-generation/template-writing/_index.md b/docs/content/code-generation/template-writing/_index.md index 16501e0a5..e502e8a57 100644 --- a/docs/content/code-generation/template-writing/_index.md +++ b/docs/content/code-generation/template-writing/_index.md @@ -5,8 +5,10 @@ weight: 20 ## Template System -Hof uses Go's `text/template` package (https://pkg.go.dev/text/template). -All partials are registered with all templates for use with `{{ template "path/to/partial.ext" }}`. +Hof uses Go's `text/template` package adding several helpers. +You can put both full templates and partial (reusable) template snippets +in directorys or the generator definition. +All partials will be registered with all templates for use with `{{ template "path/to/partial.ext" }}`. #### Sections: diff --git a/docs/content/code-generation/template-writing/helpers.md b/docs/content/code-generation/template-writing/helpers.md index 09d22158e..69057e44b 100644 --- a/docs/content/code-generation/template-writing/helpers.md +++ b/docs/content/code-generation/template-writing/helpers.md @@ -18,6 +18,11 @@ Notes: - It can be advantagous to do as many manipulations in CUE rather than in the template system. +`text/template` documentation can be found here: +https://pkg.go.dev/text/template + + + ### Encode to a data format: - `json` (`{{ json .Data }}`) diff --git a/docs/content/first-example/adding-features/_index.md b/docs/content/first-example/adding-features/_index.md index 32dc53133..10b095154 100644 --- a/docs/content/first-example/adding-features/_index.md +++ b/docs/content/first-example/adding-features/_index.md @@ -19,6 +19,7 @@ showing off the compounding capabilities of code generation. - Nested routes and resources - watch for changes with `hof flow` + diff --git a/docs/content/getting-started/create.md b/docs/content/getting-started/create.md index a21c159a2..7c1e03ea8 100644 --- a/docs/content/getting-started/create.md +++ b/docs/content/getting-started/create.md @@ -77,7 +77,7 @@ initial files needed to use their module. To learn more about writing creators, prompts, and how to give your users one-line bootstrapping or application blueprints, see the -[hof create section](/hof-create/) +[hof create section](/code-generation/creators/) ## Creator vs Generator Module diff --git a/docs/content/reference/hof-gen/_index.md b/docs/content/reference/hof-gen/_index.md index d57548b8e..8a3f5445f 100644 --- a/docs/content/reference/hof-gen/_index.md +++ b/docs/content/reference/hof-gen/_index.md @@ -13,8 +13,6 @@ rather than dozens of source code, test files, and database schemas. We are working on this concurrently with the datamodels work. Like that section, we will post links here as they become available. -As always, [join us in chat to learn more](https://gitter.im/hofstadter-io). - The goal here is to emit code from Cue in a general and language agnostic way. This is the best example right now: https://github.com/hofstadter-io/hofmod-cli (edited) diff --git a/docs/content/reference/hof-gen/adhoc-file-gen.md b/docs/content/reference/hof-gen/adhoc-file-gen.md index 8c0ea6bb2..3b8954d7c 100644 --- a/docs/content/reference/hof-gen/adhoc-file-gen.md +++ b/docs/content/reference/hof-gen/adhoc-file-gen.md @@ -14,7 +14,7 @@ you can write to generate any file from any data. #### Learn about writing templates, with extra functions and helpers -[Template writing docs](/reference/template-writing/) +[Template writing docs](/code-generation/template-writing/)
diff --git a/docs/hack/deps.sh b/docs/hack/deps.sh new file mode 100755 index 000000000..e6d65f44a --- /dev/null +++ b/docs/hack/deps.sh @@ -0,0 +1,21 @@ +#!/bin/bash +set -eou pipefail + +# setup the development workspace + +HUGO_VER="0.109.0" + +npm install +ln -s ../node_modules assets/node_modules +npm install broken-link-checker -g +mkdir tmp + +pushd tmp + +wget https://github.com/gohugoio/hugo/releases/download/v${HUGO_VER}/hugo_extended_${HUGO_VER}_Linux-64bit.tar.gz -O hugo.tar.gz +tar -xf hugo.tar.gz +chmod +x hugo +sudo mv hugo /usr/local/bin/hugo + +popd +rm -rf tmp diff --git a/docs/hack/make/code.inc b/docs/hack/make/code.inc index f240cef97..800bacabb 100644 --- a/docs/hack/make/code.inc +++ b/docs/hack/make/code.inc @@ -18,6 +18,6 @@ code/%.html: code/%.cue @echo highlight "$<" as "$@" @node hack/highlight.js < "$<" > "$@" -.PHONY: gen-output-examples -gen: +.PHONY: examples +examples: make -C code/first-example gen diff --git a/docs/hack/make/deps.inc b/docs/hack/make/deps.inc index ef122ce3d..ff0e2cfaa 100644 --- a/docs/hack/make/deps.inc +++ b/docs/hack/make/deps.inc @@ -1,21 +1,4 @@ -HUGO_VER = "0.109.0" - -# setup the development workspacce -# missing is install hugo... -# convert to hof/flow? .PHONY: deps deps: - npm install - npm install broken-link-checker -g - mkdir tmp - - cd tmp - wget https://github.com/gohugoio/hugo/releases/download/v$(HUGO_VER)/hugo_extended_$(HUGO_VER)_Linux-64bit.tar.gz - tar -xf hugo.tar.gz - chmod +x hugo - sudo mv hugo /usr/local/bin/hugo - cd ../ - rm -rf tmp - - + ./hack/deps.sh diff --git a/docs/hack/make/extern.inc b/docs/hack/make/extern.inc index 931bb4abf..46d050d9f 100644 --- a/docs/hack/make/extern.inc +++ b/docs/hack/make/extern.inc @@ -3,7 +3,7 @@ extern: cmdhelp schemas schemas: # todo, get from github @ version - cp -r ~/hof/hof/schema/* code/hof-schemas + cp -r ../schema/* code/hof-schemas .PHONY: cmdhelp cmdhelp: diff --git a/docs/hack/make/publish.inc b/docs/hack/make/publish.inc index e632fcbac..a51e5b26d 100644 --- a/docs/hack/make/publish.inc +++ b/docs/hack/make/publish.inc @@ -1,37 +1,39 @@ build: hugo docker -release: push deploy config.yaml: config.cue cue export config.cue --out yaml --outfile config.yaml --force -.PHONY: hugo -hugo: config.yaml +.PHONY: hugo hugo.prod +hugo: hugo.prod +hugo.prod: config.yaml @rm -rf dist @hugo --baseURL https://docs.hofstadter.io/ -d dist +hugo.next: config.yaml + @rm -rf dist + @hugo --baseURL https://next.hofstadter.io/ -d dist .PHONY: docker -docker: image push +docker: image .PHONY: image image: - @docker build --no-cache -f ci/Dockerfile -t us.gcr.io/$(PROJECT)/docs.hofstadter.io:$(TAG) . + @docker build --no-cache -f ci/Dockerfile -t us.gcr.io/$(PROJECT)/docs.hofstadter.io:$(COMMIT) . .PHONY: nginx nginx: - @docker run --rm -it -p 8080:80 --name hof-docs us.gcr.io/$(PROJECT)/docs.hofstadter.io:$(TAG) + @docker run --rm -it -p 8080:80 --name hof-docs us.gcr.io/$(PROJECT)/docs.hofstadter.io:$(COMMIT) .PHONY: push push: - @docker push us.gcr.io/$(PROJECT)/docs.hofstadter.io:$(TAG) - -.PHONY: deploy -deploy: - @cue export ci/cuelm.cue -t version=$(TAG) -e Install | kubectl apply -f - - -.PHONY: deploy-view -deploy-view: - @cue export ci/cuelm.cue -t version=$(TAG) -e Install - - - + @docker push us.gcr.io/$(PROJECT)/docs.hofstadter.io:$(COMMIT) + +.PHONY: deploy.prod deploy.prod.view deploy.next deploy.next.view +deploy.prod: + @cue export ci/cuelm.cue -t version=$(COMMIT) -e Install | kubectl apply -f - +deploy.prod.view: + @cue export ci/cuelm.cue -t version=$(COMMIT) -e Install +deploy.next: + @cue export ci/cuelm.cue -t version=$(COMMIT) -t name=hof-next-docs -t domain="next.hofstadter.io" -e Install | kubectl apply -f - +deploy.next.view: + @cue export ci/cuelm.cue -t version=$(COMMIT) -t name=hof-next-docs -t domain="next.hofstadter.io" -e Install diff --git a/docs/hack/make/test.inc b/docs/hack/make/test.inc index 2689bbd84..6ff8b1778 100644 --- a/docs/hack/make/test.inc +++ b/docs/hack/make/test.inc @@ -5,4 +5,4 @@ verify_diff: @git diff --exit-code code/ verify_code: - make -C code all + make -C code test diff --git a/lib/mod/testdata/authd/sshconfig/vendor__priv_github.txt b/lib/mod/testdata/authd/sshconfig/vendor__priv_github.txt index 22040e3a3..547574e6c 100644 --- a/lib/mod/testdata/authd/sshconfig/vendor__priv_github.txt +++ b/lib/mod/testdata/authd/sshconfig/vendor__priv_github.txt @@ -1,5 +1,5 @@ # hof mod vendor - with deps -env GITHUB_TOKEN="" +env GITHUB_TOKEN= exec hof mod vendor -- cue.mod/module.cue -- diff --git a/lib/mod/testdata/authd/sshkey/vendor__priv_all.txt b/lib/mod/testdata/authd/sshkey/vendor__priv_all.txt index 28455739b..4d1024c41 100644 --- a/lib/mod/testdata/authd/sshkey/vendor__priv_all.txt +++ b/lib/mod/testdata/authd/sshkey/vendor__priv_all.txt @@ -3,10 +3,10 @@ env HOF_PRIVATE=github.com,gitlab.com,bitbucket.org ## blankout token vars for this test -env GITHUB_TOKEN="" -env GITLAB_TOKEN="" -env BITBUCKET_USERNAME="" -env BITBUCKET_PASSWORD="" +env GITHUB_TOKEN= +env GITLAB_TOKEN= +env BITBUCKET_USERNAME= +env BITBUCKET_PASSWORD= ## setup default sshkey auth mkdir $HOME/.ssh diff --git a/lib/mod/testdata/noauth_deps.txt b/lib/mod/testdata/noauth_deps.txt new file mode 100644 index 000000000..44fa63df0 --- /dev/null +++ b/lib/mod/testdata/noauth_deps.txt @@ -0,0 +1,20 @@ +env GITHUB_TOKEN= +env GITLAB_TOKEN= +env BITBUCKET_USERNAME= +env BITBUCKET_PASSWORD= + +hof mod tidy + +-- cue.mod/module.cue -- +module: "github.com/hofstadter-io/hof-docs" +cue: "v0.4.3" + +require: { + "github.com/hofstadter-io/cuelm": "v0.1.0" + "github.com/hofstadter-io/harmony-cue": "v0.2.0" +} + +indirect: { + "github.com/hofstadter-io/harmony": "v0.2.0" +} + diff --git a/lib/repos/cache/fetch.go b/lib/repos/cache/fetch.go index 2d73c7721..ae783fc51 100644 --- a/lib/repos/cache/fetch.go +++ b/lib/repos/cache/fetch.go @@ -2,7 +2,7 @@ package cache import ( "fmt" - "sort" + "strings" "github.com/go-git/go-billy/v5" "github.com/go-git/go-billy/v5/osfs" @@ -55,22 +55,28 @@ func GetLatestTag(path string, pre bool) (string, error) { return "", err } - var tags []string + best := "" refs.ForEach(func (ref *plumbing.Reference) error { n := ref.Name().Short() + + // skip any tags which do not start with v + if !strings.HasPrefix(n, "v") { + return nil + } + // maybe filter prereleases if !pre && semver.Prerelease(n) != "" { return nil } - tags = append(tags, n) + + // update best? + if best == "" || semver.Compare(n, best) > 0 { + best = n + } return nil }) - sort.Slice(tags, func(i, j int) bool { - // sort so greatest is at front - return semver.Compare(tags[i], tags[j]) > 0 - }) - return tags[0], nil + return best, nil } /* diff --git a/lib/repos/git/fetch.go b/lib/repos/git/fetch.go index 6d70b62b0..66ca91c9e 100644 --- a/lib/repos/git/fetch.go +++ b/lib/repos/git/fetch.go @@ -177,6 +177,7 @@ func getAuth(remote, owner, repo string) (auth transport.AuthMethod, err error) Password: netrc.Password, } } else if strings.Contains(remote, "github.com") && os.Getenv("GITHUB_TOKEN") != "" { + fmt.Println(remote, os.Getenv("GITHUB_TOKEN")) auth = &http.BasicAuth{ Username: "github-token", // yes, this can be anything except an empty string Password: os.Getenv("GITHUB_TOKEN"), @@ -202,6 +203,10 @@ func getAuth(remote, owner, repo string) (auth transport.AuthMethod, err error) auth = ssh.Keys } + // no auth found, so don't return any + if auth == nil { + return nil, nil + } if debug { fmt.Println("cache auth:", remote, auth) } diff --git a/script/runtime/cmd_env.go b/script/runtime/cmd_env.go index 4c7b38077..6c6a07afe 100644 --- a/script/runtime/cmd_env.go +++ b/script/runtime/cmd_env.go @@ -61,8 +61,12 @@ func (ts *Script) CmdEnv(neg int, args []string) { } // else, split and do things - k, v := env[:i], env[i+1:] - if v[0] == '@' { + parts := strings.Split(env, "=") + k, v := parts[0], "" + if len(parts) > 1 { + v = parts[1] + } + if len(v) > 0 && v[0] == '@' { fname := v[1:] // for error messages if fname == "stdout" { v = ts.stdout