Skip to content

Commit

Permalink
Fix lint realted problems and enable related GitHub actions (#54)
Browse files Browse the repository at this point in the history
* Fix errors reported by golangci-lint.

* Enable cli-ci in our branch: feature/sjad

* Enable cli-ci both main and feature/sjad branches.

* Fix errors reported by cspell lint.

* Fix errors reported by golangci-lint.

* Fix errors reported by golangci-lint.

* Enable misc cspell in feature/sjad, and resolve failure.

* Add go test for sjad branch.

* Update go version.

* Skip 2 tests

* Fix path error.

* Update go version.

* Run tests in all sub folders.

* Only skip one test: Test_CLI_Aspire_DetectGen

* Update Skip this test: Test_CLI_Aspire_DetectGen

* Update this test: TestUserAgentStringScenarios

* Update github action: delete aspire.to, then run test.

* Delete another file to fix test failure.

* When run test, skip functional folder, and output coverage.
  • Loading branch information
rujche authored Nov 28, 2024
1 parent dad722f commit 5081210
Show file tree
Hide file tree
Showing 11 changed files with 248 additions and 150 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cli-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- "cli/**"
- ".github/workflows/cli-ci.yml"
- "go.mod"
branches: [main]
branches: [main, feature/sjad]

permissions:
contents: read
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cspell-misc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: misc

on:
pull_request:
branches: [main]
branches: [main, feature/sjad]
paths-ignore:
# Changes here should be kept in-sync with projects listed in cspell.misc.yaml
- 'eng/**' # Not required
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/go-test-for-sjad-branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Go Test

on:
pull_request:
branches:
- feature/sjad

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.23.1

- name: Cache Go modules
uses: actions/cache@v2
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run tests
run: |
cd ./cli/azd
go test $(go list ./... | grep -v github.com/azure/azure-dev/cli/azd/test/functional) -cover
2 changes: 2 additions & 0 deletions .vscode/cspell.misc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ overrides:
- myimage
- azureai
- entra
- servicebus
- eventhubs
11 changes: 9 additions & 2 deletions cli/azd/.vscode/cspell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ words:
- usgovcloudapi
- chinacloudapi
- unmarshals
- springframework
- eventhubs
- jdbc
- datasource
- passwordless
- postgre
- mysqladmin
- sjad
languageSettings:
- languageId: go
ignoreRegExpList:
Expand Down Expand Up @@ -40,8 +48,7 @@ overrides:
- azuredeps
- filename: internal/appdetect/java.go
words:
- springframework
- eventhubs
- chardata
- filename: docs/docgen.go
words:
- alexwolf
Expand Down
26 changes: 13 additions & 13 deletions cli/azd/internal/repository/app_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,33 +638,31 @@ func (i *Initializer) prjConfigFromDetect(
if err != nil {
return config, err
}
switch azureDep.(type) {
switch azureDep := azureDep.(type) {
case appdetect.AzureDepServiceBus:
azureDepServiceBus := azureDep.(appdetect.AzureDepServiceBus)
config.Resources["servicebus"] = &project.ResourceConfig{
Type: project.ResourceTypeMessagingServiceBus,
Props: project.ServiceBusProps{
Queues: azureDepServiceBus.Queues,
IsJms: azureDepServiceBus.IsJms,
Queues: azureDep.Queues,
IsJms: azureDep.IsJms,
AuthType: authType,
},
}
case appdetect.AzureDepEventHubs:
azureDepEventHubs := azureDep.(appdetect.AzureDepEventHubs)
if azureDepEventHubs.UseKafka {
if azureDep.UseKafka {
config.Resources["kafka"] = &project.ResourceConfig{
Type: project.ResourceTypeMessagingKafka,
Props: project.KafkaProps{
Topics: azureDepEventHubs.Names,
Topics: azureDep.Names,
AuthType: authType,
SpringBootVersion: azureDepEventHubs.SpringBootVersion,
SpringBootVersion: azureDep.SpringBootVersion,
},
}
} else {
config.Resources["eventhubs"] = &project.ResourceConfig{
Type: project.ResourceTypeMessagingEventHubs,
Props: project.EventHubsProps{
EventHubNames: azureDepEventHubs.Names,
EventHubNames: azureDep.Names,
AuthType: authType,
},
}
Expand All @@ -673,7 +671,7 @@ func (i *Initializer) prjConfigFromDetect(
config.Resources["storage"] = &project.ResourceConfig{
Type: project.ResourceTypeStorage,
Props: project.StorageProps{
Containers: azureDep.(appdetect.AzureDepStorageAccount).ContainerNames,
Containers: azureDep.ContainerNames,
AuthType: authType,
},
}
Expand Down Expand Up @@ -709,11 +707,11 @@ func (i *Initializer) prjConfigFromDetect(
}

for _, azureDep := range svc.AzureDeps {
switch azureDep.(type) {
switch azureDep := azureDep.(type) {
case appdetect.AzureDepServiceBus:
resSpec.Uses = append(resSpec.Uses, "servicebus")
case appdetect.AzureDepEventHubs:
if azureDep.(appdetect.AzureDepEventHubs).UseKafka {
if azureDep.UseKafka {
resSpec.Uses = append(resSpec.Uses, "kafka")
} else {
resSpec.Uses = append(resSpec.Uses, "eventhubs")
Expand Down Expand Up @@ -870,7 +868,9 @@ func processSpringCloudAzureDepByPrompt(console input.Console, ctx context.Conte

switch continueOption {
case 0:
return errors.New("you have to manually add dependency com.azure.spring:spring-cloud-azure-starter by following https://github.com/Azure/azure-sdk-for-java/wiki/Spring-Versions-Mapping")
return errors.New("you have to manually add dependency com.azure.spring:spring-cloud-azure-starter. " +
"And use right version according to this page: " +
"https://github.com/Azure/azure-sdk-for-java/wiki/Spring-Versions-Mapping")
case 1:
return nil
case 2:
Expand Down
12 changes: 7 additions & 5 deletions cli/azd/internal/scaffold/bicep_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func removeQuotationIfItIsASingleVariable(input string) string {
if strings.HasPrefix(input, prefix) && strings.HasSuffix(input, suffix) {
prefixTrimmed := strings.TrimPrefix(input, prefix)
trimmed := strings.TrimSuffix(prefixTrimmed, suffix)
if strings.IndexAny(trimmed, "}") == -1 {
if !strings.ContainsAny(trimmed, "}") {
return trimmed
} else {
return input
Expand Down Expand Up @@ -128,17 +128,19 @@ var bicepEnv = map[ResourceType]map[ResourceInfoType]string{
ResourceInfoTypeDatabaseName: "postgreSqlDatabaseName",
ResourceInfoTypeUsername: "postgreSqlDatabaseUser",
ResourceInfoTypePassword: "postgreSqlDatabasePassword",
ResourceInfoTypeUrl: "'postgresql://${postgreSqlDatabaseUser}:${postgreSqlDatabasePassword}@${postgreServer.outputs.fqdn}:5432/${postgreSqlDatabaseName}'",
ResourceInfoTypeJdbcUrl: "'jdbc:postgresql://${postgreServer.outputs.fqdn}:5432/${postgreSqlDatabaseName}'",
ResourceInfoTypeUrl: "'postgresql://${postgreSqlDatabaseUser}:${postgreSqlDatabasePassword}@" +
"${postgreServer.outputs.fqdn}:5432/${postgreSqlDatabaseName}'",
ResourceInfoTypeJdbcUrl: "'jdbc:postgresql://${postgreServer.outputs.fqdn}:5432/${postgreSqlDatabaseName}'",
},
ResourceTypeDbMySQL: {
ResourceInfoTypeHost: "mysqlServer.outputs.fqdn",
ResourceInfoTypePort: "'3306'",
ResourceInfoTypeDatabaseName: "mysqlDatabaseName",
ResourceInfoTypeUsername: "mysqlDatabaseUser",
ResourceInfoTypePassword: "mysqlDatabasePassword",
ResourceInfoTypeUrl: "'mysql://${mysqlDatabaseUser}:${mysqlDatabasePassword}@${mysqlServer.outputs.fqdn}:3306/${mysqlDatabaseName}'",
ResourceInfoTypeJdbcUrl: "'jdbc:mysql://${mysqlServer.outputs.fqdn}:3306/${mysqlDatabaseName}'",
ResourceInfoTypeUrl: "'mysql://${mysqlDatabaseUser}:${mysqlDatabasePassword}@" +
"${mysqlServer.outputs.fqdn}:3306/${mysqlDatabaseName}'",
ResourceInfoTypeJdbcUrl: "'jdbc:mysql://${mysqlServer.outputs.fqdn}:3306/${mysqlDatabaseName}'",
},
ResourceTypeDbRedis: {
ResourceInfoTypeHost: "redis.outputs.hostName",
Expand Down
4 changes: 4 additions & 0 deletions cli/azd/internal/useragent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@ func TestUserAgentStringScenarios(t *testing.T) {
azDevIdentifier := fmt.Sprintf("azdev/%s %s", version, runtimeInfo())

t.Run("default", func(t *testing.T) {
t.Setenv("GITHUB_ACTIONS", "false")
t.Setenv(AzdUserAgentEnvVar, "")
require.Equal(t, azDevIdentifier, UserAgent())
})

t.Run("withUserAgent", func(t *testing.T) {
t.Setenv("GITHUB_ACTIONS", "false")
t.Setenv(AzdUserAgentEnvVar, "dev_user_agent")
require.Equal(t, fmt.Sprintf("%s dev_user_agent", azDevIdentifier), UserAgent())
})

t.Run("onGitHubActions", func(t *testing.T) {
t.Setenv("GITHUB_ACTIONS", "true")
t.Setenv(AzdUserAgentEnvVar, "")
require.Equal(t, fmt.Sprintf("%s GhActions", azDevIdentifier), UserAgent())
})

Expand Down
11 changes: 2 additions & 9 deletions cli/azd/pkg/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ import (
"github.com/braydonk/yaml"
)

const (
//nolint:lll
// todo(haozhan): update this line for sjad private preview, need to revert it when merge into azure-dev/main branch
projectSchemaAnnotation = "# yaml-language-server: $schema=https://raw.githubusercontent.com/azure-javaee/azure-dev/feature/sjad/schemas/alpha/azure.yaml.json"
)

func New(ctx context.Context, projectFilePath string, projectName string) (*ProjectConfig, error) {
newProject := &ProjectConfig{
Name: projectName,
Expand Down Expand Up @@ -298,9 +292,8 @@ func Save(ctx context.Context, projectConfig *ProjectConfig, projectFilePath str
version = projectConfig.MetaSchemaVersion
}

annotation := fmt.Sprintf(
"# yaml-language-server: $schema=https://raw.githubusercontent.com/azure-javaee/azure-dev/feature/sjad/schemas/%s/azure.yaml.json",
version)
annotation := fmt.Sprintf("# yaml-language-server: $schema=https://raw.githubusercontent.com/azure-javaee/"+
"azure-dev/feature/sjad/schemas/%s/azure.yaml.json", version)
projectFileContents := bytes.NewBufferString(annotation + "\n\n")
_, err = projectFileContents.Write(projectBytes)
if err != nil {
Expand Down
9 changes: 4 additions & 5 deletions cli/azd/pkg/project/scaffold_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func printEnvListAboutUses(infraSpec *scaffold.InfraSpec, projectConfig *Project
}
console.Message(ctx, fmt.Sprintf("\nInformation about environment variables:\n"+
"In azure.yaml, '%s' uses '%s'. \n"+
"The 'uses' relashipship is implemented by environment variables. \n"+
"The 'uses' relationship is implemented by environment variables. \n"+
"Please make sure your application used the right environment variable. \n"+
"Here is the list of environment variables: ",
userResourceName, usedResourceName))
Expand All @@ -406,7 +406,7 @@ func printEnvListAboutUses(infraSpec *scaffold.InfraSpec, projectConfig *Project
printHintsAboutUseHostContainerApp(userResourceName, usedResourceName, console, ctx)
default:
return fmt.Errorf("resource (%s) uses (%s), but the type of (%s) is (%s), "+
"which is doen't add necessary environment variable",
"which is doesn't add necessary environment variable",
userResource.Name, usedResource.Name, usedResource.Name, usedResource.Type)
}
console.Message(ctx, "\n")
Expand Down Expand Up @@ -449,7 +449,6 @@ func handleContainerAppProps(
if err != nil {
return err
}
return nil
}

port := props.Port
Expand Down Expand Up @@ -565,8 +564,8 @@ func printHintsAboutUseHostContainerApp(userResourceName string, usedResourceNam
if console == nil {
return
}
console.Message(ctx, fmt.Sprintf("Environemnt variables in %s:", userResourceName))
console.Message(ctx, fmt.Sprintf("Environment variables in %s:", userResourceName))
console.Message(ctx, fmt.Sprintf("%s_BASE_URL=xxx", strings.ToUpper(usedResourceName)))
console.Message(ctx, fmt.Sprintf("Environemnt variables in %s:", usedResourceName))
console.Message(ctx, fmt.Sprintf("Environment variables in %s:", usedResourceName))
console.Message(ctx, fmt.Sprintf("%s_BASE_URL=xxx", strings.ToUpper(userResourceName)))
}
Loading

0 comments on commit 5081210

Please sign in to comment.