mirror of
https://github.com/Bornholm/formidable.git
synced 2024-12-22 23:09:33 +01:00
Merge branch 'release/0.0.4'
This commit is contained in:
commit
d08e7ea64f
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@
|
||||
/internal/server/assets/dist/*
|
||||
dist/
|
||||
/CHANGELOG.md
|
||||
/tools
|
||||
|
12
Makefile
12
Makefile
@ -15,9 +15,19 @@ help: ## Display this help
|
||||
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 )
|
||||
|
||||
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) ./... )
|
||||
|
||||
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
|
||||
golangci-lint run --enable-all $(LINT_ARGS)
|
||||
|
||||
|
@ -17,11 +17,28 @@ import (
|
||||
func Edit() *cli.Command {
|
||||
flags := commonFlags()
|
||||
|
||||
flags = append(flags, &cli.StringFlag{
|
||||
Name: "browser",
|
||||
EnvVars: []string{"FORMIDABLE_BROWSER"},
|
||||
Value: "w3m",
|
||||
})
|
||||
flags = append(flags,
|
||||
&cli.StringFlag{
|
||||
Name: "browser",
|
||||
EnvVars: []string{"FORMIDABLE_BROWSER"},
|
||||
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{
|
||||
Name: "edit",
|
||||
@ -29,6 +46,9 @@ func Edit() *cli.Command {
|
||||
Flags: flags,
|
||||
Action: func(ctx *cli.Context) error {
|
||||
browser := ctx.String("browser")
|
||||
noBrowser := ctx.Bool("no-browser")
|
||||
httpPort := ctx.Uint("http-port")
|
||||
httpHost := ctx.String("http-host")
|
||||
|
||||
schema, err := loadSchema(ctx)
|
||||
if err != nil {
|
||||
@ -49,6 +69,7 @@ func Edit() *cli.Command {
|
||||
defer srvCancel()
|
||||
|
||||
srv := server.New(
|
||||
server.WithAddress(httpHost, httpPort),
|
||||
server.WithSchema(schema),
|
||||
server.WithValues(values),
|
||||
server.WithDefaults(defaults),
|
||||
@ -68,38 +89,48 @@ func Edit() *cli.Command {
|
||||
|
||||
log.Printf("listening on %s", url)
|
||||
|
||||
cmdErrs := make(chan error)
|
||||
cmdCtx, cmdCancel := context.WithCancel(ctx.Context)
|
||||
defer cmdCancel()
|
||||
browserErrs := make(chan error)
|
||||
browserCtx, browserCancel := context.WithCancel(ctx.Context)
|
||||
defer browserCancel()
|
||||
|
||||
go func() {
|
||||
defer func() {
|
||||
close(cmdErrs)
|
||||
}()
|
||||
|
||||
cmd := exec.CommandContext(cmdCtx, browser, url)
|
||||
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Env = os.Environ()
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
cmdErrs <- errors.WithStack(err)
|
||||
}
|
||||
}()
|
||||
if !noBrowser {
|
||||
browserErrs = startBrowser(browserCtx, browser, url)
|
||||
}
|
||||
|
||||
select {
|
||||
case err := <-cmdErrs:
|
||||
case err := <-browserErrs:
|
||||
srvCancel()
|
||||
|
||||
return errors.WithStack(err)
|
||||
|
||||
case err := <-srvErrs:
|
||||
cmdCancel()
|
||||
browserCancel()
|
||||
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func startBrowser(ctx context.Context, browser, url string) chan error {
|
||||
cmdErrs := make(chan error)
|
||||
|
||||
go func() {
|
||||
defer func() {
|
||||
close(cmdErrs)
|
||||
}()
|
||||
|
||||
cmd := exec.CommandContext(ctx, browser, url)
|
||||
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Env = os.Environ()
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
cmdErrs <- errors.WithStack(err)
|
||||
}
|
||||
}()
|
||||
|
||||
return cmdErrs
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ set -e
|
||||
FORMIDABLE_RELEASES_URL="https://github.com/Bornholm/formidable/releases"
|
||||
FORMIDABLE_DESTDIR="."
|
||||
FORMIDABLE_FILE_BASENAME="frmd"
|
||||
FORMIDABLE_PLATEFORM_SUFFIX="$(uname -s)_$(uname -m)"
|
||||
|
||||
function main {
|
||||
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)"
|
||||
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}"
|
||||
@ -26,14 +27,14 @@ function main {
|
||||
# Download Formidable
|
||||
echo "Downloading Formidable ${FORMIDABLE_VERSION}..."
|
||||
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 )
|
||||
|
||||
# Download checksums
|
||||
curl -sfLo "checksums.txt" "${FORMIDABLE_RELEASES_URL}/download/${FORMIDABLE_VERSION}/checksums.txt"
|
||||
|
||||
echo "Verifying checksums..."
|
||||
sha256sum --ignore-missing --quiet --check checksums.txt ||
|
||||
echo "Verifying checksum..."
|
||||
check_sum ||
|
||||
( 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 !"
|
||||
}
|
||||
|
||||
function check_sum {
|
||||
set -o pipefail
|
||||
cat checksums.txt | grep frmd_*_${FORMIDABLE_PLATEFORM_SUFFIX}.tar.gz | sha256sum -c
|
||||
set +o pipefail
|
||||
}
|
||||
|
||||
main $@
|
36
misc/script/test_install.sh
Normal file
36
misc/script/test_install.sh
Normal 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}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "formidable",
|
||||
"version": "0.0.3",
|
||||
"version": "0.0.4",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"dependencies": {},
|
||||
|
Loading…
Reference in New Issue
Block a user