Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
122400a
init and verify done
Integralist Apr 29, 2022
db7469b
fix rebase conflict for fastly.toml package name
Integralist Jul 14, 2022
eeee3a8
resolve conflicts
Integralist May 26, 2022
afc7de8
update LocalServer doc string
Integralist May 3, 2022
f0bd91a
1.18.1
Integralist May 3, 2022
7d54a4c
clarify toolchain/compiler fields
Integralist May 3, 2022
f1159f0
fix invalid go mod
Integralist May 4, 2022
a948781
update warning
Integralist May 23, 2022
ce70822
fix snippet tests
Integralist May 26, 2022
2939d56
remove --verbose flag as it's not a recognised asc compiler options
Integralist May 26, 2022
42ef24c
replace --binaryFile with --outFile
Integralist May 26, 2022
b1a2458
update default config
Integralist May 30, 2022
05b7715
include compiler for Go
Integralist Jun 13, 2022
7f15c02
add PLC
Integralist Jun 15, 2022
8cf62c6
lowercase
Integralist Jun 27, 2022
fffc6d0
resolve conflicts
Integralist Jun 29, 2022
3ed76e5
typo
Integralist Jun 29, 2022
e0ed150
fix merge conflict
Integralist Jul 6, 2022
7ddc026
make src directory more flexible
Integralist Jun 29, 2022
7abf4b2
fix tinygo build setup
Integralist Jun 29, 2022
b6ab2fb
bug fixes for go running from the root directory
Integralist Jun 29, 2022
d57427b
bump versions
Integralist Jul 12, 2022
c87e5f4
resolve conflict in rebase
Integralist Jul 15, 2022
d2851ab
fix tests
Integralist Jul 12, 2022
b8a11cb
go tests
Integralist Jul 12, 2022
1460490
fix ci by installing tinygo
Integralist Jul 13, 2022
72fc1ec
replace brew install with manual install
Integralist Jul 13, 2022
650b2e5
revert to brew
Integralist Jul 13, 2022
6160ff4
get ci working for windows
Integralist Jul 13, 2022
7372810
fix broken test and a bad rebase
Integralist Jul 14, 2022
78d752b
fix gitignore
Integralist Jul 15, 2022
247170d
update static config
Integralist Jul 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion .github/workflows/pr_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
test:
strategy:
matrix:
tinygo-version: [0.24.0]
go-version: [1.18.x]
node-version: [12]
rust-toolchain: [stable]
Expand Down Expand Up @@ -97,10 +98,39 @@ jobs:
- name: "Download latest app config"
run: |
make config
- name: "Test suite"
- if: ${{ matrix.platform == 'ubuntu-latest' }}
name: Install TinyGo (Ubuntu)
run: |
wget https://github.com/tinygo-org/tinygo/releases/download/v${{ matrix.tinygo-version }}/tinygo_${{ matrix.tinygo-version }}_amd64.deb
sudo dpkg -i tinygo_${{ matrix.tinygo-version }}_amd64.deb
echo "/usr/local/bin" >> $GITHUB_PATH
tinygo version
- if: ${{ matrix.platform == 'macos-latest' }}
name: Install TinyGo (macOS)
run: |
brew tap tinygo-org/tools
brew install tinygo
tinygo version
- if: ${{ matrix.platform != 'windows-latest' }}
name: "Test suite"
run: make test
shell: bash
env:
TEST_COMPUTE_INIT: true
TEST_COMPUTE_BUILD: true
TEST_COMPUTE_DEPLOY: true
# NOTE: I was unable to get scoops's shims to persist across steps.
# So we duplicate the `make test` step and combine the scoop install.
- if: ${{ matrix.platform == 'windows-latest' }}
name: "Test suite (Windows)"
run: |
iex "& {$(irm get.scoop.sh)} -RunAsAdmin"
scoop install binaryen
scoop install go
scoop install tinygo
tinygo version
make test
env:
TEST_COMPUTE_INIT: true
TEST_COMPUTE_BUILD: true
TEST_COMPUTE_DEPLOY: true
9 changes: 4 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# ignore fastly binary
#
# NOTE: This can cause fuzzy finders to fail to locate cmd/fastly/main.go
# because gitignore cannot negate files inside an ignore directory.
fastly
# Fastly binary
**/fastly
# But allow fastly main package
!cmd/fastly

RELEASE_CHANGELOG.md

Expand Down
18 changes: 17 additions & 1 deletion DEVELOP.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Development

