Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mod docs n tests #71

Merged
merged 32 commits into from
Sep 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
fe4fbb8
move mod cred helpers to yagu for more general usage
verdverm Aug 8, 2021
f202e6a
push mod fetch details into remote types
verdverm Aug 8, 2021
a3678d6
fix private github zip fetching and add test
verdverm Aug 8, 2021
06eca95
enable github auth for testing mods
verdverm Aug 8, 2021
d545a85
remove some print statements
verdverm Aug 8, 2021
d3a29ef
fixup some api tests, enable expected failures, run api tests in work…
verdverm Aug 8, 2021
821818d
use custom secret for hofmod
verdverm Aug 9, 2021
072d279
fix var interpolation in workflow
verdverm Aug 9, 2021
94567c1
start breaking out more GHA workflows
verdverm Aug 24, 2021
dd9bc15
flatten for test_mod to work(flow)
verdverm Aug 24, 2021
42f97fc
uncomment the actaul test...
verdverm Aug 24, 2021
fb90b70
add fail case when auth not present
verdverm Aug 26, 2021
aa0ce81
update some repo deps, cleanup a bit of logic, make notes about auth …
verdverm Aug 26, 2021
8e7a1b5
add private gitlab mod test
verdverm Aug 26, 2021
5d48525
add GITLAB_TOKEN to vars passed during mod test, make easier to expand
verdverm Aug 26, 2021
3701fe4
breakout windows into own workflow; switch trigger to push
verdverm Aug 26, 2021
0ef11eb
fix windows workflow cue
verdverm Aug 26, 2021
4510aa5
change test_mod trigger to push
verdverm Aug 26, 2021
f94e45a
try seeing if path matching works on full PR changeset
verdverm Aug 26, 2021
77e454e
remove windows workflows, too many issues with GHA and the code base;…
verdverm Aug 31, 2021
1f59219
add lookup for default pub key when ssh config not found; start tests…
verdverm Aug 31, 2021
a894c2c
fix some errors
verdverm Aug 31, 2021
b6b20da
push code with ssh_config issue
verdverm Sep 1, 2021
01ec0ec
add bitbucket support
verdverm Sep 11, 2021
a05413f
create GHA env for mod testing, update secrets
verdverm Sep 13, 2021
6cafd87
update mod test file triggers
verdverm Sep 13, 2021
a00a5d2
add bitbucket apikey test; iterate on sshkey test
verdverm Sep 13, 2021
4a6707b
work on sshkey auth test
verdverm Sep 13, 2021
132b89d
empty more vars in sshkey test
verdverm Sep 13, 2021
75dff8e
fix bbc auth vars used in testing; remove a bunch of debug prints
verdverm Sep 13, 2021
ae5e877
fix var name with sshkey auth
verdverm Sep 13, 2021
a6ba252
update mod docs
verdverm Sep 19, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/common/base.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package common

import "github.com/hofstadter-io/ghacue"

#Workflow: ghacue.#Workflow & {
name: string
on: _ | *["pull_request"]
jobs: test: {
strategy: matrix: {
"go-version": ["1.16.x", "1.17.x"]
os: ["ubuntu-latest", "macos-latest"]
}
strategy: "fail-fast": false
"runs-on": "${{ matrix.os }}"
}
}

#BuildSteps: [{
name: "Install Go"
uses: "actions/setup-go@v2"
with: "go-version": "${{ matrix.go-version }}"
},{
name: "Checkout code"
uses: "actions/checkout@v2"
},{
name: "Download mods"
run: "go mod download"
},{
name: "Build CLI"
run: "go install ./cmd/hof"
}]
39 changes: 13 additions & 26 deletions .github/workflows/default.cue
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
import "github.com/hofstadter-io/ghacue"
package workflows

ghacue.#Workflow & {
name: "hof"
on: ["push", "pull_request"]
import "github.com/hofstadter-io/hof/.github/workflows/common"

