Move more functionality into internal/build/build.go
and use make targets in CI, pass flag spec YAML through yq includes result of running `make v2approve`
This commit is contained in:
parent
8e3fa067e0
commit
8cc0a9c5da
107
.github/workflows/cli.yml
vendored
107
.github/workflows/cli.yml
vendored
@ -1,5 +1,4 @@
|
|||||||
name: Run Tests
|
name: Run Tests
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
@ -12,10 +11,8 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
- v3-dev-main
|
- v3-dev-main
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
strategy:
|
strategy:
|
||||||
@ -25,45 +22,26 @@ jobs:
|
|||||||
name: ${{ matrix.os }} @ Go ${{ matrix.go }}
|
name: ${{ matrix.os }} @ Go ${{ matrix.go }}
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
- name: Set up Go ${{ matrix.go }}
|
- uses: actions/setup-go@v3
|
||||||
uses: actions/setup-go@v3
|
|
||||||
with:
|
with:
|
||||||
go-version: ${{ matrix.go }}
|
go-version: ${{ matrix.go }}
|
||||||
|
|
||||||
- name: Set PATH
|
- name: Set PATH
|
||||||
run: echo "${GITHUB_WORKSPACE}/.local/bin" >>"${GITHUB_PATH}"
|
run: echo "${GITHUB_WORKSPACE}/.local/bin" | tee -a "${GITHUB_PATH}" >/dev/null
|
||||||
|
- if: matrix.go == '1.19.x' && matrix.os == 'ubuntu-latest'
|
||||||
- name: install goimports
|
run: make ensure-goimports
|
||||||
if: matrix.go == '1.19.x' && matrix.os == 'ubuntu-latest'
|
- uses: actions/checkout@v3
|
||||||
run: GOBIN=${PWD}/.local/bin go install golang.org/x/tools/cmd/goimports@latest
|
- if: matrix.go == '1.19.x' && matrix.os == 'ubuntu-latest'
|
||||||
|
run: make lint
|
||||||
- name: Checkout Code
|
- run: make vet
|
||||||
uses: actions/checkout@v3
|
- run: make tag-test
|
||||||
|
- run: make test
|
||||||
- name: goimports check
|
- run: make -C cmd/urfave-cli-genflags
|
||||||
if: matrix.go == '1.19.x' && matrix.os == 'ubuntu-latest'
|
- run: make check-binary-size
|
||||||
run: test -z $(goimports -l .)
|
- run: make tag-check-binary-size
|
||||||
|
- run: make yamlfmt
|
||||||
- name: vet
|
- run: make diffcheck
|
||||||
run: go run internal/build/build.go vet
|
- run: make v2diff
|
||||||
|
- if: success() && matrix.go == '1.19.x' && matrix.os == 'ubuntu-latest'
|
||||||
- name: test with urfave_cli_no_docs tag
|
|
||||||
run: go run internal/build/build.go -tags urfave_cli_no_docs test
|
|
||||||
|
|
||||||
- name: test
|
|
||||||
run: go run internal/build/build.go test
|
|
||||||
|
|
||||||
- name: test urfave-cli-genflags
|
|
||||||
run: make -C cmd/urfave-cli-genflags
|
|
||||||
|
|
||||||
- name: check-binary-size
|
|
||||||
run: go run internal/build/build.go check-binary-size
|
|
||||||
|
|
||||||
- name: check-binary-size with tags (informational only)
|
|
||||||
run: go run internal/build/build.go -tags urfave_cli_no_docs check-binary-size
|
|
||||||
|
|
||||||
- name: Upload coverage to Codecov
|
|
||||||
if: success() && matrix.go == '1.19.x' && matrix.os == 'ubuntu-latest'
|
|
||||||
uses: codecov/codecov-action@v3
|
uses: codecov/codecov-action@v3
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.CODECOV_TOKEN }}
|
token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
@ -73,36 +51,18 @@ jobs:
|
|||||||
name: test-docs
|
name: test-docs
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Set up Go
|
- uses: actions/setup-go@v3
|
||||||
uses: actions/setup-go@v3
|
|
||||||
with:
|
with:
|
||||||
go-version: 1.19.x
|
go-version: 1.19.x
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
- name: Use Node.js 16
|
|
||||||
uses: actions/setup-node@v3
|
|
||||||
with:
|
with:
|
||||||
node-version: '16'
|
node-version: '16'
|
||||||
|
|
||||||
- name: Set PATH
|
- name: Set PATH
|
||||||
run: echo "${GITHUB_WORKSPACE}/.local/bin" >>"${GITHUB_PATH}"
|
run: echo "${GITHUB_WORKSPACE}/.local/bin" | tee -a "${GITHUB_PATH}" >/dev/null
|
||||||
|
- uses: actions/checkout@v3
|
||||||
- name: Checkout Code
|
- run: make ensure-gfmrun
|
||||||
uses: actions/checkout@v3
|
- run: make gfmrun
|
||||||
|
- run: make diffcheck
|
||||||
- name: Install Dependencies
|
|
||||||
run: |
|
|
||||||
mkdir -p "${GITHUB_WORKSPACE}/.local/bin"
|
|
||||||
curl -fsSL -o "${GITHUB_WORKSPACE}/.local/bin/gfmrun" "https://github.com/urfave/gfmrun/releases/download/v1.3.0/gfmrun-$(go env GOOS)-$(go env GOARCH)-v1.3.0"
|
|
||||||
chmod +x "${GITHUB_WORKSPACE}/.local/bin/gfmrun"
|
|
||||||
|
|
||||||
- name: gfmrun
|
|
||||||
run: go run internal/build/build.go gfmrun --walk docs/v3/
|
|
||||||
|
|
||||||
- name: diff check
|
|
||||||
run: |
|
|
||||||
git diff --exit-code
|
|
||||||
git diff --cached --exit-code
|
|
||||||
|
|
||||||
publish:
|
publish:
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
@ -114,18 +74,11 @@ jobs:
|
|||||||
needs: [test-docs]
|
needs: [test-docs]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Code
|
- uses: actions/checkout@v3
|
||||||
uses: actions/checkout@v3
|
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
- run: make ci-ensure-mkdocs
|
||||||
- name: Setup mkdocs
|
- run: make set-mkdocs-remote
|
||||||
run: |
|
env:
|
||||||
pip install -U pip
|
MKDOCS_REMOTE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
pip install -r mkdocs-requirements.txt
|
- run: make deploy-mkdocs
|
||||||
git remote rm origin
|
|
||||||
git remote add origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/urfave/cli.git
|
|
||||||
|
|
||||||
- name: Publish Docs
|
|
||||||
run: |
|
|
||||||
mkdocs gh-deploy --force
|
|
||||||
|
20
Makefile
20
Makefile
@ -4,8 +4,10 @@
|
|||||||
# are very important so that maintainers and contributors can focus their
|
# are very important so that maintainers and contributors can focus their
|
||||||
# attention on files that are primarily Go.
|
# attention on files that are primarily Go.
|
||||||
|
|
||||||
|
GO_RUN_BUILD := go run internal/build/build.go
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: generate vet tag-test test check-binary-size tag-check-binary-size gfmrun v2diff
|
all: generate vet tag-test test check-binary-size tag-check-binary-size gfmrun yamlfmt v2diff
|
||||||
|
|
||||||
# NOTE: this is a special catch-all rule to run any of the commands
|
# NOTE: this is a special catch-all rule to run any of the commands
|
||||||
# defined in internal/build/build.go with optional arguments passed
|
# defined in internal/build/build.go with optional arguments passed
|
||||||
@ -13,28 +15,28 @@ all: generate vet tag-test test check-binary-size tag-check-binary-size gfmrun v
|
|||||||
#
|
#
|
||||||
# $ make test GFLAGS='--packages cli'
|
# $ make test GFLAGS='--packages cli'
|
||||||
%:
|
%:
|
||||||
go run internal/build/build.go $(GFLAGS) $* $(FLAGS)
|
$(GO_RUN_BUILD) $(GFLAGS) $* $(FLAGS)
|
||||||
|
|
||||||
.PHONY: tag-test
|
.PHONY: tag-test
|
||||||
tag-test:
|
tag-test:
|
||||||
go run internal/build/build.go -tags urfave_cli_no_docs test
|
$(GO_RUN_BUILD) -tags urfave_cli_no_docs test
|
||||||
|
|
||||||
.PHONY: tag-check-binary-size
|
.PHONY: tag-check-binary-size
|
||||||
tag-check-binary-size:
|
tag-check-binary-size:
|
||||||
go run internal/build/build.go -tags urfave_cli_no_docs check-binary-size
|
$(GO_RUN_BUILD) -tags urfave_cli_no_docs check-binary-size
|
||||||
|
|
||||||
.PHONY: gfmrun
|
.PHONY: gfmrun
|
||||||
gfmrun:
|
gfmrun:
|
||||||
go run internal/build/build.go gfmrun docs/v2/manual.md
|
$(GO_RUN_BUILD) gfmrun --walk docs/v2/
|
||||||
|
|
||||||
|
.PHONY: ci-ensure-mkdocs
|
||||||
|
ci-ensure-mkdocs:
|
||||||
|
$(GO_RUN_BUILD) ensure-mkdocs --upgrade-pip
|
||||||
|
|
||||||
.PHONY: docs
|
.PHONY: docs
|
||||||
docs:
|
docs:
|
||||||
mkdocs build
|
mkdocs build
|
||||||
|
|
||||||
.PHONY: docs-deps
|
|
||||||
docs-deps:
|
|
||||||
pip install -r mkdocs-requirements.txt
|
|
||||||
|
|
||||||
.PHONY: serve-docs
|
.PHONY: serve-docs
|
||||||
serve-docs:
|
serve-docs:
|
||||||
mkdocs serve
|
mkdocs serve
|
||||||
|
@ -107,7 +107,7 @@ following `make` targets may be used if desired:
|
|||||||
|
|
||||||
```sh
|
```sh
|
||||||
# install documentation dependencies with `pip`
|
# install documentation dependencies with `pip`
|
||||||
make docs-deps
|
make ensure-mkdocs
|
||||||
```
|
```
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
@ -5,12 +5,17 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/urfave/cli/v3"
|
"github.com/urfave/cli/v3"
|
||||||
@ -21,6 +26,8 @@ const (
|
|||||||
goodNewsEmoji = "✨"
|
goodNewsEmoji = "✨"
|
||||||
checksPassedEmoji = "✅"
|
checksPassedEmoji = "✅"
|
||||||
|
|
||||||
|
gfmrunVersion = "v1.3.0"
|
||||||
|
|
||||||
v2diffWarning = `
|
v2diffWarning = `
|
||||||
# The unified diff above indicates that the public API surface area
|
# The unified diff above indicates that the public API surface area
|
||||||
# has changed. If you feel that the changes are acceptable and adhere
|
# has changed. If you feel that the changes are acceptable and adhere
|
||||||
@ -45,63 +52,108 @@ func main() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
app := cli.NewApp()
|
app := &cli.App{
|
||||||
|
Name: "builder",
|
||||||
app.Name = "builder"
|
Usage: "Do a thing for urfave/cli! (maybe build?)",
|
||||||
app.Usage = "Generates a new urfave/cli build!"
|
Commands: cli.Commands{
|
||||||
|
{
|
||||||
app.Commands = cli.Commands{
|
Name: "vet",
|
||||||
{
|
Action: topRunAction("go", "vet", "./..."),
|
||||||
Name: "vet",
|
},
|
||||||
Action: VetActionFunc,
|
{
|
||||||
},
|
Name: "test",
|
||||||
{
|
Action: TestActionFunc,
|
||||||
Name: "test",
|
},
|
||||||
Action: TestActionFunc,
|
{
|
||||||
},
|
Name: "gfmrun",
|
||||||
{
|
Flags: []cli.Flag{
|
||||||
Name: "gfmrun",
|
&cli.BoolFlag{
|
||||||
Flags: []cli.Flag{
|
Name: "walk",
|
||||||
&cli.BoolFlag{
|
Value: false,
|
||||||
Name: "walk",
|
Usage: "Walk the specified directory and perform validation on all markdown files",
|
||||||
Value: false,
|
},
|
||||||
Usage: "Walk the specified directory and perform validation on all markdown files",
|
},
|
||||||
|
Action: GfmrunActionFunc,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "check-binary-size",
|
||||||
|
Action: checkBinarySizeActionFunc,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "generate",
|
||||||
|
Action: GenerateActionFunc,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "yamlfmt",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.BoolFlag{Name: "strict", Value: false, Usage: "require presence of yq"},
|
||||||
|
},
|
||||||
|
Action: YAMLFmtActionFunc,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "diffcheck",
|
||||||
|
Action: DiffCheckActionFunc,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "ensure-goimports",
|
||||||
|
Action: EnsureGoimportsActionFunc,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "ensure-gfmrun",
|
||||||
|
Action: EnsureGfmrunActionFunc,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "ensure-mkdocs",
|
||||||
|
Action: EnsureMkdocsActionFunc,
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.BoolFlag{Name: "upgrade-pip"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: GfmrunActionFunc,
|
{
|
||||||
},
|
Name: "set-mkdocs-remote",
|
||||||
{
|
Action: SetMkdocsRemoteActionFunc,
|
||||||
Name: "check-binary-size",
|
Flags: []cli.Flag{
|
||||||
Action: checkBinarySizeActionFunc,
|
&cli.StringFlag{Name: "github-token", Required: true},
|
||||||
},
|
},
|
||||||
{
|
},
|
||||||
Name: "generate",
|
{
|
||||||
Action: GenerateActionFunc,
|
Name: "deploy-mkdocs",
|
||||||
},
|
Action: topRunAction("mkdocs", "gh-deploy", "--force"),
|
||||||
{
|
},
|
||||||
Name: "v2diff",
|
{
|
||||||
Flags: []cli.Flag{
|
Name: "lint",
|
||||||
&cli.BoolFlag{Name: "color", Value: false},
|
Action: LintActionFunc,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "v2diff",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.BoolFlag{Name: "color", Value: false},
|
||||||
|
},
|
||||||
|
Action: V2Diff,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "v2approve",
|
||||||
|
Action: topRunAction(
|
||||||
|
"cp",
|
||||||
|
"-v",
|
||||||
|
"godoc-current.txt",
|
||||||
|
filepath.Join("testdata", "godoc-v2.x.txt"),
|
||||||
|
),
|
||||||
},
|
},
|
||||||
Action: V2Diff,
|
|
||||||
},
|
},
|
||||||
{
|
Flags: []cli.Flag{
|
||||||
Name: "v2approve",
|
&cli.StringFlag{
|
||||||
Action: V2Approve,
|
Name: "tags",
|
||||||
},
|
Usage: "set build tags",
|
||||||
}
|
},
|
||||||
app.Flags = []cli.Flag{
|
&cli.PathFlag{
|
||||||
&cli.StringFlag{
|
Name: "top",
|
||||||
Name: "tags",
|
Value: top,
|
||||||
Usage: "set build tags",
|
},
|
||||||
},
|
&cli.StringSliceFlag{
|
||||||
&cli.PathFlag{
|
Name: "packages",
|
||||||
Name: "top",
|
Value: cli.NewStringSlice("cli", "altsrc", "internal/build"),
|
||||||
Value: top,
|
},
|
||||||
},
|
|
||||||
&cli.StringSliceFlag{
|
|
||||||
Name: "packages",
|
|
||||||
Value: cli.NewStringSlice("cli", "altsrc", "internal/build"),
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,6 +172,14 @@ func sh(exe string, args ...string) (string, error) {
|
|||||||
return string(outBytes), err
|
return string(outBytes), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func topRunAction(arg string, args ...string) cli.ActionFunc {
|
||||||
|
return func(cCtx *cli.Context) error {
|
||||||
|
os.Chdir(cCtx.Path("top"))
|
||||||
|
|
||||||
|
return runCmd(arg, args...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func runCmd(arg string, args ...string) error {
|
func runCmd(arg string, args ...string) error {
|
||||||
cmd := exec.Command(arg, args...)
|
cmd := exec.Command(arg, args...)
|
||||||
|
|
||||||
@ -131,6 +191,43 @@ func runCmd(arg string, args ...string) error {
|
|||||||
return cmd.Run()
|
return cmd.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func downloadFile(src, dest string, dirPerm, perm os.FileMode) error {
|
||||||
|
req, err := http.NewRequest(http.MethodGet, src, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode >= 300 {
|
||||||
|
return fmt.Errorf("download response %[1]v", resp.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := os.MkdirAll(filepath.Dir(dest), dirPerm); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
out, err := os.Create(dest)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := io.Copy(out, resp.Body); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := out.Close(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return os.Chmod(dest, perm)
|
||||||
|
}
|
||||||
|
|
||||||
func VetActionFunc(cCtx *cli.Context) error {
|
func VetActionFunc(cCtx *cli.Context) error {
|
||||||
return runCmd("go", "vet", cCtx.Path("top")+"/...")
|
return runCmd("go", "vet", cCtx.Path("top")+"/...")
|
||||||
}
|
}
|
||||||
@ -145,15 +242,20 @@ func TestActionFunc(c *cli.Context) error {
|
|||||||
packageName = fmt.Sprintf("github.com/urfave/cli/v3/%s", pkg)
|
packageName = fmt.Sprintf("github.com/urfave/cli/v3/%s", pkg)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := runCmd(
|
args := []string{"test"}
|
||||||
"go", "test",
|
if tags != "" {
|
||||||
"-tags", tags,
|
args = append(args, []string{"-tags", tags}...)
|
||||||
|
}
|
||||||
|
|
||||||
|
args = append(args, []string{
|
||||||
"-v",
|
"-v",
|
||||||
"--coverprofile", pkg+".coverprofile",
|
"--coverprofile", pkg + ".coverprofile",
|
||||||
"--covermode", "count",
|
"--covermode", "count",
|
||||||
"--cover", packageName,
|
"--cover", packageName,
|
||||||
packageName,
|
packageName,
|
||||||
); err != nil {
|
}...)
|
||||||
|
|
||||||
|
if err := runCmd("go", args...); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -411,6 +513,125 @@ func GenerateActionFunc(cCtx *cli.Context) error {
|
|||||||
return runCmd("go", "generate", cCtx.Path("top")+"/...")
|
return runCmd("go", "generate", cCtx.Path("top")+"/...")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func YAMLFmtActionFunc(cCtx *cli.Context) error {
|
||||||
|
yqBin, err := exec.LookPath("yq")
|
||||||
|
if err != nil {
|
||||||
|
if !cCtx.Bool("strict") {
|
||||||
|
fmt.Fprintln(cCtx.App.ErrWriter, "# ---> no yq found; skipping")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Chdir(cCtx.Path("top"))
|
||||||
|
|
||||||
|
return runCmd(yqBin, "eval", "--inplace", "flag-spec.yaml")
|
||||||
|
}
|
||||||
|
|
||||||
|
func DiffCheckActionFunc(cCtx *cli.Context) error {
|
||||||
|
os.Chdir(cCtx.Path("top"))
|
||||||
|
|
||||||
|
if err := runCmd("git", "diff", "--exit-code"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return runCmd("git", "diff", "--cached", "--exit-code")
|
||||||
|
}
|
||||||
|
|
||||||
|
func EnsureGoimportsActionFunc(cCtx *cli.Context) error {
|
||||||
|
top := cCtx.Path("top")
|
||||||
|
os.Chdir(top)
|
||||||
|
|
||||||
|
if err := runCmd(
|
||||||
|
"goimports",
|
||||||
|
"-d",
|
||||||
|
filepath.Join(top, "internal/build/build.go"),
|
||||||
|
); err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Setenv("GOBIN", filepath.Join(top, ".local/bin"))
|
||||||
|
|
||||||
|
return runCmd("go", "install", "golang.org/x/tools/cmd/goimports@latest")
|
||||||
|
}
|
||||||
|
|
||||||
|
func EnsureGfmrunActionFunc(cCtx *cli.Context) error {
|
||||||
|
top := cCtx.Path("top")
|
||||||
|
gfmrunExe := filepath.Join(top, ".local/bin/gfmrun")
|
||||||
|
|
||||||
|
os.Chdir(top)
|
||||||
|
|
||||||
|
if v, err := sh(gfmrunExe, "--version"); err == nil && strings.TrimSpace(v) == gfmrunVersion {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
gfmrunURL, err := url.Parse(
|
||||||
|
fmt.Sprintf(
|
||||||
|
"https://github.com/urfave/gfmrun/releases/download/%[1]s/gfmrun-%[2]s-%[3]s-%[1]s",
|
||||||
|
gfmrunVersion, runtime.GOOS, runtime.GOARCH,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return downloadFile(gfmrunURL.String(), gfmrunExe, 0755, 0755)
|
||||||
|
}
|
||||||
|
|
||||||
|
func EnsureMkdocsActionFunc(cCtx *cli.Context) error {
|
||||||
|
os.Chdir(cCtx.Path("top"))
|
||||||
|
|
||||||
|
if err := runCmd("mkdocs", "--version"); err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if cCtx.Bool("upgrade-pip") {
|
||||||
|
if err := runCmd("pip", "install", "-U", "pip"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return runCmd("pip", "install", "-r", "mkdocs-requirements.txt")
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetMkdocsRemoteActionFunc(cCtx *cli.Context) error {
|
||||||
|
ghToken := strings.TrimSpace(cCtx.String("github-token"))
|
||||||
|
if ghToken == "" {
|
||||||
|
return errors.New("empty github token")
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Chdir(cCtx.Path("top"))
|
||||||
|
|
||||||
|
if err := runCmd("git", "remote", "rm", "origin"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return runCmd(
|
||||||
|
"git", "remote", "add", "origin",
|
||||||
|
fmt.Sprintf("https://x-access-token:%[1]s@github.com/urfave/cli.git", ghToken),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func LintActionFunc(cCtx *cli.Context) error {
|
||||||
|
top := cCtx.Path("top")
|
||||||
|
os.Chdir(top)
|
||||||
|
|
||||||
|
out, err := sh(filepath.Join(top, ".local/bin/goimports"), "-l", ".")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.TrimSpace(out) != "" {
|
||||||
|
fmt.Fprintln(cCtx.App.ErrWriter, "# ---> goimports -l is non-empty:")
|
||||||
|
fmt.Fprintln(cCtx.App.ErrWriter, out)
|
||||||
|
|
||||||
|
return errors.New("goimports needed")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func V2Diff(cCtx *cli.Context) error {
|
func V2Diff(cCtx *cli.Context) error {
|
||||||
os.Chdir(cCtx.Path("top"))
|
os.Chdir(cCtx.Path("top"))
|
||||||
|
|
||||||
@ -439,34 +660,29 @@ func V2Diff(cCtx *cli.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func V2Approve(cCtx *cli.Context) error {
|
func getSize(sourcePath, builtPath, tags string) (int64, error) {
|
||||||
top := cCtx.Path("top")
|
args := []string{"build"}
|
||||||
|
|
||||||
return runCmd(
|
if tags != "" {
|
||||||
"cp",
|
args = append(args, []string{"-tags", tags}...)
|
||||||
"-v",
|
}
|
||||||
filepath.Join(top, "godoc-current.txt"),
|
|
||||||
filepath.Join(top, "testdata", "godoc-v2.x.txt"),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getSize(sourcePath string, builtPath string, tags string) (size int64, err error) {
|
args = append(args, []string{
|
||||||
// build example binary
|
"-o", builtPath,
|
||||||
err = runCmd("go", "build", "-tags", tags, "-o", builtPath, "-ldflags", "-s -w", sourcePath)
|
"-ldflags", "-s -w",
|
||||||
if err != nil {
|
sourcePath,
|
||||||
|
}...)
|
||||||
|
|
||||||
|
if err := runCmd("go", args...); err != nil {
|
||||||
fmt.Println("issue getting size for example binary")
|
fmt.Println("issue getting size for example binary")
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// get file info
|
|
||||||
fileInfo, err := os.Stat(builtPath)
|
fileInfo, err := os.Stat(builtPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("issue getting size for example binary")
|
fmt.Println("issue getting size for example binary")
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// size!
|
return fileInfo.Size(), nil
|
||||||
size = fileInfo.Size()
|
|
||||||
|
|
||||||
return size, nil
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user