diff --git a/.goreleaser.yml b/.goreleaser.yml index fc775e4f6..233a0bba6 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -73,11 +73,9 @@ archives: <<: *archive_defaults wrap_in_directory: false format: zip - # https://goreleaser.com/customization/aur/ aurs: - - - homepage: "https://github.com/fastly/cli" + - homepage: "https://github.com/fastly/cli" description: "A CLI for interacting with the Fastly platform" maintainers: - 'oss@fastly.com' @@ -183,6 +181,6 @@ changelog: # - --label=created={{ time "2006-01-02T15:04:05Z07:00" }} # - --label=revision={{ .FullCommit }} # - --label=licenses=Apache-2.0 -# dockerfile: Dockerfile-assemblyscript +# dockerfile: Dockerfile-node # - <<: *build_opts # dockerfile: Dockerfile-rust diff --git a/TESTING.md b/TESTING.md index 907707432..741514bf7 100644 --- a/TESTING.md +++ b/TESTING.md @@ -29,9 +29,8 @@ Some integration tests aren't run outside of the CI environment, to enable these The available environment variables are: - `TEST_COMPUTE_INIT`: runs `TestInit`. -- `TEST_COMPUTE_BUILD`: runs `TestBuildRust`, `TestBuildAssemblyScript` and `TestBuildJavaScript`. +- `TEST_COMPUTE_BUILD`: runs `TestBuildRust`, `TestBuildJavaScript`, `TestBuildGo`. - `TEST_COMPUTE_BUILD_RUST`: runs `TestBuildRust`. -- `TEST_COMPUTE_BUILD_ASSEMBLYSCRIPT`: runs `TestBuildAssemblyScript`. - `TEST_COMPUTE_BUILD_JAVASCRIPT`: runs `TestBuildJavaScript`. - `TEST_COMPUTE_DEPLOY`: runs `TestDeploy`. diff --git a/pkg/commands/compute/build.go b/pkg/commands/compute/build.go index f0684babc..00649c662 100644 --- a/pkg/commands/compute/build.go +++ b/pkg/commands/compute/build.go @@ -678,12 +678,6 @@ func identifyToolchain(c *BuildCommand) (string, error) { func language(toolchain, manifestFilename string, c *BuildCommand, in io.Reader, out io.Writer, spinner text.Spinner) (*Language, error) { var language *Language switch toolchain { - case "assemblyscript": - language = NewLanguage(&LanguageOptions{ - Name: "assemblyscript", - SourceDirectory: AsSourceDirectory, - Toolchain: NewAssemblyScript(c, in, manifestFilename, out, spinner), - }) case "go": language = NewLanguage(&LanguageOptions{ Name: "go", diff --git a/pkg/commands/compute/build_test.go b/pkg/commands/compute/build_test.go index 8f4d70864..7af7d08fd 100644 --- a/pkg/commands/compute/build_test.go +++ b/pkg/commands/compute/build_test.go @@ -640,201 +640,6 @@ func TestBuildJavaScript(t *testing.T) { } } -func TestBuildAssemblyScript(t *testing.T) { - if os.Getenv("TEST_COMPUTE_BUILD_ASSEMBLYSCRIPT") == "" && os.Getenv("TEST_COMPUTE_BUILD") == "" { - t.Log("skipping test") - t.Skip("Set TEST_COMPUTE_BUILD to run this test") - } - - args := testutil.Args - - scenarios := []struct { - name string - args []string - fastlyManifest string - wantError string - wantRemediationError string - wantOutput []string - npmInstall bool - }{ - { - name: "no fastly.toml manifest", - args: args("compute build"), - wantError: "error reading fastly.toml", - wantRemediationError: "Run `fastly compute init` to ensure a correctly configured manifest.", - }, - { - name: "empty language", - args: args("compute build"), - fastlyManifest: ` - manifest_version = 2 - name = "test"`, - wantError: "language cannot be empty, please provide a language", - }, - { - name: "unknown language", - args: args("compute build"), - fastlyManifest: ` - manifest_version = 2 - name = "test" - language = "foobar"`, - wantError: "unsupported language foobar", - }, - // The following test validates that the project compiles successfully even - // though the fastly.toml manifest has no build script. There should be a - // default build script inserted. - // - // NOTE: This test passes --verbose so we can validate specific outputs. - { - name: "build script inserted dynamically when missing", - args: args("compute build --verbose"), - fastlyManifest: ` - manifest_version = 2 - name = "test" - language = "assemblyscript"`, - wantOutput: []string{ - "No [scripts.build] found in fastly.toml.", // requires --verbose - "The following default build command for", - "npm exec -- asc", - }, - }, - { - name: "build error", - args: args("compute build"), - fastlyManifest: ` - manifest_version = 2 - name = "test" - language = "assemblyscript" - - [scripts] - build = "echo no compilation happening"`, - wantRemediationError: compute.DefaultBuildErrorRemediation, - }, - // NOTE: This test passes --verbose so we can validate specific outputs. - { - name: "successful build", - args: args("compute build --verbose"), - fastlyManifest: fmt.Sprintf(` - manifest_version = 2 - name = "test" - language = "assemblyscript" - - [scripts] - build = "%s"`, compute.AsDefaultBuildCommand), - wantOutput: []string{ - "Creating ./bin directory (for Wasm binary)", - "Built package", - }, - npmInstall: true, - }, - } - for testcaseIdx := range scenarios { - testcase := &scenarios[testcaseIdx] - t.Run(testcase.name, func(t *testing.T) { - // We're going to chdir to a build environment, - // so save the PWD to return to, afterwards. - pwd, err := os.Getwd() - if err != nil { - t.Fatal(err) - } - - wasmtoolsBinName := "wasm-tools" - - // Windows was having issues when trying to move a tmpBin file (which - // represents the latest binary downloaded from GitHub) to binPath (which - // represents the existing binary installed on a user's machine). - // - // The problem was, for the sake of the tests, I just create one file - // `wasmtoolsBinName` and used that for both `tmpBin` and `binPath` and - // this works fine on *nix systems. But once Windows did `os.Rename()` and - // move tmpBin to binPath it would no longer be able to set permissions on - // the binPath because it didn't think the file existed any more. My guess - // is that moving a file over itself causes Windows to remove the file. - // - // So to work around that issue I just create two separate files because - // in reality that's what the CLI will be dealing with. I only used one - // file for the sake of test case convenience (which ironically became - // very INCONVENIENT when the tests started unexpectedly failing on - // Windows and caused me a long time debugging). - latestDownloaded := wasmtoolsBinName + "-latest-downloaded" - - // Create test environment - rootdir := testutil.NewEnv(testutil.EnvOpts{ - T: t, - Copy: []testutil.FileIO{ - {Src: filepath.Join("testdata", "build", "assemblyscript", "package.json"), Dst: "package.json"}, - {Src: filepath.Join("testdata", "build", "assemblyscript", "assembly", "index.ts"), Dst: filepath.Join("assembly", "index.ts")}, - }, - Write: []testutil.FileIO{ - {Src: `#!/usr/bin/env bash - echo wasm-tools 1.0.4`, Dst: wasmtoolsBinName, Executable: true}, - {Src: `#!/usr/bin/env bash - echo wasm-tools 2.0.0`, Dst: latestDownloaded, Executable: true}, - {Src: testcase.fastlyManifest, Dst: manifest.Filename}, - }, - }) - defer os.RemoveAll(rootdir) - wasmtoolsBinPath := filepath.Join(rootdir, wasmtoolsBinName) - - // Before running the test, chdir into the build environment. - // When we're done, chdir back to our original location. - // This is so we can reliably copy the testdata/ fixtures. - if err := os.Chdir(rootdir); err != nil { - t.Fatal(err) - } - defer func() { - _ = os.Chdir(pwd) - }() - - // NOTE: We only want to run `npm install` for the success case. - if testcase.npmInstall { - // gosec flagged this: - // G204 (CWE-78): Subprocess launched with variable - // Disabling as we control this command. - // #nosec - // nosemgrep - cmd := exec.Command("npm", "install") - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - - err = cmd.Run() - if err != nil { - t.Fatal(err) - } - } - - var stdout threadsafe.Buffer - app.Init = func(_ []string, _ io.Reader) (*global.Data, error) { - opts := testutil.MockGlobalData(testcase.args, &stdout) - opts.Versioners = global.Versioners{ - WasmTools: mock.AssetVersioner{ - AssetVersion: "1.2.3", - BinaryFilename: wasmtoolsBinName, - DownloadOK: true, - DownloadedFile: latestDownloaded, - InstallFilePath: wasmtoolsBinPath, // avoid overwriting developer's actual wasm-tools install - }, - } - return opts, nil - } - err = app.Run(testcase.args, nil) - - t.Log(stdout.String()) - - testutil.AssertRemediationErrorContains(t, err, testcase.wantRemediationError) - - // NOTE: Some errors we want to assert only the remediation. - // e.g. a 'stat' error isn't the same across operating systems/platforms. - if testcase.wantError != "" { - testutil.AssertErrorContains(t, err, testcase.wantError) - } - for _, s := range testcase.wantOutput { - testutil.AssertStringContains(t, stdout.String(), s) - } - }) - } -} - // NOTE: TestBuildOther also validates the post_build settings. func TestBuildOther(t *testing.T) { args := testutil.Args diff --git a/pkg/commands/compute/testdata/build/assemblyscript/assembly/index.ts b/pkg/commands/compute/testdata/build/assemblyscript/assembly/index.ts deleted file mode 100644 index e5e805859..000000000 --- a/pkg/commands/compute/testdata/build/assemblyscript/assembly/index.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { Request, Response, Fastly } from "@fastly/as-compute"; - -// The name of a backend server associated with this service. -// -// This should be changed to match the name of your own backend. See the the -// `Hosts` section of the Fastly Wasm service UI for more information. -const BACKEND_NAME = "backend_name"; - -/// The name of a second backend associated with this service. -const OTHER_BACKEND_NAME = "other_backend_name"; - -// The entry point for your application. -// -// Use this function to define your main request handling logic. It could be -// used to route based on the request properties (such as method or path), send -// the request to a backend, make completely new requests, and/or generate -// synthetic responses. -function main(req: Request): Response { - // Make any desired changes to the client request. - req.headers().set("Host", "example.com"); - - // We can filter requests that have unexpected methods. - const VALID_METHODS = ["HEAD", "GET", "POST"]; - if (!VALID_METHODS.includes(req.method())) { - return new Response(String.UTF8.encode("This method is not allowed"), { - status: 405, - }); - } - - let method = req.method(); - let urlParts = req.url().split("//").pop().split("/"); - let host = urlParts.shift(); - let path = "/" + urlParts.join("/"); - - // If request is a `GET` to the `/` path, send a default response. - if (method == "GET" && path == "/") { - return new Response(String.UTF8.encode("Welcome to Fastly Compute!"), { - status: 200, - }); - } - - // If request is a `GET` to the `/backend` path, send to a named backend. - if (method == "GET" && path == "/backend") { - // Request handling logic could go here... - // E.g., send the request to an origin backend and then cache the - // response for one minute. - let cacheOverride = new Fastly.CacheOverride(); - cacheOverride.setTTL(60); - return Fastly.fetch(req, { - backend: BACKEND_NAME, - cacheOverride, - }).wait(); - } - - // If request is a `GET` to a path starting with `/other/`. - if (method == "GET" && path.startsWith("/other/")) { - // Send request to a different backend and don't cache response. - let cacheOverride = new Fastly.CacheOverride(); - cacheOverride.setPass(); - return Fastly.fetch(req, { - backend: OTHER_BACKEND_NAME, - cacheOverride, - }).wait(); - } - - // Catch all other requests and return a 404. - return new Response(String.UTF8.encode("The page you requested could not be found"), { - status: 200, - }); -} - -// Get the request from the client. -let req = Fastly.getClientRequest(); - -// Pass the request to the main request handler function. -let resp = main(req); - -// Send the response back to the client. -Fastly.respondWith(resp); \ No newline at end of file diff --git a/pkg/commands/compute/testdata/build/assemblyscript/package.json b/pkg/commands/compute/testdata/build/assemblyscript/package.json deleted file mode 100644 index c80e89c3a..000000000 --- a/pkg/commands/compute/testdata/build/assemblyscript/package.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "compute-starter-kit-assemblyscript-default", - "version": "1.0.0", - "description": "Default package starter kit for AssemblyScript based Compute projects", - "main": "src/index.ts", - "repository": { - "type": "git", - "url": "git+https://github.com/fastly/compute-starter-kit-assemblyscript-default.git" - }, - "keywords": [], - "author": "oss@fastly.com", - "license": "MIT", - "bugs": { - "url": "https://github.com/fastly/compute-starter-kit-assemblyscript-default/issues" - }, - "homepage": "https://github.com/fastly/compute-starter-kit-assemblyscript-default#readme", - "devDependencies": { - "assemblyscript": "^0.14.11" - }, - "dependencies": { - "@fastly/as-compute": "^0.1.1" - } -} \ No newline at end of file diff --git a/pkg/config/config.go b/pkg/config/config.go index 7d67cbe02..8ffb70440 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -162,10 +162,9 @@ type Profile struct { // StarterKitLanguages represents language specific starter kits. type StarterKitLanguages struct { - AssemblyScript []StarterKit `toml:"assemblyscript"` - Go []StarterKit `toml:"go"` - JavaScript []StarterKit `toml:"javascript"` - Rust []StarterKit `toml:"rust"` + Go []StarterKit `toml:"go"` + JavaScript []StarterKit `toml:"javascript"` + Rust []StarterKit `toml:"rust"` } // StarterKit represents starter kit specific configuration. diff --git a/pkg/config/testdata/config-incompatible-config-version.toml b/pkg/config/testdata/config-incompatible-config-version.toml index 7b0b57274..b6c5817c0 100644 --- a/pkg/config/testdata/config-incompatible-config-version.toml +++ b/pkg/config/testdata/config-incompatible-config-version.toml @@ -10,23 +10,18 @@ last_checked = "2021-06-18T15:13:34+01:00" version = "0.0.1" [language] - [language.rust] - # we're missing the 'toolchain_constraint' property - wasm_wasi_target = "wasm32-wasi" +[language.rust] +# we're missing the 'toolchain_constraint' property +wasm_wasi_target = "wasm32-wasi" [starter-kits] -[[starter-kits.assemblyscript]] - name = "Default" - path = "https://github.com/fastly/compute-starter-kit-assemblyscript-default" - tag = "v0.2.1" [[starter-kits.rust]] - name = "Default" - path = "https://github.com/fastly/compute-starter-kit-rust-default.git" - branch = "0.7" +name = "Default" +path = "https://github.com/fastly/compute-starter-kit-rust-default.git" +branch = "0.7" [[starter-kits.rust]] - name = "Beacon" - path = "https://github.com/fastly/compute-starter-kit-rust-beacon-termination.git" +name = "Beacon" +path = "https://github.com/fastly/compute-starter-kit-rust-beacon-termination.git" [[starter-kits.rust]] - name = "Static" - path = "https://github.com/fastly/compute-starter-kit-rust-static-content.git" - +name = "Static" +path = "https://github.com/fastly/compute-starter-kit-rust-static-content.git" diff --git a/pkg/config/testdata/config.toml b/pkg/config/testdata/config.toml index e94529f9b..285bca690 100644 --- a/pkg/config/testdata/config.toml +++ b/pkg/config/testdata/config.toml @@ -10,28 +10,24 @@ last_checked = "2021-06-18T15:13:34+01:00" version = "0.0.1" [language] - [language.rust] - toolchain_constraint = ">= 1.49.0 < 2.0.0" - wasm_wasi_target = "wasm32-wasi" +[language.rust] +toolchain_constraint = ">= 1.49.0 < 2.0.0" +wasm_wasi_target = "wasm32-wasi" [starter-kits] -[[starter-kits.assemblyscript]] - name = "Default" - description = "A basic starter kit that demonstrates routing, simple synthetic responses and overriding caching rules." - path = "https://github.com/fastly/compute-starter-kit-assemblyscript-default" [[starter-kits.javascript]] - name = "Default" - description = "A basic starter kit that demonstrates routing and simple synthetic responses." - path = "https://github.com/fastly/compute-starter-kit-javascript-default" +name = "Default" +description = "A basic starter kit that demonstrates routing and simple synthetic responses." +path = "https://github.com/fastly/compute-starter-kit-javascript-default" [[starter-kits.rust]] - name = "Default" - description = "A basic starter kit that demonstrates routing, simple synthetic responses and overriding caching rules." - path = "https://github.com/fastly/compute-starter-kit-rust-default" +name = "Default" +description = "A basic starter kit that demonstrates routing, simple synthetic responses and overriding caching rules." +path = "https://github.com/fastly/compute-starter-kit-rust-default" [[starter-kits.rust]] - name = "Beacon" - description = "Capture beacon data from the browser, divert beacon request payloads to a log endpoint, and avoid putting load on your own infrastructure." - path = "https://github.com/fastly/compute-starter-kit-rust-beacon-termination" +name = "Beacon" +description = "Capture beacon data from the browser, divert beacon request payloads to a log endpoint, and avoid putting load on your own infrastructure." +path = "https://github.com/fastly/compute-starter-kit-rust-beacon-termination" [[starter-kits.rust]] - name = "Static" - description = "Apply performance, security and usability upgrades to static bucket services such as Google Cloud Storage or AWS S3." - path = "https://github.com/fastly/compute-starter-kit-rust-static-content" +name = "Static" +description = "Apply performance, security and usability upgrades to static bucket services such as Google Cloud Storage or AWS S3." +path = "https://github.com/fastly/compute-starter-kit-rust-static-content" diff --git a/pkg/config/testdata/static/config.toml b/pkg/config/testdata/static/config.toml index d45fb9fcd..90abe02a5 100644 --- a/pkg/config/testdata/static/config.toml +++ b/pkg/config/testdata/static/config.toml @@ -8,28 +8,24 @@ remote_config = "https://developer.fastly.com/api/internal/cli-config" ttl = "5m" [language] - [language.rust] - toolchain_constraint = ">= 1.49.0 < 2.0.0" - wasm_wasi_target = "wasm32-wasi" +[language.rust] +toolchain_constraint = ">= 1.49.0 < 2.0.0" +wasm_wasi_target = "wasm32-wasi" [starter-kits] -[[starter-kits.assemblyscript]] - name = "Default" - description = "A basic starter kit that demonstrates routing, simple synthetic responses and overriding caching rules." - path = "https://github.com/fastly/compute-starter-kit-assemblyscript-default" [[starter-kits.javascript]] - name = "Default" - description = "A basic starter kit that demonstrates routing and simple synthetic responses." - path = "https://github.com/fastly/compute-starter-kit-javascript-default" +name = "Default" +description = "A basic starter kit that demonstrates routing and simple synthetic responses." +path = "https://github.com/fastly/compute-starter-kit-javascript-default" [[starter-kits.rust]] - name = "Default" - description = "A basic starter kit that demonstrates routing, simple synthetic responses and overriding caching rules." - path = "https://github.com/fastly/compute-starter-kit-rust-default" +name = "Default" +description = "A basic starter kit that demonstrates routing, simple synthetic responses and overriding caching rules." +path = "https://github.com/fastly/compute-starter-kit-rust-default" [[starter-kits.rust]] - name = "Beacon" - description = "Capture beacon data from the browser, divert beacon request payloads to a log endpoint, and avoid putting load on your own infrastructure." - path = "https://github.com/fastly/compute-starter-kit-rust-beacon-termination" +name = "Beacon" +description = "Capture beacon data from the browser, divert beacon request payloads to a log endpoint, and avoid putting load on your own infrastructure." +path = "https://github.com/fastly/compute-starter-kit-rust-beacon-termination" [[starter-kits.rust]] - name = "Static" - description = "Apply performance, security and usability upgrades to static bucket services such as Google Cloud Storage or AWS S3." - path = "https://github.com/fastly/compute-starter-kit-rust-static-content" +name = "Static" +description = "Apply performance, security and usability upgrades to static bucket services such as Google Cloud Storage or AWS S3." +path = "https://github.com/fastly/compute-starter-kit-rust-static-content" diff --git a/scripts/config.sh b/scripts/config.sh index 0b2beaeb0..d67112027 100755 --- a/scripts/config.sh +++ b/scripts/config.sh @@ -4,40 +4,38 @@ set -e cp ".fastly/config.toml" "pkg/config/config.toml" -if ! command -v tomlq &> /dev/null -then - cargo install tomlq +if ! command -v tomlq &>/dev/null; then + cargo install tomlq fi kits=( - compute-starter-kit-assemblyscript-default - compute-starter-kit-go-default - compute-starter-kit-go-tinygo - compute-starter-kit-javascript-default - compute-starter-kit-javascript-empty - compute-starter-kit-rust-default - compute-starter-kit-rust-empty - compute-starter-kit-rust-static-content - compute-starter-kit-rust-websockets - compute-starter-kit-typescript + compute-starter-kit-go-default + compute-starter-kit-go-tinygo + compute-starter-kit-javascript-default + compute-starter-kit-javascript-empty + compute-starter-kit-rust-default + compute-starter-kit-rust-empty + compute-starter-kit-rust-static-content + compute-starter-kit-rust-websockets + compute-starter-kit-typescript ) 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 '' - append "[[starter-kits.$(parse language)]]" - append "description = \"$(parse description)\"" - append "name = \"$(parse name)\"" - append "path = \"https://github.com/fastly/$k\"" + append '' + append "[[starter-kits.$(parse language)]]" + append "description = \"$(parse description)\"" + append "name = \"$(parse name)\"" + append "path = \"https://github.com/fastly/$k\"" - rm "$k.toml" + rm "$k.toml" done