From 84ff62bb0f03955970857fb59379f42d467b52ff Mon Sep 17 00:00:00 2001 From: Integralist Date: Fri, 21 Oct 2022 11:39:45 +0100 Subject: [PATCH] fixing all the things --- .github/workflows/pr_test.yml | 132 ++++++++++++++++++------------ .github/workflows/tag_release.yml | 2 - .gitignore | 3 + Makefile | 7 +- scripts/config.sh | 12 +-- 5 files changed, 95 insertions(+), 61 deletions(-) diff --git a/.github/workflows/pr_test.yml b/.github/workflows/pr_test.yml index c6f2dd10c..9e41fce0b 100644 --- a/.github/workflows/pr_test.yml +++ b/.github/workflows/pr_test.yml @@ -7,11 +7,31 @@ concurrency: cancel-in-progress: true jobs: + config: + runs-on: ubuntu-latest + steps: + - name: "Checkout code" + uses: actions/checkout@v2 + - 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 + - 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 with: @@ -37,16 +57,13 @@ jobs: if: steps.go-bin-cache.outputs.cache-hit != 'true' run: make dependencies shell: bash - - name: "Install Rust" - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - - name: "Generate static 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 @@ -60,6 +77,7 @@ jobs: run: make gosec shell: bash test: + needs: config strategy: matrix: tinygo-version: [0.24.0] @@ -69,48 +87,60 @@ jobs: 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/setup-tinygo@v1.0.0 - 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: "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@v2 + - name: "Install Go" + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + - uses: Integralist/setup-tinygo@v1.0.0 + 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: "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 diff --git a/.github/workflows/tag_release.yml b/.github/workflows/tag_release.yml index 55bd7277c..cfdcb2964 100644 --- a/.github/workflows/tag_release.yml +++ b/.github/workflows/tag_release.yml @@ -24,8 +24,6 @@ jobs: toolchain: stable - name: "Generate static app config" run: make config - - name: "Display app config" - run: cat pkg/config/config.toml # Passing the raw SSH private key causes an error: # Load key "/tmp/id_*": invalid format # diff --git a/.gitignore b/.gitignore index f04109ab7..39e2f82fc 100644 --- a/.gitignore +++ b/.gitignore @@ -61,4 +61,7 @@ vendor/ # Ignore generated file for AUR_KEY which is passed to goreleaser as an environment variable. aur_key + +# Ignore static config that is embedded into the CLI +# All Makefile targets use the 'config' as a prerequisite (which generates the config) pkg/config/config.toml diff --git a/Makefile b/Makefile index ca4858e71..592d8fdaf 100644 --- a/Makefile +++ b/Makefile @@ -28,9 +28,11 @@ ifeq ($(OS), Windows_NT) 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_SCRIPT = ./scripts/config.sh + CONFIG_FILE = pkg/config/config.toml endif # You can pass flags to goreleaser via GORELEASER_ARGS @@ -49,6 +51,7 @@ debug: .PHONY: config config: @$(CONFIG_SCRIPT) + @cat $(CONFIG_FILE) .PHONY: all all: config dependencies tidy fmt vet staticcheck gosec test build install @@ -74,7 +77,7 @@ fmt: # Run static analysis. .PHONY: vet -vet: +vet: config $(GO_BIN) vet ./{cmd,pkg}/... # Run linter. diff --git a/scripts/config.sh b/scripts/config.sh index 0e64e204c..8bcb79e4f 100755 --- a/scripts/config.sh +++ b/scripts/config.sh @@ -2,13 +2,13 @@ set -e +cp ".fastly/config.toml" "pkg/config/config.toml" + if ! command -v tomlq &> /dev/null then cargo install tomlq fi -cp ./.fastly/config.toml ./pkg/config/config.toml - kits=( compute-starter-kit-rust-default compute-starter-kit-rust-empty @@ -21,15 +21,15 @@ kits=( ) function parse() { - tomlq -f "./$k.toml" $1 + tomlq -f "$k.toml" $1 } function append() { - echo $1 >> ./pkg/config/config.toml + echo $1 >> pkg/config/config.toml } for k in ${kits[@]}; do - curl -s "https://raw.githubusercontent.com/fastly/$k/main/fastly.toml" -o "./$k.toml" + curl -s "https://raw.githubusercontent.com/fastly/$k/main/fastly.toml" -o "$k.toml" append "[[starter-kits.$(parse language)]]" append "description = \"$(parse description)\"" @@ -37,5 +37,5 @@ for k in ${kits[@]}; do append "path = \"https://github.com/fastly/$k\"" append '' - rm "./$k.toml" + rm "$k.toml" done