From e88ba7edc2e5ace706f92bcfcf7278b9b041c9ed Mon Sep 17 00:00:00 2001 From: UncleGedd <42304551+UncleGedd@users.noreply.github.com> Date: Fri, 10 May 2024 17:39:42 -0500 Subject: [PATCH] chore: swap Makefile for Maru (#602) --- .github/actions/install-uds-cli/action.yaml | 13 ++++ .github/workflows/nightly-ghcr.yaml | 7 +- .github/workflows/nightly-uds-core.yaml | 8 +- .github/workflows/release.yaml | 7 +- .github/workflows/scan-codeql.yaml | 5 +- .github/workflows/test-e2e-pr.yaml | 7 +- .github/workflows/test-schema.yaml | 5 +- .github/workflows/test-unit.yaml | 5 +- CONTRIBUTING.md | 23 ++++-- Makefile | 72 ------------------ README.md | 3 + hack/test-generate-schema.sh | 1 + src/pkg/bundle/deploy_test.go | 3 + src/test/e2e/main_test.go | 3 +- tasks.yaml | 81 +++++++++++++++++++++ tasks/dev.yaml | 19 +++++ tasks/schema.yaml | 14 ++++ tasks/tests.yaml | 38 ++++++++++ zarf.schema.json | 35 +++++++++ 19 files changed, 258 insertions(+), 91 deletions(-) create mode 100644 .github/actions/install-uds-cli/action.yaml delete mode 100644 Makefile create mode 100644 tasks.yaml create mode 100644 tasks/dev.yaml create mode 100644 tasks/schema.yaml create mode 100644 tasks/tests.yaml diff --git a/.github/actions/install-uds-cli/action.yaml b/.github/actions/install-uds-cli/action.yaml new file mode 100644 index 00000000..85468f8f --- /dev/null +++ b/.github/actions/install-uds-cli/action.yaml @@ -0,0 +1,13 @@ +name: Install UDS CLI +description: installs uds-cli from brew +runs: + using: composite + steps: + - name: Set up Homebrew + uses: Homebrew/actions/setup-homebrew@4b34604e75af8f8b23b454f0b5ffb7c5d8ce0056 # master + + - name: Install UDS CLI + shell: bash + run: | + brew tap defenseunicorns/tap + brew install uds diff --git a/.github/workflows/nightly-ghcr.yaml b/.github/workflows/nightly-ghcr.yaml index 0f69ec9a..2fb6ba62 100644 --- a/.github/workflows/nightly-ghcr.yaml +++ b/.github/workflows/nightly-ghcr.yaml @@ -25,8 +25,11 @@ jobs: - name: Setup golang uses: ./.github/actions/golang + - name: Install UDS CLI + uses: ./.github/actions/install-uds-cli + - name: Build UDS-CLI binary - run: make build-cli-linux-amd ARCH=amd64 + run: uds run build-cli-linux-amd - name: Setup K3d uses: ./.github/actions/k3d @@ -40,7 +43,7 @@ jobs: - name: Run e2e tests run: | - make test-e2e-ghcr + build/uds run test:e2e-ghcr env: GITHUB_TOKEN: secrets.GITHUB_TOKEN diff --git a/.github/workflows/nightly-uds-core.yaml b/.github/workflows/nightly-uds-core.yaml index 225fd991..e8f3705b 100644 --- a/.github/workflows/nightly-uds-core.yaml +++ b/.github/workflows/nightly-uds-core.yaml @@ -24,8 +24,14 @@ jobs: with: fetch-depth: 0 + - name: Setup golang + uses: ./.github/actions/golang + + - name: Install UDS CLI + uses: ./.github/actions/install-uds-cli + - name: Build UDS-CLI binary - run: make build-cli-linux-amd ARCH=amd64 + run: uds run build-cli-linux-amd - name: Make UDS-CLI executable run: | diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index ff802e48..ff0601e0 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -23,9 +23,12 @@ jobs: - name: Setup golang uses: ./.github/actions/golang + - name: Install UDS CLI + uses: ./.github/actions/install-uds-cli + - name: Build CLI run: | - make build-cli-linux-amd + uds run build-cli-linux-amd # Upload the contents of the build directory for later stages to use - name: Upload build artifacts @@ -72,7 +75,7 @@ jobs: - name: Run e2e tests run: | - make test-e2e + build/uds run test:e2e env: GITHUB_TOKEN: secrets.GITHUB_TOKEN diff --git a/.github/workflows/scan-codeql.yaml b/.github/workflows/scan-codeql.yaml index 9e2a91fc..882c5528 100644 --- a/.github/workflows/scan-codeql.yaml +++ b/.github/workflows/scan-codeql.yaml @@ -41,8 +41,11 @@ jobs: - name: Setup golang uses: ./.github/actions/golang + - name: Install UDS CLI + uses: ./.github/actions/install-uds-cli + - name: Build UDS CLI - run: make build-cli-linux-amd + run: uds run build-cli-linux-amd - name: Initialize CodeQL uses: github/codeql-action/init@ccf74c947955fd1cf117aef6a0e4e66191ef6f61 # v3.25.4 diff --git a/.github/workflows/test-e2e-pr.yaml b/.github/workflows/test-e2e-pr.yaml index a5cae0b6..fecb2381 100644 --- a/.github/workflows/test-e2e-pr.yaml +++ b/.github/workflows/test-e2e-pr.yaml @@ -30,15 +30,18 @@ jobs: - name: Setup golang uses: ./.github/actions/golang + - name: Install UDS CLI + uses: ./.github/actions/install-uds-cli + - name: Build UDS-CLI binary - run: make build-cli-linux-amd ARCH=amd64 + run: uds run build-cli-linux-amd - name: Setup K3d uses: ./.github/actions/k3d - name: Run e2e tests run: | - make test-e2e-no-ghcr-write + build/uds run test:e2e-no-ghcr-write - name: Save logs if: always() diff --git a/.github/workflows/test-schema.yaml b/.github/workflows/test-schema.yaml index 0fc71d44..910ecab2 100644 --- a/.github/workflows/test-schema.yaml +++ b/.github/workflows/test-schema.yaml @@ -15,8 +15,11 @@ jobs: - name: Setup golang uses: ./.github/actions/golang + - name: Install UDS CLI + uses: ./.github/actions/install-uds-cli + - name: Docs and schemas - run: "make schema test-schema" + run: uds run schema:test-schema - name: Save logs if: always() diff --git a/.github/workflows/test-unit.yaml b/.github/workflows/test-unit.yaml index c5f257da..8fef8905 100644 --- a/.github/workflows/test-unit.yaml +++ b/.github/workflows/test-unit.yaml @@ -30,8 +30,11 @@ jobs: - name: Setup golang uses: ./.github/actions/golang + - name: Install UDS CLI + uses: ./.github/actions/install-uds-cli + - name: Run unit tests - run: make test-unit + run: uds run test:unit - name: Save logs if: always() diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0dc58758..517a04f4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,6 +3,13 @@ Welcome :unicorn: to the UDS CLI! If you'd like to contribute, please reach out Below are some notes on our core software design philosophies that should help guide contributors. +## Table of Contents +1. [Code Quality and Standards](#code-quality-and-standards) +1. [How to Contribute](#how-to-contribute) + - [Building the app](#building-the-app) + - [Pre-Commit Hooks and Linting](#pre-commit-hooks-and-linting) + - [Testing](#testing) + ## Code Quality and Standards Fundamentally, software engineering is a communication problem; we write code for each other, not a computer. When working on this project (or any project!) keep your fellow humans in mind and write clearly and concisely. Below are some general guidelines for code quality and standards that make UDS CLI :sparkles: @@ -12,10 +19,7 @@ Fundamentally, software engineering is a communication problem; we write code fo - **Prefer readability over being clever**: We have a strong preference for code readabilty in UDS CLI. Specifically, this means things like: naming variables appropriately, keeping functions to a reasonable size and avoiding complicated solutions when simple ones exist. -- **User experience is paramount**: UDS CLI doesn't have a pretty UI (yet), but the core user-centered design principles that apply when building a frontend also apply to this CLI tool. First and foremost, features in UDS CLI should enhance workflows and make life easier for end users; if a feature doesn't accomplish this, it will be dropped. - -### Pre-Commit Hooks and Linting -In this repo you can optionally use [pre-commit](https://pre-commit.com/) hooks for automated validation and linting, but if not CI will run these checks for you. +- **User experience is paramount**: UDS CLI doesn't have a pretty UI (yet), but the core user-centered design principles that apply when building a frontend also apply to this CLI tool. First and foremost, features in UDS CLI should enhance workflows and make life easier for end users; if a feature doesn't accomplish this, it will be dropped. ### Continuous Delivery Continuous Delivery is core to our development philosophy. Check out [https://minimumcd.org](https://minimumcd.org/) for a good baseline agreement on what that means. @@ -38,7 +42,12 @@ Please ensure there is a Gitub issue for your proposed change, this helps the UD 1. **Open a PR** against the `main` branch of this repo ### Building the app -Today, we use `make` to build UDS CLI. To build the app, check out the [Makefile](Makefile) and find the appropriate build target for your system, and run it from the root of the repo (ex. `make build-cli-mac-apple`). This will create a binary in the `build` directory that you can use to test your changes (note that this binary is automatically used when running the E2E tests). +We use UDS CLI's `run` feature (ie. vendored [Maru](https://github.com/defenseunicorns/maru-runner)) to build UDS CLI; this means that you'll need to have the `uds` binary [installed](./README.md#install) on your system in order to build the app. + +To build the app, check out the [tasks](tasks.yaml) with `uds run --list-all`, find the appropriate build target for your system, and run it from the root of the repo (ex. `uds run build-cli-mac-apple`). This will create a binary in the `build` directory that you can use to test your changes (note that this binary is automatically used when running [E2E Tests](#running-tests). + +### Pre-Commit Hooks and Linting +In this repo you can optionally use [pre-commit](https://pre-commit.com/) hooks for automated validation and linting, but if not CI will run these checks for you ### Testing @@ -54,7 +63,7 @@ E2E tests reside in the `src/test/e2e` directory. They use bundles located in th We prefer to use Testify's [require](https://github.com/stretchr/testify/tree/master/require) package for assertions in tests. This package provides a rich set of assertion functions that make tests more readable and easier to debug. See other tests in this repo for examples. #### Running Tests -- **Unit Tests**: To run unit tests, run `make test-unit` from the root of the repo. This will run all unit tests in the `src` directory. +- **Unit Tests**: To run unit tests, run `uds run test:unit` from the root of the repo. This will run all unit tests in the `src` directory. -- **E2E Tests**: To run E2E tests, you'll need build UDS CLI locally, and re-build any time you make a change to the source code; this is because the binary in the `build` directory is used to drive the tests. To run the entire suite of E2E tests locally, run `make test-e2e-no-ghcr-write` (note that this intentionally skips the tests that involve writing to GHCR). +- **E2E Tests**: To run E2E tests, you'll need build UDS CLI locally, and re-build any time you make a change to the source code; this is because the binary in the `build` directory is used to drive the tests. To run the entire suite of E2E tests locally, run `uds run test:e2e-no-ghcr-write` (note that this intentionally skips the tests that involve writing to GHCR). diff --git a/Makefile b/Makefile deleted file mode 100644 index b663ca74..00000000 --- a/Makefile +++ /dev/null @@ -1,72 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# SPDX-FileCopyrightText: 2023-Present The UDS Authors - -ARCH ?= amd64 -CLI_VERSION ?= $(if $(shell git describe --tags),$(shell git describe --tags),"UnknownVersion") -K9S_VERSION=$(shell go list -f '{{.Version}}' -m github.com/derailed/k9s) -CRANE_VERSION=$(shell go list -f '{{.Version}}' -m github.com/google/go-containerregistry) -SYFT_VERSION=$(shell go list -f '{{.Version}}' -m github.com/anchore/syft) -ARCHIVER_VERSION=$(shell go list -f '{{.Version}}' -m github.com/mholt/archiver/v3) -HELM_VERSION=$(shell go list -f '{{.Version}}' -m helm.sh/helm/v3) -BUILD_ARGS := -s -w -X 'github.com/defenseunicorns/uds-cli/src/config.CLIVersion=$(CLI_VERSION)' \ - -X 'github.com/defenseunicorns/zarf/src/config.ActionsCommandZarfPrefix=zarf' \ - -X 'github.com/derailed/k9s/cmd.version=$(K9S_VERSION)' \ - -X 'github.com/google/go-containerregistry/cmd/crane/cmd.Version=$(CRANE_VERSION)' \ - -X 'github.com/defenseunicorns/zarf/src/cmd/tools.syftVersion=$(SYFT_VERSION)' \ - -X 'github.com/defenseunicorns/zarf/src/cmd/tools.archiverVersion=$(ARCHIVER_VERSION)' \ - -X 'github.com/defenseunicorns/zarf/src/cmd/tools.helmVersion=$(HELM_VERSION)' - -.PHONY: help -help: ## Display this help information - @grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \ - | sort | awk 'BEGIN {FS = ":.*?## "}; \ - {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' - -build-cli-linux-amd: ## Build the CLI for Linux AMD64 - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="$(BUILD_ARGS)" -o build/uds main.go - -build-cli-linux-arm: ## Build the CLI for Linux ARM64 - CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="$(BUILD_ARGS)" -o build/uds-arm main.go - -build-cli-mac-intel: ## Build the CLI for Mac Intel - GOOS=darwin GOARCH=amd64 go build -ldflags="$(BUILD_ARGS)" -o build/uds-mac-intel main.go - -build-cli-mac-apple: ## Build the CLI for Mac Apple - GOOS=darwin GOARCH=arm64 go build -ldflags="$(BUILD_ARGS)" -o build/uds-mac-apple main.go - -test-unit: ## Run Unit Tests - cd src/pkg && go test ./... -failfast -v -timeout 5m - -test-e2e: ## Run End to End (e2e) tests - cd src/test/e2e && go test -failfast -v -timeout 30m - -test-e2e-ghcr: ## Run End to End (e2e) tests with GHCR (contains writes) - cd src/test/e2e && go test -failfast -v -timeout 30m -run ".*GHCR.*" - -test-e2e-no-ghcr-write: ## Run End to End (e2e) tests without GHCR - cd src/test/e2e && go test -failfast -v -timeout 30m -skip ".*GHCR.*" - -test-e2e-runner: ## Run End to End (e2e) tests for task runner only - cd src/test/e2e && go test -failfast -v -timeout 30m -run TestTaskRunner - -schema: ## Update JSON schema for uds-bundle.yaml - ./hack/generate-schema.sh - -test-schema: ## Test if the schema has been modified - $(MAKE) schema - ./hack/test-generate-schema.sh - -local-registry: ## Run a local docker registry - docker run -p 5000:5000 --restart=always --name registry registry:2 - -clean: ## Clean up build artifacts - rm -rf build - -clean-test-artifacts: ## removes bundles and zarf packages that have been created from previous test runs - find src/test -type f -name '*.tar.zst' -delete - -push-test-artifacts: ## Push artifacts that UDS CLI tests rely on to GHCR - cd hack && ./push-test-artifacts.sh - -lint: ## Run golangci-lint on the project - golangci-lint run ./src/... diff --git a/README.md b/README.md index ccf36dd4..9d362e7c 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ ## Table of Contents 1. [Install](#install) +1. [Contributing](CONTRIBUTING.md) 1. [Quickstart](#quickstart) - [Create](#bundle-create) - [Deploy](#bundle-deploy) @@ -34,6 +35,8 @@ brew tap defenseunicorns/tap && brew install uds ``` UDS CLI Binaries are also included with each [Github Release](https://github.com/defenseunicorns/uds-cli/releases) +## Contributing +Build instructions and contributing docs are located in [CONTRIBUTING.md](CONTRIBUTING.md). ## Quickstart The UDS-CLI's flagship feature is deploying multiple, independent Zarf packages. To create a `UDSBundle` of Zarf packages, create a `uds-bundle.yaml` file like so: diff --git a/hack/test-generate-schema.sh b/hack/test-generate-schema.sh index 835e420c..5cd42e4d 100755 --- a/hack/test-generate-schema.sh +++ b/hack/test-generate-schema.sh @@ -11,6 +11,7 @@ check_git_status() { } check_git_status uds.schema.json +check_git_status zarf.schema.json check_git_status tasks.schema.json exit 0 diff --git a/src/pkg/bundle/deploy_test.go b/src/pkg/bundle/deploy_test.go index 3cf07c4a..6658f710 100644 --- a/src/pkg/bundle/deploy_test.go +++ b/src/pkg/bundle/deploy_test.go @@ -227,6 +227,9 @@ func TestLoadVariablesPrecedence(t *testing.T) { // Run test cases for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { + // unset arch var that gets applied automatically when doing 'uds run' so it doesn't get in the way + os.Unsetenv("UDS_ARCH") + // Set for select test cases to test precedence of env vars os.Unsetenv("UDS_FOO") if tc.loadEnvVar { diff --git a/src/test/e2e/main_test.go b/src/test/e2e/main_test.go index b20e908e..a15b5758 100644 --- a/src/test/e2e/main_test.go +++ b/src/test/e2e/main_test.go @@ -68,8 +68,7 @@ func doAllTheThings(m *testing.M) (int, error) { e2e.ApplianceModeKeep = os.Getenv(applianceModeKeepEnvVar) == "true" e2e.RunClusterTests = os.Getenv(skipK8sEnvVar) != "true" - // Validate that the UDS binary exists. If it doesn't that means the dev hasn't built it, usually by running - // `make build-cli` + // Validate that the UDS binary exists. If it doesn't that means the dev hasn't built it _, err = os.Stat(e2e.UDSBinPath) if err != nil { return 1, fmt.Errorf("zarf binary %s not found", e2e.UDSBinPath) diff --git a/tasks.yaml b/tasks.yaml new file mode 100644 index 00000000..047cdd72 --- /dev/null +++ b/tasks.yaml @@ -0,0 +1,81 @@ +# SPDX-License-Identifier: Apache-2.0 +# SPDX-FileCopyrightText: 2023-Present The UDS Authors + +includes: + - test: tasks/tests.yaml + - schema: tasks/schema.yaml + - dev: tasks/dev.yaml + +tasks: + # build tasks + - name: get-versions + description: gets versions of UDS CLI + vendored tools + actions: + - cmd: go list -f '{{.Version}}' -m github.com/derailed/k9s + mute: true + setVariables: + - name: K9S_VERSION + - cmd: go list -f '{{.Version}}' -m github.com/anchore/syft + mute: true + setVariables: + - name: SYFT_VERSION + - cmd: go list -f '{{.Version}}' -m github.com/google/go-containerregistry + mute: true + setVariables: + - name: CRANE_VERSION + - cmd: go list -f '{{.Version}}' -m github.com/mholt/archiver/v3 + mute: true + setVariables: + - name: ARCHIVER_VERSION + - cmd: go list -f '{{.Version}}' -m helm.sh/helm/v3 + mute: true + setVariables: + - name: HELM_VERSION + - cmd: git describe --tags 2>/dev/null || echo "UnknownVersion" + mute: true + setVariables: + - name: CLI_VERSION + + - name: build-args + description: generates the build args for building UDS CLI + actions: + - cmd: | + cat <