diff --git a/.envrc b/.envrc index ffa84322545b..2a743f959cac 100644 --- a/.envrc +++ b/.envrc @@ -1,3 +1,5 @@ +# Requires nix to be installed and available in the PATH. +# To install nix: `./scripts/run_task.sh install-nix` use flake # Repo-local commands like ginkgo and tmpnetctl diff --git a/.github/workflows/build-linux-binaries.yml b/.github/workflows/build-linux-binaries.yml index 8572f135a7e0..7a3d45bfc946 100644 --- a/.github/workflows/build-linux-binaries.yml +++ b/.github/workflows/build-linux-binaries.yml @@ -25,7 +25,7 @@ jobs: - run: go version - name: Build the avalanchego binaries - run: ./scripts/build.sh + run: ./scripts/run_task.sh build - name: Install aws cli run: sudo snap install aws-cli --classic @@ -85,7 +85,7 @@ jobs: - run: go version - name: Build the avalanchego binaries - run: ./scripts/build.sh + run: ./scripts/run_task.sh build - name: Install aws cli run: sudo snap install aws-cli --classic diff --git a/.github/workflows/build-macos-release.yml b/.github/workflows/build-macos-release.yml index b37d1dc01545..83b02cab98ae 100644 --- a/.github/workflows/build-macos-release.yml +++ b/.github/workflows/build-macos-release.yml @@ -32,7 +32,7 @@ jobs: # Runs a single command using the runners shell - name: Build the avalanchego binary - run: ./scripts/build.sh + run: ./scripts/run_task.sh build - name: Try to get tag from git if: "${{ github.event.inputs.tag == '' }}" diff --git a/.github/workflows/build-ubuntu-amd64-release.yml b/.github/workflows/build-ubuntu-amd64-release.yml index 496dab96438f..338b66e24afe 100644 --- a/.github/workflows/build-ubuntu-amd64-release.yml +++ b/.github/workflows/build-ubuntu-amd64-release.yml @@ -23,7 +23,7 @@ jobs: - run: go version - name: Build the avalanchego binaries - run: ./scripts/build.sh + run: ./scripts/run_task.sh build - name: Install aws cli run: sudo snap install aws-cli --classic @@ -81,7 +81,7 @@ jobs: - run: go version - name: Build the avalanchego binaries - run: ./scripts/build.sh + run: ./scripts/run_task.sh build - name: Install aws cli run: sudo snap install aws-cli --classic diff --git a/.github/workflows/build-ubuntu-arm64-release.yml b/.github/workflows/build-ubuntu-arm64-release.yml index de9382be6f13..5f37355b3b62 100644 --- a/.github/workflows/build-ubuntu-arm64-release.yml +++ b/.github/workflows/build-ubuntu-arm64-release.yml @@ -23,7 +23,7 @@ jobs: - run: go version - name: Build the avalanchego binaries - run: ./scripts/build.sh + run: ./scripts/run_task.sh build - name: Install aws cli run: sudo snap install aws-cli --classic @@ -81,7 +81,7 @@ jobs: - run: go version - name: Build the avalanchego binaries - run: ./scripts/build.sh + run: ./scripts/run_task.sh build - name: Install aws cli run: sudo snap install aws-cli --classic diff --git a/.github/workflows/build-win-release.yml b/.github/workflows/build-win-release.yml index d882fe4aadd9..facf1fa5487f 100644 --- a/.github/workflows/build-win-release.yml +++ b/.github/workflows/build-win-release.yml @@ -60,7 +60,7 @@ jobs: # Runs a single command using the runners shell - name: Build the avalanchego binary - run: ./scripts/build.sh + run: ./scripts/run_task.sh build shell: bash - name: Create zip diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 42c57e4dbabc..edb582bddc49 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,9 +33,9 @@ jobs: shell: bash if: matrix.os == 'windows-2022' run: echo "TIMEOUT=240s" >> "$GITHUB_ENV" - - name: build_test + - name: test-unit shell: bash - run: ./scripts/build_test.sh + run: ./scripts/run_task.sh test-unit env: TIMEOUT: ${{ env.TIMEOUT }} Fuzz: @@ -43,22 +43,18 @@ jobs: steps: - uses: actions/checkout@v4 - uses: ./.github/actions/setup-go-for-project - - name: fuzz_test + - name: test-fuzz shell: bash - run: ./scripts/build_fuzz.sh 10 # Run each fuzz test 10 seconds + run: ./scripts/run_task.sh test-fuzz e2e: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: ./.github/actions/setup-go-for-project - - name: Build AvalancheGo Binary - shell: bash - run: ./scripts/build.sh -r - name: Run e2e tests uses: ./.github/actions/run-monitored-tmpnet-cmd with: - run: ./scripts/tests.e2e.sh - run_env: E2E_SERIAL=1 + run: ./scripts/run_task.sh test-e2e-ci artifact_prefix: e2e filter_by_owner: avalanchego-e2e prometheus_username: ${{ secrets.PROMETHEUS_ID || '' }} @@ -70,14 +66,10 @@ jobs: steps: - uses: actions/checkout@v4 - uses: ./.github/actions/setup-go-for-project - - name: Build AvalancheGo Binary - shell: bash - run: ./scripts/build.sh -r - name: Run e2e tests uses: ./.github/actions/run-monitored-tmpnet-cmd with: - run: ./scripts/tests.e2e.sh --activate-fortuna - run_env: E2E_SERIAL=1 + run: ./scripts/run_task.sh test-e2e-ci -- --activate-fortuna artifact_prefix: e2e-post-fortuna filter_by_owner: avalanchego-e2e prometheus_username: ${{ secrets.PROMETHEUS_ID || '' }} @@ -89,14 +81,10 @@ jobs: steps: - uses: actions/checkout@v4 - uses: ./.github/actions/setup-go-for-project - - name: Build AvalancheGo Binary - shell: bash - run: ./scripts/build.sh -r - name: Run e2e tests with existing network uses: ./.github/actions/run-monitored-tmpnet-cmd with: - run: ./scripts/tests.e2e.existing.sh - run_env: E2E_SERIAL=1 + run: ./scripts/run_task.sh test-e2e-existing-ci artifact_prefix: e2e-existing-network prometheus_username: ${{ secrets.PROMETHEUS_ID || '' }} prometheus_password: ${{ secrets.PROMETHEUS_PASSWORD || '' }} @@ -107,14 +95,11 @@ jobs: steps: - uses: actions/checkout@v4 - uses: ./.github/actions/setup-go-for-project - - name: Build AvalancheGo Binary - shell: bash - run: ./scripts/build.sh # TODO: Reactivate test once v1.13.0 is published # - name: Run e2e tests # uses: ./.github/actions/run-monitored-tmpnet-cmd # with: - # run: ./scripts/tests.upgrade.sh + # run: ./scripts/run_task.sh test-upgrade # artifact_prefix: upgrade # prometheus_username: ${{ secrets.PROMETHEUS_ID || '' }} # prometheus_password: ${{ secrets.PROMETHEUS_PASSWORD || '' }} @@ -125,16 +110,10 @@ jobs: steps: - uses: actions/checkout@v4 - uses: ./.github/actions/setup-go-for-project - - name: Run static analysis tests - shell: bash - run: scripts/lint.sh - - name: Run actionlint - shell: bash - run: scripts/actionlint.sh - uses: ./.github/actions/install-nix - - name: Run shellcheck - shell: bash - run: nix develop --command bash -x scripts/shellcheck.sh + - name: Runs all lint checks + shell: nix develop --command bash -x {0} + run: ./scripts/run_task.sh lint-all-ci buf-lint: name: Protobuf Lint runs-on: ubuntu-latest @@ -161,9 +140,7 @@ jobs: # Use the dev shell instead of bufbuild/buf-action to ensure the dev shell provides the expected versions - uses: ./.github/actions/install-nix - shell: nix develop --command bash -x {0} - run: scripts/protobuf_codegen.sh - - shell: bash - run: .github/workflows/check-clean-branch.sh + run: ./scripts/run_task.sh check-generate-protobuf check_mockgen: name: Up-to-date mocks runs-on: ubuntu-latest @@ -171,10 +148,7 @@ jobs: - uses: actions/checkout@v4 - uses: ./.github/actions/setup-go-for-project - shell: bash - run: | - grep -lr -E '^// Code generated by MockGen\. DO NOT EDIT\.$' . | xargs -r rm - go generate -run "go.uber.org/mock/mockgen" ./... - .github/workflows/check-clean-branch.sh + run: ./scripts/run_task.sh check-generate-mocks check_canotogen: name: Up-to-date canoto runs-on: ubuntu-latest @@ -182,9 +156,7 @@ jobs: - uses: actions/checkout@v4 - uses: ./.github/actions/setup-go-for-project - shell: bash - run: go generate -run "github.com/StephenButtolph/canoto/canoto" ./... - - shell: bash - run: .github/workflows/check-clean-branch.sh + run: ./scripts/run_task.sh check-generate-canoto go_mod_tidy: name: Up-to-date go.mod and go.sum runs-on: ubuntu-latest @@ -192,9 +164,7 @@ jobs: - uses: actions/checkout@v4 - uses: ./.github/actions/setup-go-for-project - shell: bash - run: go mod tidy - - shell: bash - run: .github/workflows/check-clean-branch.sh + run: ./scripts/run_task.sh check-go-mod-tidy test_build_image: name: Image build runs-on: ubuntu-latest @@ -206,44 +176,25 @@ jobs: sudo apt -y install qemu-system qemu-user-static - name: Check image build shell: bash - run: bash -x scripts/tests.build_image.sh + run: ./scripts/run_task.sh test-build-image test_build_antithesis_avalanchego_images: name: Build Antithesis avalanchego images runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: ./.github/actions/setup-go-for-project - - name: Build AvalancheGo Binary - shell: bash - run: ./scripts/build.sh -r - - name: Check that the avalanchego workload is sane - shell: bash - run: go run ./tests/antithesis/avalanchego --avalanchego-path=./build/avalanchego --duration=120s - name: Check image build for avalanchego test setup shell: bash - run: bash -x scripts/tests.build_antithesis_images.sh - env: - TEST_SETUP: avalanchego + run: ./scripts/run_task.sh test-build-antithesis-images-avalanchego test_build_antithesis_xsvm_images: name: Build Antithesis xsvm images runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: ./.github/actions/setup-go-for-project - - name: Build AvalancheGo Binary - shell: bash - run: ./scripts/build.sh -r - - name: Build xsvm binary - shell: bash - run: ./scripts/build_xsvm.sh - - name: Check that the xsvm workload is sane - shell: bash - run: go run ./tests/antithesis/xsvm --avalanchego-path=./build/avalanchego --duration=120s - name: Check image build for xsvm test setup shell: bash - run: bash -x scripts/tests.build_antithesis_images.sh - env: - TEST_SETUP: xsvm + run: ./scripts/run_task.sh test-build-antithesis-images-xsvm e2e_bootstrap_monitor: name: Run bootstrap monitor e2e tests runs-on: ubuntu-latest @@ -251,7 +202,6 @@ jobs: - uses: actions/checkout@v4 - uses: ./.github/actions/setup-go-for-project - uses: ./.github/actions/install-nix - - run: nix develop --command echo "dependencies installed" - name: Run e2e tests shell: bash - run: nix develop --command bash -x ./scripts/tests.e2e.bootstrap_monitor.sh + run: nix develop --command ./scripts/run_task.sh test-bootstrap-monitor-e2e diff --git a/.github/workflows/fuzz.yml b/.github/workflows/fuzz.yml index ef6deedfe840..24a73b42abb1 100644 --- a/.github/workflows/fuzz.yml +++ b/.github/workflows/fuzz.yml @@ -16,5 +16,4 @@ jobs: - name: Set up Go uses: ./.github/actions/setup-go-for-project - name: Run fuzz tests - shell: bash - run: ./scripts/build_fuzz.sh 180 # Run each fuzz test 180 seconds + run: ./scripts/run_task.sh test-fuzz-long diff --git a/.github/workflows/fuzz_merkledb.yml b/.github/workflows/fuzz_merkledb.yml index 8019b449068c..471932ceda26 100644 --- a/.github/workflows/fuzz_merkledb.yml +++ b/.github/workflows/fuzz_merkledb.yml @@ -18,5 +18,4 @@ jobs: - name: Set up Go uses: ./.github/actions/setup-go-for-project - name: Run merkledb fuzz tests - shell: bash - run: ./scripts/build_fuzz.sh 900 ./x/merkledb # Run each merkledb fuzz tests 15 minutes + run: ./scripts/run_task.sh test-fuzz-merkledb diff --git a/.github/workflows/publish_antithesis_images.yml b/.github/workflows/publish_antithesis_images.yml index 64810dac316b..9506126b698a 100644 --- a/.github/workflows/publish_antithesis_images.yml +++ b/.github/workflows/publish_antithesis_images.yml @@ -32,15 +32,13 @@ jobs: password: ${{ secrets.ANTITHESIS_GAR_JSON_KEY }} - name: Build and push images for avalanchego test setup - run: bash -x ./scripts/build_antithesis_images.sh + run: ./scripts/run_task.sh build-antithesis-images-avalanchego env: IMAGE_PREFIX: ${{ env.REGISTRY }}/${{ env.REPOSITORY }} IMAGE_TAG: ${{ github.event.inputs.image_tag || 'latest' }} - TEST_SETUP: avalanchego - name: Build and push images for xsvm test setup - run: bash -x ./scripts/build_antithesis_images.sh + run: ./scripts/run_task.sh build-antithesis-images-xsvm env: IMAGE_PREFIX: ${{ env.REGISTRY }}/${{ env.REPOSITORY }} IMAGE_TAG: ${{ github.event.inputs.image_tag || 'latest' }} - TEST_SETUP: xsvm diff --git a/.github/workflows/publish_docker_image.yml b/.github/workflows/publish_docker_image.yml index 8a38a9dbb647..eadbb9a981a6 100644 --- a/.github/workflows/publish_docker_image.yml +++ b/.github/workflows/publish_docker_image.yml @@ -27,11 +27,11 @@ jobs: DOCKER_PASS: ${{ secrets.docker_pass }} DOCKER_IMAGE: ${{ secrets.docker_repo }} BUILD_MULTI_ARCH: 1 - run: scripts/build_image.sh + run: scripts/run_task.sh build-image - name: Build and publish bootstrap-monitor image to DockerHub env: DOCKER_USERNAME: ${{ secrets.docker_username }} DOCKER_PASS: ${{ secrets.docker_pass }} DOCKER_IMAGE: avaplatform/bootstrap-monitor BUILD_MULTI_ARCH: 1 - run: scripts/build_bootstrap_monitor_image.sh + run: scripts/run_task.sh build-bootstrap-monitor-image diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 88d864c4b05a..74dca8976f20 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,6 +10,14 @@ To start developing on AvalancheGo, you'll need a few things installed. On MacOS, a modern version of bash is required (e.g. via [homebrew](https://brew.sh/) with `brew install bash`). The version installed by default is not compatible with AvalancheGo's [shell scripts](scripts). +## Running tasks + +This repo uses the [Task](https://taskfile.dev/) task runner to simplify usage and discoverability of development tasks. To list available tasks: + +```bash +./scripts/run_task.sh +``` + ## Issues ### Security @@ -44,7 +52,7 @@ On MacOS, a modern version of bash is required (e.g. via [homebrew](https://brew - Any changes to protobuf message types require that protobuf files are regenerated. ```sh -./scripts/protobuf_codegen.sh +./scripts/run_task.sh generate-protobuf ``` #### Autogenerated mocks @@ -56,7 +64,7 @@ Mocks are auto-generated using [mockgen](https://pkg.go.dev/go.uber.org/mock/moc - To **re-generate all mocks**, use the command below from the root of the project: ```sh - go generate -run "go.uber.org/mock/mockgen" ./... + ./scripts/run_task.sh generate-mocks ``` - To **add** an interface that needs a corresponding mock generated: @@ -90,19 +98,19 @@ Mocks are auto-generated using [mockgen](https://pkg.go.dev/go.uber.org/mock/moc - Build the avalanchego binary ```sh -./scripts/build.sh +./scripts/run_task.sh build ``` - Run unit tests ```sh -./scripts/build_test.sh +./scripts/run_task.sh test-unit ``` - Run the linter ```sh -./scripts/lint.sh +./scipts/run_task.sh lint ``` ### Continuous Integration (CI) diff --git a/README.md b/README.md index 9102d95acc1e..5db55c819241 100644 --- a/README.md +++ b/README.md @@ -42,10 +42,10 @@ This will clone and checkout the `master` branch. #### Building AvalancheGo -Build AvalancheGo by running the build script: +Build AvalancheGo by running the build task: ```sh -./scripts/build.sh +./scripts/run_task.sh build ``` The `avalanchego` binary is now in the `build` directory. To run: @@ -93,7 +93,7 @@ Make sure Docker is installed on the machine - so commands like `docker run` etc Building the Docker image of latest `avalanchego` branch can be done by running: ```sh -./scripts/build_image.sh +./scripts/run-task.sh build-image ``` To check the built image, run: @@ -155,7 +155,7 @@ AvalancheGo uses multiple tools to generate efficient and boilerplate code. ### Running protobuf codegen -To regenerate the protobuf go code, run `scripts/protobuf_codegen.sh` from the root of the repo. +To regenerate the protobuf go code, run `scripts/run-task.sh generate-protobuf` from the root of the repo. This should only be necessary when upgrading protobuf versions or modifying .proto definition files. @@ -180,7 +180,7 @@ If you extract buf to ~/software/buf/bin, the following should work: export PATH=$PATH:~/software/buf/bin/:~/go/bin go get google.golang.org/protobuf/cmd/protoc-gen-go go get google.golang.org/protobuf/cmd/protoc-gen-go-grpc -scripts/protobuf_codegen.sh +scripts/run_task.sh generate-protobuf ``` For more information, refer to the [GRPC Golang Quick Start Guide](https://grpc.io/docs/languages/go/quickstart/). diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 000000000000..fa6d64c18064 --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,206 @@ +# https://taskfile.dev +# To run on a system without task installed, `./scripts/run_task.sh` will execute it with `go run`. +# If in the nix dev shell, `task` is available. + +version: '3' + +tasks: + default: ./scripts/run_task.sh --list + + build: + desc: Builds avalanchego + cmd: ./scripts/build.sh + + build-antithesis-images-avalanchego: + desc: Builds docker images for antithesis for the avalanchego test setup + env: + TEST_SETUP: avalanchego + cmd: bash -x ./scripts/build_antithesis_images.sh + + build-antithesis-images-xsvm: + desc: Builds docker images for antithesis for the xsvm test setup + env: + TEST_SETUP: xsvm + cmd: bash -x ./scripts/build_antithesis_images.sh + + build-bootstrap-monitor: + desc: Builds bootstrap-monitor + cmd: ./scripts/build_bootstrap_monitor.sh + + build-bootstrap-monitor-image: + desc: Builds docker image for bootstrap-monitor + cmd: ./scripts/build_bootstrap_monitor_image.sh + + build-image: + desc: Builds docker image for avalanchego + cmd: ./scripts/build_image.sh + + build-race: + desc: Builds avalanchego with race detection enabled + cmd: ./scripts/build.sh -r + + build-tmpnetctl: + desc: Builds tmpnetctl + cmd: ./scripts/build_tmpnetctl.sh + + build-xsvm: + desc: Builds xsvm plugin + cmd: ./scripts/build_xsvm.sh + + check-clean-branch: + desc: Checks that the git working tree is clean + cmd: .github/workflows/check-clean-branch.sh + + check-generate-canoto: + desc: Checks that generated canoto is up-to-date (requires a clean git working tree) + cmds: + - task: generate-canoto + - task: check-clean-branch + + check-generate-mocks: + desc: Checks that generated mocks are up-to-date (requires a clean git working tree) + cmds: + - task: generate-mocks + - task: check-clean-branch + + check-generate-protobuf: + desc: Checks that generated protobuf is up-to-date (requires a clean git working tree) + cmds: + - task: generate-protobuf + - task: check-clean-branch + + check-go-mod-tidy: + desc: Checks that go.mod and go.sum are up-to-date (requires a clean git working tree) + cmds: + - cmd: go mod tidy + - task: check-clean-branch + + generate-mocks: + desc: Generates testing mocks + cmds: + - cmd: grep -lr -E '^// Code generated by MockGen\. DO NOT EDIT\.$' . | xargs -r rm + - cmd: go generate -run "go.uber.org/mock/mockgen" ./... + + generate-canoto: + desc: Generates canoto + cmd: go generate -run "github.com/StephenButtolph/canoto/canoto" ./... + + generate-protobuf: + desc: Generates protobuf + cmd: ./scripts/protobuf_codegen.sh + + install-nix: + desc: Installs nix with the determinate systems installer + cmd: curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install + + lint: + desc: Runs static analysis tests of golang code + cmd: ./scripts/lint.sh + + lint-action: + desc: Runs actionlint to check sanity of github action configuration + cmd: ./scripts/actionlint.sh + + lint-all: + desc: Runs all lint checks in parallel + deps: + - lint + - lint-action + - lint-shell + + lint-all-ci: + desc: Runs all lint checks one-by-one + cmds: + - task: lint + - task: lint-action + - task: lint-shell + + lint-shell: + desc: Runs shellcheck to check sanity of shell scripts + cmd: ./scripts/shellcheck.sh + + test-bootstrap-monitor-e2e: + desc: Runs bootstrap monitor e2e tests + cmd: bash -x ./scripts/tests.e2e.bootstrap_monitor.sh + + test-build-antithesis-images-avalanchego: + desc: Tests the build of antithesis images for the avalanchego test setup + env: + TEST_SETUP: avalanchego + cmds: + - task: build-race + - cmd: go run ./tests/antithesis/avalanchego --avalanchego-path=./build/avalanchego --duration=120s + - cmd: bash -x ./scripts/tests.build_antithesis_images.sh + + test-build-antithesis-images-xsvm: + desc: Tests the build of antithesis images for the xsvm test setup + env: + TEST_SETUP: xsvm + cmds: + - task: build-race + - task: build-xsvm + - cmd: go run ./tests/antithesis/xsvm --avalanchego-path=./build/avalanchego --duration=120s + - cmd: bash -x ./scripts/tests.build_antithesis_images.sh + + test-build-image: + # On mac, docker/podman/lima should work out-of-the-box. + # On linux, requires qemu (e.g. apt -y install qemu-system qemu-user-static). + desc: Runs test of cross-platform docker image build + cmd: bash -x scripts/tests.build_image.sh + + test-e2e: + desc: Runs e2e tests + cmds: + - task: build + - task: build-xsvm + - cmd: bash -x ./scripts/tests.e2e.sh {{.CLI_ARGS}} + + test-e2e-ci: + desc: Runs e2e tests [serially with race detection enabled] + env: + E2E_SERIAL: 1 + cmds: + - task: build-race + - task: build-xsvm + - cmd: bash -x ./scripts/tests.e2e.sh {{.CLI_ARGS}} + + test-e2e-existing-ci: + desc: Runs e2e tests with an existing network [serially with race detection enabled] + env: + E2E_SERIAL: 1 + cmds: + - task: build-race + - task: build-xsvm + - cmd: bash -x ./scripts/tests.e2e.existing.sh {{.CLI_ARGS}} + + # To use a different fuzz time, run `task test-fuzz FUZZTIME=[value in seconds]`. + # A value of `-1` will run until it encounters a failing output. + + test-fuzz: + desc: Runs each fuzz test for 10 seconds + vars: + FUZZTIME: '{{.FUZZTIME| default "10"}}' + cmd: ./scripts/build_fuzz.sh {{.FUZZTIME}} + + test-fuzz-long: + desc: Runs each fuzz test for 180 seconds + vars: + FUZZTIME: '{{.FUZZTIME| default "180"}}' + cmd: ./scripts/build_fuzz.sh {{.FUZZTIME}} + + test-fuzz-merkledb: + desc: Runs each merkledb fuzz test for 15 minutes + vars: + FUZZTIME: '{{.FUZZTIME| default "900"}}' + cmd: ./scripts/build_fuzz.sh {{.FUZZTIME}} ./x/merkledb + + test-unit: + desc: Runs unit tests + # Invoking with bash ensures compatibility with CI execution on Windows + cmd: bash ./scripts/build_test.sh + + test-upgrade: + desc: Runs upgrade tests + cmds: + - task: build + - cmd: bash -x ./scripts/tests.upgrade.sh {{.CLI_ARGS}} diff --git a/flake.nix b/flake.nix index 9eaf6c78db49..881b9f5e8454 100644 --- a/flake.nix +++ b/flake.nix @@ -1,6 +1,6 @@ { # To use: - # - install nix: https://github.com/DeterminateSystems/nix-installer?tab=readme-ov-file#install-nix + # - install nix: `./scripts/run_task.sh install-nix` # - run `nix develop` or use direnv (https://direnv.net/) # - for quieter direnv output, set `export DIRENV_LOG_FORMAT=` @@ -33,6 +33,9 @@ default = pkgs.mkShell { # The Nix packages provided in the environment packages = with pkgs; [ + # Task runner + go-task + # Monitoring tools promtail # Loki log shipper prometheus # Metrics collector diff --git a/scripts/actionlint.sh b/scripts/actionlint.sh index bdc3083e6b65..c4aea1257901 100755 --- a/scripts/actionlint.sh +++ b/scripts/actionlint.sh @@ -2,6 +2,23 @@ set -euo pipefail -go install github.com/rhysd/actionlint/cmd/actionlint@v1.7.1 +go run github.com/rhysd/actionlint/cmd/actionlint@v1.7.1 "${@}" -actionlint +echo "Checking use of scripts/* in GitHub Actions workflows..." +SCRIPT_USAGE= +for file in .github/workflows/*.{yml,yaml}; do + # Skip if no matches found (in case one of the extensions doesn't exist) + [[ -f "$file" ]] || continue + + # Search for scripts/* except for scripts/run_task.sh + MATCHES=$(grep -H -n -P "scripts/(?!run_task\.sh)" "$file" || true) + if [[ -n "${MATCHES}" ]]; then + echo "${MATCHES}" + SCRIPT_USAGE=1 + fi +done + +if [[ -n "${SCRIPT_USAGE}" ]]; then + echo "Error: the lines listed above must be converted to use scripts/run_task.sh to ensure local reproducibility." + exit 1 +fi diff --git a/scripts/lint.sh b/scripts/lint.sh index 376cee7f936c..fd1201b5d18e 100755 --- a/scripts/lint.sh +++ b/scripts/lint.sh @@ -32,8 +32,7 @@ fi TESTS=${TESTS:-"golangci_lint license_header require_error_is_no_funcs_as_params single_import interface_compliance_nil require_no_error_inline_func import_testing_only_in_tests"} function test_golangci_lint { - go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@v1.64.5 - golangci-lint run --config .golangci.yml + go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.64.5 run --config .golangci.yml } # automatically checks license headers @@ -41,12 +40,11 @@ function test_golangci_lint { # TESTS='license_header' ADDLICENSE_FLAGS="--debug" ./scripts/lint.sh _addlicense_flags=${ADDLICENSE_FLAGS:-"--verify --debug"} function test_license_header { - go install -v github.com/palantir/go-license@v1.25.0 local files=() while IFS= read -r line; do files+=("$line"); done < <(find . -type f -name '*.go' ! -name '*.pb.go' ! -name 'mock_*.go' ! -name 'mocks_*.go' ! -path './**/*mock/*.go' ! -name '*.canoto.go') # shellcheck disable=SC2086 - go-license \ + go run github.com/palantir/go-license@v1.25.0 \ --config=./header.yml \ ${_addlicense_flags} \ "${files[@]}" diff --git a/scripts/run_task.sh b/scripts/run_task.sh new file mode 100755 index 000000000000..beec43e21cc4 --- /dev/null +++ b/scripts/run_task.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# Assume the system-installed task is compatible with the taskfile version +if command -v task > /dev/null 2>&1; then + exec task "${@}" +else + go run github.com/go-task/task/v3/cmd/task@v3.39.2 "${@}" +fi diff --git a/scripts/tests.e2e.sh b/scripts/tests.e2e.sh index 042b9a32d2e7..4bdceb72c475 100755 --- a/scripts/tests.e2e.sh +++ b/scripts/tests.e2e.sh @@ -20,10 +20,6 @@ fi # the instructions to build non-portable BLST. source ./scripts/constants.sh -# Enable subnet testing by building xsvm -./scripts/build_xsvm.sh -echo "" - # Ensure an absolute path to avoid dependency on the working directory # of script execution. AVALANCHEGO_PATH="$(realpath "${AVALANCHEGO_PATH:-./build/avalanchego}")"