Merge branch 'release/0.0.4'

This commit is contained in:
wpetit 2022-06-15 21:18:54 +02:00
commit d08e7ea64f
6 changed files with 117 additions and 32 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@
/internal/server/assets/dist/* /internal/server/assets/dist/*
dist/ dist/
/CHANGELOG.md /CHANGELOG.md
/tools

View File

@ -15,9 +15,19 @@ help: ## Display this help
watch: deps ## Watching updated files - live reload watch: deps ## Watching updated files - live reload
( set -o allexport && source .env && set +o allexport && go run -mod=readonly github.com/cortesi/modd/cmd/modd@latest ) ( set -o allexport && source .env && set +o allexport && go run -mod=readonly github.com/cortesi/modd/cmd/modd@latest )
test: deps ## Executing tests .PHONY: help
test: test-go test-install-script ## Executing tests
test-go: deps
( set -o allexport && source .env && set +o allexport && go test -v -race -count=1 $(GOTEST_ARGS) ./... ) ( set -o allexport && source .env && set +o allexport && go test -v -race -count=1 $(GOTEST_ARGS) ./... )
test-install-script: tools/bin/bash_unit
tools/bin/bash_unit ./misc/script/test_install.sh
tools/bin/bash_unit:
mkdir -p tools/bin
cd tools/bin && bash <(curl -s https://raw.githubusercontent.com/pgrange/bash_unit/master/install.sh)
lint: ## Lint sources code lint: ## Lint sources code
golangci-lint run --enable-all $(LINT_ARGS) golangci-lint run --enable-all $(LINT_ARGS)

View File

@ -17,11 +17,28 @@ import (
func Edit() *cli.Command { func Edit() *cli.Command {
flags := commonFlags() flags := commonFlags()
flags = append(flags, &cli.StringFlag{ flags = append(flags,
&cli.StringFlag{
Name: "browser", Name: "browser",
EnvVars: []string{"FORMIDABLE_BROWSER"}, EnvVars: []string{"FORMIDABLE_BROWSER"},
Value: "w3m", Value: "w3m",
}) },
&cli.StringFlag{
Name: "http-host",
EnvVars: []string{"FORMIDABLE_HTTP_HOST"},
Value: "127.0.0.1",
},
&cli.UintFlag{
Name: "http-port",
EnvVars: []string{"FORMIDABLE_HTTP_PORT"},
Value: 0,
},
&cli.BoolFlag{
Name: "no-browser",
EnvVars: []string{"FORMIDABLE_NO_BROWSER"},
Value: false,
},
)
return &cli.Command{ return &cli.Command{
Name: "edit", Name: "edit",
@ -29,6 +46,9 @@ func Edit() *cli.Command {
Flags: flags, Flags: flags,
Action: func(ctx *cli.Context) error { Action: func(ctx *cli.Context) error {
browser := ctx.String("browser") browser := ctx.String("browser")
noBrowser := ctx.Bool("no-browser")
httpPort := ctx.Uint("http-port")
httpHost := ctx.String("http-host")
schema, err := loadSchema(ctx) schema, err := loadSchema(ctx)
if err != nil { if err != nil {
@ -49,6 +69,7 @@ func Edit() *cli.Command {
defer srvCancel() defer srvCancel()
srv := server.New( srv := server.New(
server.WithAddress(httpHost, httpPort),
server.WithSchema(schema), server.WithSchema(schema),
server.WithValues(values), server.WithValues(values),
server.WithDefaults(defaults), server.WithDefaults(defaults),
@ -68,16 +89,38 @@ func Edit() *cli.Command {
log.Printf("listening on %s", url) log.Printf("listening on %s", url)
browserErrs := make(chan error)
browserCtx, browserCancel := context.WithCancel(ctx.Context)
defer browserCancel()
if !noBrowser {
browserErrs = startBrowser(browserCtx, browser, url)
}
select {
case err := <-browserErrs:
srvCancel()
return errors.WithStack(err)
case err := <-srvErrs:
browserCancel()
return errors.WithStack(err)
}
},
}
}
func startBrowser(ctx context.Context, browser, url string) chan error {
cmdErrs := make(chan error) cmdErrs := make(chan error)
cmdCtx, cmdCancel := context.WithCancel(ctx.Context)
defer cmdCancel()
go func() { go func() {
defer func() { defer func() {
close(cmdErrs) close(cmdErrs)
}() }()
cmd := exec.CommandContext(cmdCtx, browser, url) cmd := exec.CommandContext(ctx, browser, url)
cmd.Stdin = os.Stdin cmd.Stdin = os.Stdin
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
@ -89,17 +132,5 @@ func Edit() *cli.Command {
} }
}() }()
select { return cmdErrs
case err := <-cmdErrs:
srvCancel()
return errors.WithStack(err)
case err := <-srvErrs:
cmdCancel()
return errors.WithStack(err)
}
},
}
} }

View File

@ -4,6 +4,7 @@ set -e
FORMIDABLE_RELEASES_URL="https://github.com/Bornholm/formidable/releases" FORMIDABLE_RELEASES_URL="https://github.com/Bornholm/formidable/releases"
FORMIDABLE_DESTDIR="." FORMIDABLE_DESTDIR="."
FORMIDABLE_FILE_BASENAME="frmd" FORMIDABLE_FILE_BASENAME="frmd"
FORMIDABLE_PLATEFORM_SUFFIX="$(uname -s)_$(uname -m)"
function main { function main {
test -z "${FORMIDABLE_VERSION}" && FORMIDABLE_VERSION="$(curl -sfL -o /dev/null -w %{url_effective} "${FORMIDABLE_RELEASES_URL}/latest" | test -z "${FORMIDABLE_VERSION}" && FORMIDABLE_VERSION="$(curl -sfL -o /dev/null -w %{url_effective} "${FORMIDABLE_RELEASES_URL}/latest" |
@ -18,7 +19,7 @@ function main {
} }
test -z "${FORMIDABLE_TMPDIR}" && FORMIDABLE_TMPDIR="$(mktemp -d)" test -z "${FORMIDABLE_TMPDIR}" && FORMIDABLE_TMPDIR="$(mktemp -d)"
export TAR_FILE="${FORMIDABLE_TMPDIR}/${FORMIDABLE_FILE_BASENAME}_${FORMIDABLE_VERSION}_$(uname -s)_$(uname -m).tar.gz" export TAR_FILE="${FORMIDABLE_TMPDIR}/${FORMIDABLE_FILE_BASENAME}_${FORMIDABLE_VERSION}_${FORMIDABLE_PLATEFORM_SUFFIX}.tar.gz"
( (
cd "${FORMIDABLE_TMPDIR}" cd "${FORMIDABLE_TMPDIR}"
@ -26,14 +27,14 @@ function main {
# Download Formidable # Download Formidable
echo "Downloading Formidable ${FORMIDABLE_VERSION}..." echo "Downloading Formidable ${FORMIDABLE_VERSION}..."
curl -sfLo "${TAR_FILE}" \ curl -sfLo "${TAR_FILE}" \
"${FORMIDABLE_RELEASES_URL}/download/${FORMIDABLE_VERSION}/${FORMIDABLE_FILE_BASENAME}_${FORMIDABLE_VERSION}_$(uname -s)_$(uname -m).tar.gz" || "${FORMIDABLE_RELEASES_URL}/download/${FORMIDABLE_VERSION}/${FORMIDABLE_FILE_BASENAME}_${FORMIDABLE_VERSION}_${FORMIDABLE_PLATEFORM_SUFFIX}.tar.gz" ||
( echo "Error while downloading Formidable !" >&2 && exit 1 ) ( echo "Error while downloading Formidable !" >&2 && exit 1 )
# Download checksums # Download checksums
curl -sfLo "checksums.txt" "${FORMIDABLE_RELEASES_URL}/download/${FORMIDABLE_VERSION}/checksums.txt" curl -sfLo "checksums.txt" "${FORMIDABLE_RELEASES_URL}/download/${FORMIDABLE_VERSION}/checksums.txt"
echo "Verifying checksums..." echo "Verifying checksum..."
sha256sum --ignore-missing --quiet --check checksums.txt || check_sum ||
( echo "Error while verifying checksums !" >&2 && exit 1 ) ( echo "Error while verifying checksums !" >&2 && exit 1 )
) )
@ -46,4 +47,10 @@ function main {
echo "You can now use '${FORMIDABLE_DESTDIR}/${FORMIDABLE_FILE_BASENAME}', enjoy !" echo "You can now use '${FORMIDABLE_DESTDIR}/${FORMIDABLE_FILE_BASENAME}', enjoy !"
} }
function check_sum {
set -o pipefail
cat checksums.txt | grep frmd_*_${FORMIDABLE_PLATEFORM_SUFFIX}.tar.gz | sha256sum -c
set +o pipefail
}
main $@ main $@

View File

@ -0,0 +1,36 @@
#!/bin/bash
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}"; )" &> /dev/null && pwd 2> /dev/null; )";
function test_install_ubuntu_20.04 {
cat <<EOF | run_in_docker ubuntu:20.04
apt update && apt install -y curl
bash /src/misc/script/install.sh
test -f ./frmd
EOF
}
function test_install_alpine_3.16 {
cat <<EOF | run_in_docker alpine:3.16
apk add curl
sh /src/misc/script/install.sh
test -f ./frmd
EOF
}
function test_install_fedora_36 {
cat <<EOF | run_in_docker fedora:36
yum install -y util-linux
bash /src/misc/script/install.sh
test -f ./frmd
EOF
}
function run_in_docker {
local image=$1
cat | docker run \
-v "${SCRIPT_DIR}/../..:/src" \
--workdir /tmp \
-i --rm \
${image}
}

View File

@ -1,6 +1,6 @@
{ {
"name": "formidable", "name": "formidable",
"version": "0.0.3", "version": "0.0.4",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"dependencies": {}, "dependencies": {},