Skip to content

Commit

Permalink
Move more functionality into internal/build/build.go
Browse files Browse the repository at this point in the history
and use make targets in CI, pass flag spec YAML through yq

includes result of running `make v2approve`
  • Loading branch information
meatballhat committed Sep 11, 2022
1 parent 375e5df commit 12a3c62
Show file tree
Hide file tree
Showing 6 changed files with 565 additions and 193 deletions.
108 changes: 30 additions & 78 deletions .github/workflows/cli.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
name: Run Tests

on:
push:
branches:
Expand All @@ -9,10 +8,8 @@ on:
pull_request:
branches:
- main

permissions:
contents: read

jobs:
test:
strategy:
Expand All @@ -22,84 +19,46 @@ jobs:
name: ${{ matrix.os }} @ Go ${{ matrix.go }}
runs-on: ${{ matrix.os }}
steps:
- name: Set up Go ${{ matrix.go }}
uses: actions/setup-go@v3
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}

- name: Set PATH
run: echo "${GITHUB_WORKSPACE}/.local/bin" >>"${GITHUB_PATH}"

- name: install goimports
if: matrix.go == '1.19.x' && matrix.os == 'ubuntu-latest'
run: GOBIN=${PWD}/.local/bin go install golang.org/x/tools/cmd/goimports@latest

- name: Checkout Code
uses: actions/checkout@v3

- name: goimports check
if: matrix.go == '1.19.x' && matrix.os == 'ubuntu-latest'
run: test -z $(goimports -l .)

- name: vet
run: go run internal/build/build.go vet

- 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'
run: echo "${GITHUB_WORKSPACE}/.local/bin" | tee -a "${GITHUB_PATH}" >/dev/null
- if: matrix.go == '1.19.x' && matrix.os == 'ubuntu-latest'
run: make ensure-goimports
- uses: actions/checkout@v3
- if: matrix.go == '1.19.x' && matrix.os == 'ubuntu-latest'
run: make lint
- run: make vet
- run: make tag-test
- run: make test
- run: make -C cmd/urfave-cli-genflags
- run: make check-binary-size
- run: make tag-check-binary-size
- run: make yamlfmt
- run: make diffcheck
- run: make v2diff
- if: success() && matrix.go == '1.19.x' && matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true

test-docs:
name: test-docs
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v3
- uses: actions/setup-go@v3
with:
go-version: 1.19.x

- name: Use Node.js 16
uses: actions/setup-node@v3
- uses: actions/setup-node@v3
with:
node-version: '16'

- name: Set PATH
run: echo "${GITHUB_WORKSPACE}/.local/bin" >>"${GITHUB_PATH}"

- name: Checkout Code
uses: actions/checkout@v3

- 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/v2/

- name: diff check
run: |
git diff --exit-code
git diff --cached --exit-code
run: echo "${GITHUB_WORKSPACE}/.local/bin" | tee -a "${GITHUB_PATH}" >/dev/null
- uses: actions/checkout@v3
- run: make ensure-gfmrun
- run: make gfmrun
- run: make diffcheck
publish:
permissions:
contents: write
Expand All @@ -108,18 +67,11 @@ jobs:
needs: [test-docs]
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup mkdocs
run: |
pip install -U pip
pip install -r mkdocs-requirements.txt
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
- run: make ci-ensure-mkdocs
- run: make set-mkdocs-remote
env:
MKDOCS_REMOTE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: make deploy-mkdocs
20 changes: 11 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,39 @@
# are very important so that maintainers and contributors can focus their
# attention on files that are primarily Go.

GO_RUN_BUILD := go run internal/build/build.go

.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
# defined in internal/build/build.go with optional arguments passed
# via GFLAGS (global flags) and FLAGS (command-specific flags), e.g.:
#
# $ make test GFLAGS='--packages cli'
%:
go run internal/build/build.go $(GFLAGS) $* $(FLAGS)
$(GO_RUN_BUILD) $(GFLAGS) $* $(FLAGS)

.PHONY: 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
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
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
docs:
mkdocs build

.PHONY: docs-deps
docs-deps:
pip install -r mkdocs-requirements.txt

.PHONY: serve-docs
serve-docs:
mkdocs serve
2 changes: 1 addition & 1 deletion docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ following `make` targets may be used if desired:

```sh
# install documentation dependencies with `pip`
make docs-deps
make ensure-mkdocs
```

```sh
Expand Down
19 changes: 9 additions & 10 deletions flag-spec.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# NOTE: this file is used by the tool defined in
# ./cmd/urfave-cli-genflags/main.go which uses the
# `Spec` type that maps to this file structure.

flag_types:
bool:
bool:
struct_fields:
- name: Count
- name: Count
type: int
pointer: true
float64:
float64:
Float64Slice:
value_pointer: true
skip_interfaces:
Expand All @@ -33,18 +32,18 @@ flag_types:
struct_fields:
- name: Base
type: int
UintSlice:
UintSlice:
value_pointer: true
skip_interfaces:
- fmt.Stringer
uint64:
struct_fields:
- name: Base
type: int
Uint64Slice:
Uint64Slice:
value_pointer: true
skip_interfaces:
- fmt.Stringer
- fmt.Stringer
string:
struct_fields:
- name: TakesFile
Expand All @@ -56,12 +55,12 @@ flag_types:
struct_fields:
- name: TakesFile
type: bool
time.Duration:
time.Duration:
Timestamp:
value_pointer: true
struct_fields:
- name: Layout
type: string
- name: Layout
type: string
- name: Timezone
type: "*time.Location"
Generic:
Expand Down
Loading

0 comments on commit 12a3c62

Please sign in to comment.