Skip to content

Commit

Permalink
fixing all the things
Browse files Browse the repository at this point in the history
  • Loading branch information
Integralist committed Oct 21, 2022
1 parent aafe7e4 commit 84ff62b
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 61 deletions.
132 changes: 81 additions & 51 deletions .github/workflows/pr_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -60,6 +77,7 @@ jobs:
run: make gosec
shell: bash
test:
needs: config
strategy:
matrix:
tinygo-version: [0.24.0]
Expand All @@ -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
2 changes: 0 additions & 2 deletions .github/workflows/tag_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -74,7 +77,7 @@ fmt:

# Run static analysis.
.PHONY: vet
vet:
vet: config
$(GO_BIN) vet ./{cmd,pkg}/...

# Run linter.
Expand Down
12 changes: 6 additions & 6 deletions scripts/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,21 +21,21 @@ 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)\""
append "name = \"$(parse name)\""
append "path = \"https://github.com/fastly/$k\""
append ''

rm "./$k.toml"
rm "$k.toml"
done

0 comments on commit 84ff62b

Please sign in to comment.