The Fastly CLI requires [Go 1.16 or above](https://golang.org). Clone this repo
The Fastly CLI requires [Go 1.18 or above](https://golang.org). Clone this repo
to any path and type `make` to run all of the tests and generate a development
build locally.

Expand Down Expand Up @@ -54,3 +54,19 @@ CLI_CATEGORY=logging CLI_CATEGORY_COMMAND=logging CLI_PACKAGE=foobar CLI_COMMAND
```

> **NOTE**: Within the generated files, keep an eye out for any `<...>` references that need to be manually updated.

### config.toml

The CLI will attempt to sync its internal configuration data with the following API endpoint:

```
https://developer.fastly.com/api/internal/cli-config
```

The config served from that endpoint is the result of an internal Fastly build process that uses the `.fastly/config.toml` file in the CLI repo as a template, and then dynamically adds in any available Starter Kits.

In case of an API service failure, the CLI will use a built-in version of the `config.toml` file here:

```
./cmd/fastly/static/config.toml
```
5 changes: 5 additions & 0 deletions cmd/fastly/static/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ name = "Default starter for AssemblyScript"
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.go]]
name = "Default starter for Go"
description = "A basic starter kit that demonstrates routing, simple synthetic responses and overriding caching rules."
path = "https://github.com/fastly/compute-starter-kit-go-default"

[[starter-kits.javascript]]
name = "Default starter for JavaScript"
description = "A basic starter kit that demonstrates routing, simple synthetic responses and overriding caching rules."
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3896,7 +3896,7 @@ COMMANDS
version
--autoclone If the selected service version is not
editable, clone it and use the clone.
--address=ADDRESS The hostname or IPv4 addres
--address=ADDRESS The hostname or IPv4 address
--user=USER The username for the server
--ssh-known-hosts=SSH-KNOWN-HOSTS
A list of host keys for all hosts we can
Expand Down
54 changes: 44 additions & 10 deletions pkg/commands/compute/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,27 +128,61 @@ func (c *BuildCommand) Exec(in io.Reader, out io.Writer) (err error) {
language = NewLanguage(&LanguageOptions{
Name: "assemblyscript",
SourceDirectory: ASSourceDirectory,
IncludeFiles: []string{"package.json"},
Toolchain: NewAssemblyScript(c.Flags.Timeout, name, c.Manifest.File.Scripts, c.Globals.ErrLog),
IncludeFiles: []string{JSManifestName},
Toolchain: NewAssemblyScript(
name,
c.Manifest.File.Scripts,
c.Globals.ErrLog,
c.Flags.Timeout,
),
})
case "go":
language = NewLanguage(&LanguageOptions{
Name: "go",
SourceDirectory: GoSourceDirectory,
IncludeFiles: []string{GoManifestName},
Toolchain: NewGo(
name,
c.Manifest.File.Scripts,
c.Globals.ErrLog,
c.Flags.Timeout,
c.Globals.File.Language.Go,
),
})
case "javascript":
language = NewLanguage(&LanguageOptions{
Name: "javascript",
SourceDirectory: JSSourceDirectory,
IncludeFiles: []string{"package.json"},
Toolchain: NewJavaScript(c.Flags.Timeout, name, c.Manifest.File.Scripts, c.Globals.ErrLog),
IncludeFiles: []string{JSManifestName},
Toolchain: NewJavaScript(
name,
c.Manifest.File.Scripts,
c.Globals.ErrLog,
c.Flags.Timeout,
),
})
case "rust":
language = NewLanguage(&LanguageOptions{
Name: "rust",
SourceDirectory: RustSourceDirectory,
IncludeFiles: []string{"Cargo.toml"},
Toolchain: NewRust(c.Globals.HTTPClient, c.Globals.File.Language.Rust, c.Globals.ErrLog, c.Flags.Timeout, name, c.Manifest.File.Scripts),
IncludeFiles: []string{RustManifestName},
Toolchain: NewRust(
name,
c.Manifest.File.Scripts,
c.Globals.ErrLog,
c.Globals.HTTPClient,
c.Flags.Timeout,
c.Globals.File.Language.Rust,
),
})
case "other":
language = NewLanguage(&LanguageOptions{
Name: "other",
Toolchain: NewOther(c.Flags.Timeout, c.Manifest.File.Scripts, c.Globals.ErrLog),
Name: "other",
Toolchain: NewOther(
c.Manifest.File.Scripts,
c.Globals.ErrLog,
c.Flags.Timeout,
),
})
default:
return fmt.Errorf("unsupported language %s", toolchain)
Expand Down Expand Up @@ -408,8 +442,8 @@ func GetIgnoredFiles(filePath string) (files map[string]bool, err error) {
return files, nil
}

// GetNonIgnoredFiles walks a filepath and returns all files don't exist in the
// provided ignore files map.
// GetNonIgnoredFiles walks a filepath and returns all files that don't exist in
// the provided ignore files map.
func GetNonIgnoredFiles(base string, ignoredFiles map[string]bool) ([]string, error) {
var files []string
err := filepath.Walk(base, func(path string, info os.FileInfo, err error) error {
Expand Down
153 changes: 150 additions & 3 deletions pkg/commands/compute/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,18 @@ func TestBuildJavaScript(t *testing.T) {
language = "javascript"`,
wantError: "name cannot be empty, please provide a name",
},
{
name: "JavaScript compilation error",
args: args("compute build --verbose"),
fastlyManifest: `
manifest_version = 2
name = "test"
language = "javascript"`,
sourceOverride: `D"F;
'GREGERgregeg '
ERG`,
wantError: "error during execution process",
},
{
name: "JavaScript success",
args: args("compute build"),
Expand All @@ -517,18 +529,133 @@ func TestBuildJavaScript(t *testing.T) {
language = "javascript"`,
wantOutputContains: "Built package 'test'",
},
} {
t.Run(testcase.name, func(t *testing.T) {
if testcase.fastlyManifest != "" {
if err := os.WriteFile(filepath.Join(rootdir, manifest.Filename), []byte(testcase.fastlyManifest), 0o777); err != nil {
t.Fatal(err)
}
}

// We want to ensure the original `index.js` is put back in case of a test
// case overriding its content using `sourceOverride`.
src := filepath.Join(rootdir, "src", "index.js")
b, err := os.ReadFile(src)
if err != nil {
t.Fatal(err)
}
defer func(src string, b []byte) {
err := os.WriteFile(src, b, 0o644)
if err != nil {
t.Fatal(err)
}
}(src, b)

if testcase.sourceOverride != "" {
if err := os.WriteFile(src, []byte(testcase.sourceOverride), 0o777); err != nil {
t.Fatal(err)
}
}

var stdout threadsafe.Buffer
opts := testutil.NewRunOpts(testcase.args, &stdout)
err = app.Run(opts)

t.Log(stdout.String())

testutil.AssertErrorContains(t, err, testcase.wantError)
testutil.AssertRemediationErrorContains(t, err, testcase.wantRemediationError)
if testcase.wantOutputContains != "" {
testutil.AssertStringContains(t, stdout.String(), testcase.wantOutputContains)
}
})
}
}

func TestBuildGo(t *testing.T) {
args := testutil.Args
if os.Getenv("TEST_COMPUTE_BUILD_GO") == "" && os.Getenv("TEST_COMPUTE_BUILD") == "" {
t.Log("skipping test")
t.Skip("Set TEST_COMPUTE_BUILD_GO or TEST_COMPUTE_BUILD to run this test")
}

// 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)
}

// Create test environment
rootdir := testutil.NewEnv(testutil.EnvOpts{
T: t,
Copy: []testutil.FileIO{
{Src: filepath.Join("testdata", "build", "go", "go.mod"), Dst: "go.mod"},
{Src: filepath.Join("testdata", "build", "go", "main.go"), Dst: "main.go"},
},
})
defer os.RemoveAll(rootdir)

// 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 os.Chdir(pwd)

for _, testcase := range []struct {
name string
args []string
fastlyManifest string
sourceOverride string
wantError string
wantRemediationError string
wantOutputContains string
}{
{
name: "no fastly.toml manifest",
args: args("compute build"),
wantError: "error reading package manifest",
wantRemediationError: "Run `fastly compute init` to ensure a correctly configured manifest.",
},
{
name: "JavaScript compilation error",
name: "empty language",
args: args("compute build"),
fastlyManifest: `
manifest_version = 2
name = "test"`,
wantError: "language cannot be empty, please provide a language",
},
{
name: "empty name",
args: args("compute build"),
fastlyManifest: `
manifest_version = 2
language = "go"`,
wantError: "name cannot be empty, please provide a name",
},
{
name: "syntax error",
args: args("compute build --verbose"),
fastlyManifest: `
manifest_version = 2
name = "test"
language = "javascript"`,
language = "go"`,
sourceOverride: `D"F;
'GREGERgregeg '
ERG`,
wantError: "error during execution process",
},
{
name: "success",
args: args("compute build"),
fastlyManifest: `
manifest_version = 2
name = "test"
language = "go"`,
wantOutputContains: "Built package 'test'",
},
} {
t.Run(testcase.name, func(t *testing.T) {
if testcase.fastlyManifest != "" {
Expand All @@ -537,14 +664,34 @@ func TestBuildJavaScript(t *testing.T) {
}
}

// We want to ensure the original `main.go` is put back in case of a test
// case overriding its content using `sourceOverride`.
src := filepath.Join(rootdir, "main.go")
b, err := os.ReadFile(src)
if err != nil {
t.Fatal(err)
}
defer func(src string, b []byte) {
err := os.WriteFile(src, b, 0o644)
if err != nil {
t.Fatal(err)
}
}(src, b)

if testcase.sourceOverride != "" {
if err := os.WriteFile(filepath.Join(rootdir, "src", "index.js"), []byte(testcase.sourceOverride), 0o777); err != nil {
if err := os.WriteFile(src, []byte(testcase.sourceOverride), 0o777); err != nil {
t.Fatal(err)
}
}

var stdout threadsafe.Buffer
opts := testutil.NewRunOpts(testcase.args, &stdout)

// NOTE: The following constraints should be kept in-sync with
// cmd/fastly/static/config.toml
opts.ConfigFile.Language.Go.TinyGoConstraint = ">= 0.24.0-0" // NOTE: -0 is to allow prereleases.
opts.ConfigFile.Language.Go.ToolchainConstraint = ">= 1.17 < 1.19"

err = app.Run(opts)

t.Log(stdout.String())
Expand Down
Loading