common.#Workflow & {
name: "default"
on: ["push"]
jobs: test: {
strategy: matrix: {
"go-version": ["1.16.x"]
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
}
strategy: "fail-fast": false
"runs-on": "${{ matrix.os }}"
steps: [{
name: "Install Go"
uses: "actions/setup-go@v2"
with: "go-version": "${{ matrix.go-version }}"
},{
name: "Checkout code"
uses: "actions/checkout@v2"
},{
name: "Download mods"
run: "go mod download"
},{
name: "Build CLI"
run: "go install ./cmd/hof"
},{
name: "Run tests"
steps: [ for step in common.#BuildSteps {step} ] + [{
name: "Run gen tests"
run: """
hof test test.cue -s gen -t test
hof test test.cue -s lib -t test -t mod
"""
},{
name: "Run tester tests"
run: """
hof test test/testers/api/postman.cue
"""
}]
}
Expand Down
14 changes: 6 additions & 8 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
name: hof
name: default
on:
- push
- pull_request
jobs:
test:
strategy:
matrix:
go-version:
- 1.16.x
- 1.17.x
os:
- ubuntu-latest
- macos-latest
- windows-latest
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -25,8 +24,7 @@ jobs:
run: go mod download
- name: Build CLI
run: go install ./cmd/hof
- name: Run tests
run: |-
hof test test.cue -s gen -t test
hof test test.cue -s lib -t test -t mod
services: {}
- name: Run gen tests
run: hof test test.cue -s gen -t test
- name: Run tester tests
run: hof test test/testers/api/postman.cue
25 changes: 25 additions & 0 deletions .github/workflows/test_mod.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package workflows

import "github.com/hofstadter-io/hof/.github/workflows/common"

common.#Workflow & {
name: "test_mod"
on: pull_request: { paths: ["lib/mod/**", "lib/yagu/repos/**", "lib/yagu/git.go", "lib/yagu/netrc.go", "lib/yagu/ssh.go"] }
jobs: test: {
environment: "hof mod testing"
steps: [ for step in common.#BuildSteps {step} ] + [{
name: "Run mod tests"
run: """
hof test test.cue -s lib -t test -t mod
"""
env: {
HOFMOD_SSHKEY: "${{secrets.HOFMOD_SSHKEY}}"
GITHUB_TOKEN: "${{secrets.HOFMOD_TOKEN}}"
GITLAB_TOKEN: "${{secrets.GITLAB_TOKEN}}"
BITBUCKET_USERNAME: "hofstadter"
BITBUCKET_PASSWORD: "${{secrets.BITBUCKET_TOKEN}}"
}
}]
}
}

41 changes: 41 additions & 0 deletions .github/workflows/test_mod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: test_mod
on:
pull_request:
paths:
- lib/mod/**
- lib/yagu/repos/**
- lib/yagu/git.go
- lib/yagu/netrc.go
- lib/yagu/ssh.go
jobs:
test:
strategy:
matrix:
go-version:
- 1.16.x
- 1.17.x
os:
- ubuntu-latest
- macos-latest
fail-fast: false
runs-on: ${{ matrix.os }}
environment: hof mod testing
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- name: Download mods
run: go mod download
- name: Build CLI
run: go install ./cmd/hof
- name: Run mod tests
run: hof test test.cue -s lib -t test -t mod
env:
HOFMOD_SSHKEY: ${{secrets.HOFMOD_SSHKEY}}
GITHUB_TOKEN: ${{secrets.HOFMOD_TOKEN}}
GITLAB_TOKEN: ${{secrets.GITLAB_TOKEN}}
BITBUCKET_USERNAME: hofstadter
BITBUCKET_PASSWORD: ${{secrets.BITBUCKET_TOKEN}}
109 changes: 100 additions & 9 deletions .hof/shadow/Cli/cmd/hof/cmd/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,111 @@ import (
"github.com/hofstadter-io/hof/cmd/hof/cmd/mod"
)

var modLong = `The mod subcmd is a polyglot dependency management tool based on go mods.
var modLong = `hof mod is a flexible tool and library based on Go mods.

mod file format:
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.

module = "<module path>"

<name> = "version"
### Features

require (
...
)
- 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.

replace <module path> => <local path>
...`

### Usage

# Print known languages in the current directory
hof mod info

# Initialize this folder as a module
hof mod init <lang> <module-path>

# Add your requirements
vim <lang>.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


### Module File

The module file holds the requirements for project.
It has the same format as a go.mod file.

---
# These are like golang import paths
# i.e. github.com/hofstadter-io/hof
module <module-path>

# Information about the module type / version
# some systems that take this into account
# go = 1.14
<lang> = <version>

# Required dependencies section
require (
# <module-path> <module-semver>
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 <module-path> => <module-path|local-path> [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
---


### Authentication and private modules

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.

If you are using credentials, then private modules can be transparent.
An ENV VAR like GOPRIVATE and CUEPRIVATE can be used to require credentials.

The following ENV VARS are used to set credentials.

GITHUB_TOKEN
GITLAB_TOKEN
BITBUCKET_TOKEN or BITBUCKET_USERNAME / BITBUCKET_PASSWORD *

SSH keys will be looked up in the following ~/.ssh/config, /etc/ssh/config, ~/.ssh/in_rsa

You can configure the SSH key with

HOF_SSHUSR and HOF_SSHKEY

* The bitbucket method will depend on the account type and enterprise license.


### Custom Module Systems

.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.

See the ./lib/mod/langs in the repository for examples.

### Motivation

- 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.
`

func ModPersistentPreRun(args []string) (err error) {

Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,12 @@ cloccode: cmd lang lib gen cmd

clocdev: hof.cue design schema lang lib docs test cue.mods go.mod
cloc --read-lang-def=$$HOME/hof/jumpfiles/assets/cloc_defs.txt --exclude-dir=cue.mod,vendor $^

WORKFLOWS = default \
test_mod

.PHONY: workflow
workflows = $(addprefix workflow_, $(WORKFLOWS))
workflow: $(workflows)
$(workflows): workflow_%:
@cue export --out yaml .github/workflows/$(subst workflow_,,$@).cue > .github/workflows/$(subst workflow_,,$@).yml