-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add pkg/config/config.toml * update documentation * document Make targets for autocomplete * remove obsolete Make target from CI * remove typo from code comment * fix tests that caught invalid toml * pkg/config/config.toml dynamically generated * update docs * ensure dependencies are installed * fix config for both mac and linux * fix ci * don't need the comment line as DevHub strips it anyway * whoops, forgot the cp command * Update DEVELOP.md * support windows * CI * fixing all the things * update deprecated set-output syntax * bump CI actions * bump tinygo
- Loading branch information
1 parent
3c5384c
commit fcd188f
Showing
10 changed files
with
180 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,25 +7,45 @@ concurrency: | |
cancel-in-progress: true | ||
|
||
jobs: | ||
config: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: "Checkout code" | ||
uses: actions/checkout@v3 | ||
- name: "Install Rust" | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: stable # to install tomlq via `make config` | ||
- name: "Generate static app config" | ||
run: make config | ||
- name: "Config Artifact" | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: config-artifact-${{ github.sha }} | ||
path: pkg/config/config.toml | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: "Checkout code" | ||
uses: actions/checkout@v2 | ||
uses: actions/checkout@v3 | ||
- name: "Install Rust" | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: stable # to install tomlq via `make vet` pre-requisite | ||
- name: Install Go | ||
uses: actions/setup-go@v2 | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.18.x | ||
- name: "Restore golang bin cache" | ||
id: go-bin-cache | ||
uses: actions/cache@v2 | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/go/bin | ||
key: ${{ runner.os }}-go-bin-${{ hashFiles('~/go/bin') }}-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go-bin- | ||
- name: "Restore golang mod cache" | ||
uses: actions/cache@v2 | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/Library/Caches/go-build | ||
|
@@ -37,13 +57,13 @@ jobs: | |
if: steps.go-bin-cache.outputs.cache-hit != 'true' | ||
run: make dependencies | ||
shell: bash | ||
- name: "Download latest app config" | ||
run: | | ||
make config | ||
- name: "Run go mod tidy" | ||
run: make tidy | ||
- name: "Run go fmt" | ||
run: make fmt | ||
# NOTE: We don't download the config artifact in this job. | ||
# This is because we know Linux is able to generate the configuration file. | ||
# Which is triggered by the `make vet` pre-requisite target `config`. | ||
- name: "Run go vet" | ||
run: make vet | ||
shell: bash | ||
|
@@ -57,60 +77,70 @@ jobs: | |
run: make gosec | ||
shell: bash | ||
test: | ||
needs: config | ||
strategy: | ||
matrix: | ||
tinygo-version: [0.24.0] | ||
tinygo-version: [0.26.0] | ||
go-version: [1.18.x] | ||
node-version: [18] | ||
rust-toolchain: [stable] | ||
platform: [ubuntu-latest, macos-latest, windows-latest] | ||
runs-on: ${{ matrix.platform }} | ||
steps: | ||
- name: "Checkout code" | ||
uses: actions/checkout@v2 | ||
- name: "Install Go" | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
- uses: Integralist/[email protected] | ||
with: | ||
tinygo-version: ${{ matrix.tinygo-version }} | ||
- name: "Restore golang bin cache" | ||
uses: actions/cache@v2 | ||
with: | ||
path: ~/go/bin | ||
key: ${{ runner.os }}-go-bin-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go-bin- | ||
- name: "Restore golang mod cache" | ||
uses: actions/cache@v2 | ||
with: | ||
path: | | ||
~/Library/Caches/go-build | ||
~/go/pkg/mod | ||
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go-mod- | ||
- name: "Install Rust" | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: ${{ matrix.rust-toolchain }} | ||
- name: "Add wasm32-wasi Rust target" | ||
run: rustup target add wasm32-wasi --toolchain ${{ matrix.rust-toolchain }} | ||
- name: "Validate Rust toolchain" | ||
run: rustup show && rustup target list --installed --toolchain stable | ||
shell: bash | ||
- name: "Install Node" | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: "Download latest app config" | ||
run: | | ||
make config | ||
- name: "Test suite" | ||
run: make test | ||
shell: bash | ||
env: | ||
TEST_COMPUTE_INIT: true | ||
TEST_COMPUTE_BUILD: true | ||
TEST_COMPUTE_DEPLOY: true | ||
- name: "Checkout code" | ||
uses: actions/checkout@v3 | ||
- name: "Install Go" | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
- uses: Integralist/[email protected] | ||
with: | ||
tinygo-version: ${{ matrix.tinygo-version }} | ||
- name: "Restore golang bin cache" | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/go/bin | ||
key: ${{ runner.os }}-go-bin-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go-bin- | ||
- name: "Restore golang mod cache" | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/Library/Caches/go-build | ||
~/go/pkg/mod | ||
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go-mod- | ||
- name: "Install Rust" | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: ${{ matrix.rust-toolchain }} | ||
- name: "Add wasm32-wasi Rust target" | ||
run: rustup target add wasm32-wasi --toolchain ${{ matrix.rust-toolchain }} | ||
- name: "Validate Rust toolchain" | ||
run: rustup show && rustup target list --installed --toolchain stable | ||
shell: bash | ||
- name: "Install Node" | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: "Config Artifact" | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: config-artifact-${{ github.sha }} | ||
- name: "Move Config" | ||
run: mv config.toml pkg/config/config.toml | ||
# NOTE: Windows should fail quietly for 'test' pre-requisite target. | ||
# On Windows, executing `make config` works fine. | ||
# But via GitHub Actions the ../../scripts/config.sh isn't run. | ||
# This is because you can't nest PowerShell instances. | ||
# Each GitHub Action 'run' step is a PowerShell instance. | ||
# And each instance is run as: powershell.exe -command ". '...'" | ||
- name: "Test suite" | ||
run: make test | ||
shell: bash | ||
env: | ||
TEST_COMPUTE_INIT: true | ||
TEST_COMPUTE_BUILD: true | ||
TEST_COMPUTE_DEPLOY: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,8 +27,12 @@ ifeq ($(OS), Windows_NT) | |
.SHELLFLAGS = /c | ||
GO_FILES = $(shell where /r pkg *.go) | ||
GO_FILES += $(shell where /r cmd *.go) | ||
CONFIG_SCRIPT = scripts\config.sh | ||
CONFIG_FILE = pkg\config\config.toml | ||
else | ||
GO_FILES = $(shell find cmd pkg -type f -name '*.go') | ||
CONFIG_SCRIPT = ./scripts/config.sh | ||
CONFIG_FILE = pkg/config/config.toml | ||
endif | ||
|
||
# You can pass flags to goreleaser via GORELEASER_ARGS | ||
|
@@ -40,69 +44,83 @@ endif | |
fastly: dependencies $(GO_FILES) | ||
@GOHOSTOS="${GOHOSTOS}" GOHOSTARCH="${GOHOSTARCH}" goreleaser build ${GORELEASER_ARGS} | ||
|
||
# useful for attaching a debugger such as https://github.com/go-delve/delve | ||
debug: config | ||
# Useful for attaching a debugger such as https://github.com/go-delve/delve | ||
debug: | ||
@$(GO_BIN) build -gcflags="all=-N -l" $(GO_ARGS) -o "fastly" ./cmd/fastly | ||
|
||
.PHONY: config | ||
config: | ||
@$(CONFIG_SCRIPT) | ||
@cat $(CONFIG_FILE) | ||
|
||
.PHONY: all | ||
all: dependencies config tidy fmt vet staticcheck gosec test build install | ||
all: config dependencies tidy fmt vet staticcheck gosec test build install | ||
|
||
# update goreleaser inline with the release GHA workflow | ||
# Update CI tools used by ./.github/workflows/pr_test.yml | ||
.PHONY: dependencies | ||
dependencies: | ||
$(GO_BIN) install github.com/securego/gosec/v2/cmd/gosec@latest | ||
$(GO_BIN) install honnef.co/go/tools/cmd/staticcheck@latest | ||
$(GO_BIN) install github.com/mgechev/revive@latest | ||
$(GO_BIN) install github.com/goreleaser/[email protected] | ||
|
||
# Clean up Go modules file. | ||
.PHONY: tidy | ||
tidy: | ||
$(GO_BIN) mod tidy | ||
|
||
# Run formatter. | ||
.PHONY: fmt | ||
fmt: | ||
@echo gofmt -l ./{cmd,pkg} | ||
@eval "bash -c 'F=\$$(gofmt -l ./{cmd,pkg}) ; if [[ \$$F ]] ; then echo \$$F ; exit 1 ; fi'" | ||
|
||
# Run static analysis. | ||
.PHONY: vet | ||
vet: | ||
vet: config | ||
$(GO_BIN) vet ./{cmd,pkg}/... | ||
|
||
# Run linter. | ||
.PHONY: revive | ||
revive: | ||
revive ./... | ||
|
||
# Run security vulnerability checker. | ||
.PHONY: gosec | ||
gosec: | ||
gosec -quiet -exclude=G104 ./{cmd,pkg}/... | ||
|
||
# Run third-party static analysis. | ||
.PHONY: staticcheck | ||
staticcheck: | ||
staticcheck ./{cmd,pkg}/... | ||
|
||
# Run tests | ||
.PHONY: test | ||
test: config | ||
@$(TEST_COMMAND) -race $(TEST_ARGS) | ||
|
||
# GO_ARGS allows for passing additional args to the build e.g. | ||
# make build GO_ARGS='--ldflags "-s -w"' | ||
# Compile program. | ||
# | ||
# GO_ARGS allows for passing additional arguments. | ||
# e.g. make build GO_ARGS='--ldflags "-s -w"' | ||
.PHONY: build | ||
build: config | ||
$(GO_BIN) build $(GO_ARGS) ./cmd/fastly | ||
|
||
# GO_ARGS allows for passing additional args to the build e.g. | ||
# Compile and install program. | ||
# | ||
# GO_ARGS allows for passing additional arguments. | ||
.PHONY: install | ||
install: config | ||
$(GO_BIN) install $(GO_ARGS) ./cmd/fastly | ||
|
||
.PHONY: config | ||
config: | ||
@curl -so pkg/config/config.toml https://developer.fastly.com/api/internal/cli-config | ||
|
||
# Scaffold a new CLI command from template files. | ||
.PHONY: scaffold | ||
scaffold: | ||
@$(shell pwd)/scripts/scaffold.sh $(CLI_PACKAGE) $(CLI_COMMAND) $(CLI_API) | ||
|
||
# Scaffold a new CLI 'category' command from template files. | ||
.PHONY: scaffold-category | ||
scaffold-category: | ||
@$(shell pwd)/scripts/scaffold-category.sh $(CLI_CATEGORY) $(CLI_CATEGORY_COMMAND) $(CLI_PACKAGE) $(CLI_COMMAND) $(CLI_API) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.