Skip to content

Commit 996b1b8

Browse files
authored
Merge pull request #371 from GoogleCloudPlatform/issue369
bug: fix cloud deploy variables
2 parents a9c76c7 + cc250ff commit 996b1b8

File tree

9 files changed

+310
-78
lines changed

9 files changed

+310
-78
lines changed

internal/client/integrations/integrations.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,11 +955,13 @@ func GetVersion(name string, userLabel string, snapshot string) (version string,
955955
if err != nil {
956956
return "", err
957957
}
958-
} else {
958+
} else if snapshot != "" {
959959
integrationBody, err = GetBySnapshot(name, snapshot, true, false, false)
960960
if err != nil {
961961
return "", err
962962
}
963+
} else {
964+
return "", fmt.Errorf("userLabel or snapshot must be passed")
963965
}
964966
apiclient.ClientPrintHttpResponse.Set(true)
965967
return GetIntegrationVersion(integrationBody)

internal/cmd/integrations/apply.go

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,41 @@ var ApplyCmd = &cobra.Command{
4545
Args: func(cmd *cobra.Command, args []string) (err error) {
4646
cmdProject := cmd.Flag("proj")
4747
cmdRegion := cmd.Flag("reg")
48+
cloudDeploy, _ := strconv.ParseBool(utils.GetStringParam(cmd.Flag("cloud-deploy")))
4849

49-
if err = apiclient.SetRegion(utils.GetStringParam(cmdRegion)); err != nil {
50-
return err
51-
}
5250
cmd.Flags().VisitAll(func(f *pflag.Flag) {
5351
clilog.Debug.Printf("%s: %s\n", f.Name, f.Value)
5452
})
53+
54+
if !cloudDeploy && folder == "" {
55+
return fmt.Errorf("either --folder or --cloud-deploy must be set")
56+
}
57+
58+
if err = apiclient.SetRegion(utils.GetStringParam(cmdRegion)); err != nil {
59+
return err
60+
}
61+
5562
return apiclient.SetProjectID(utils.GetStringParam(cmdProject))
5663
},
5764
RunE: func(cmd *cobra.Command, args []string) (err error) {
5865
cmd.SilenceUsage = true
5966

6067
var skaffoldConfigUri string
6168

62-
if folder == "" {
69+
cloudDeploy, _ := strconv.ParseBool(utils.GetStringParam(cmd.Flag("cloud-deploy")))
70+
createSecret, _ := strconv.ParseBool(utils.GetStringParam(cmd.Flag("create-secret")))
71+
grantPermission, _ := strconv.ParseBool(utils.GetStringParam(cmd.Flag("grant-permission")))
72+
userLabel := utils.GetStringParam(cmd.Flag("user-label"))
73+
wait, _ := strconv.ParseBool(utils.GetStringParam(cmd.Flag("wait")))
74+
runTests, _ := strconv.ParseBool(utils.GetStringParam(cmd.Flag("run-tests")))
75+
76+
apiclient.DisableCmdPrintHttpResponse()
77+
78+
if cloudDeploy {
79+
if err = storeCloudDeployVariables(); err != nil {
80+
return err
81+
}
82+
6383
skaffoldConfigUri, err = apiclient.GetCloudDeployGCSLocations(cloudDeployProjectId, cloudDeployLocation, pipeline, release)
6484
if err != nil {
6585
return err
@@ -78,14 +98,6 @@ var ApplyCmd = &cobra.Command{
7898
return fmt.Errorf("problem with supplied path, %w", err)
7999
}
80100

81-
createSecret, _ := strconv.ParseBool(utils.GetStringParam(cmd.Flag("create-secret")))
82-
cloudDeploy, _ := strconv.ParseBool(utils.GetStringParam(cmd.Flag("cloud-deploy")))
83-
grantPermission, _ := strconv.ParseBool(utils.GetStringParam(cmd.Flag("grant-permission")))
84-
userLabel := utils.GetStringParam(cmd.Flag("user-label"))
85-
wait, _ := strconv.ParseBool(utils.GetStringParam(cmd.Flag("wait")))
86-
runTests, _ := strconv.ParseBool(utils.GetStringParam(cmd.Flag("run-tests")))
87-
88-
integrationFolder := path.Join(srcFolder, "src")
89101
testsFolder := path.Join(folder, "tests")
90102
testsConfigFolder := path.Join(folder, "test-configs")
91103
authconfigFolder := path.Join(folder, "authconfigs")
@@ -98,13 +110,7 @@ var ApplyCmd = &cobra.Command{
98110
endpointsFolder := path.Join(folder, "endpoints")
99111
zonesFolder := path.Join(folder, "zones")
100112

101-
apiclient.DisableCmdPrintHttpResponse()
102-
103-
if cloudDeploy {
104-
if err = storeCloudDeployVariables(); err != nil {
105-
return err
106-
}
107-
}
113+
integrationFolder := path.Join(srcFolder, "src")
108114

109115
if !skipAuthconfigs {
110116
if err = processAuthConfigs(authconfigFolder); err != nil {
@@ -744,13 +750,19 @@ func processTestCases(testsFolder string, integrationName string, version string
744750

745751
func storeCloudDeployVariables() (err error) {
746752
pipeline = os.Getenv("CLOUD_DEPLOY_DELIVERY_PIPELINE")
747-
release = os.Getenv("CLOUD_DEPLOY_RELEASE_NAME")
753+
release = os.Getenv("CLOUD_DEPLOY_RELEASE")
748754
outputGCSPath = os.Getenv("CLOUD_DEPLOY_OUTPUT_GCS_PATH")
749755
cloudDeployProjectId = os.Getenv("CLOUD_DEPLOY_PROJECT_ID")
750756
cloudDeployLocation = os.Getenv("CLOUD_DEPLOY_LOCATION")
751757

758+
clilog.Debug.Printf("CLOUD_DEPLOY_DELIVERY_PIPELINE: %s\n", pipeline)
759+
clilog.Debug.Printf("CLOUD_DEPLOY_RELEASE: %s\n", release)
760+
clilog.Debug.Printf("CLOUD_DEPLOY_OUTPUT_GCS_PATH: %s\n", outputGCSPath)
761+
clilog.Debug.Printf("CLOUD_DEPLOY_PROJECT_ID: %s\n", cloudDeployProjectId)
762+
clilog.Debug.Printf("CLOUD_DEPLOY_LOCATION: %s\n", cloudDeployLocation)
763+
752764
if pipeline == "" || release == "" || outputGCSPath == "" || cloudDeployProjectId == "" {
753-
return fmt.Errorf("CLOUD_DEPLOY_DELIVERY_PIPELINE, CLOUD_DEPLOY_RELEASE_NAME, CLOUD_DEPLOY_OUTPUT_GCS_PATH, " +
765+
return fmt.Errorf("CLOUD_DEPLOY_DELIVERY_PIPELINE, CLOUD_DEPLOY_RELEASE, CLOUD_DEPLOY_OUTPUT_GCS_PATH, " +
754766
"CLOUD_DEPLOY_PROJECT_ID, CLOUD_DEPLOY_LOCATION must be set")
755767
}
756768
return nil

internal/cmd/integrations/executetestcase.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"os"
2424

2525
"github.com/spf13/cobra"
26+
"github.com/spf13/pflag"
2627
)
2728

2829
// ExecuteTestCaseCmd to get integration flow
@@ -40,6 +41,10 @@ var ExecuteTestCaseCmd = &cobra.Command{
4041
inputFile := utils.GetStringParam(cmd.Flag("input-file"))
4142
inputFolder := utils.GetStringParam(cmd.Flag("input-folder"))
4243

44+
cmd.Flags().VisitAll(func(f *pflag.Flag) {
45+
clilog.Debug.Printf("%s: %s\n", f.Name, f.Value)
46+
})
47+
4348
if err = apiclient.SetRegion(cmdRegion); err != nil {
4449
return err
4550
}
@@ -76,9 +81,11 @@ var ExecuteTestCaseCmd = &cobra.Command{
7681
inputFile := utils.GetStringParam(cmd.Flag("input-file"))
7782
inputFolder := utils.GetStringParam(cmd.Flag("input-folder"))
7883

79-
version, err = integrations.GetVersion(name, userLabel, snapshot)
80-
if err != nil {
81-
return err
84+
if version == "" {
85+
version, err = integrations.GetVersion(name, userLabel, snapshot)
86+
if err != nil {
87+
return err
88+
}
8289
}
8390

8491
apiclient.EnableCmdPrintHttpResponse()
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# this github action publishes a new integration version
16+
# it also includes any overrides present in overrides.json and config-vars files.
17+
# this sample is using the example in samples/scaffold-example
18+
19+
name: apply-sample-action
20+
permissions: read-all
21+
22+
# Controls when the workflow will run
23+
on: push
24+
25+
env:
26+
ENVIRONMENT: 'dev'
27+
PROJECT_ID: ${{ vars.PROJECT_ID }}
28+
REGION: ${{ vars.REGION }}
29+
WORKLOAD_IDENTITY_PROVIDER_NAME: ${{ vars.PROVIDER_NAME }}
30+
SERVICE_ACCOUNT: ${{ vars.SERVICE_ACCOUNT }}
31+
32+
jobs:
33+
34+
integrationcli-action:
35+
36+
permissions:
37+
contents: 'read'
38+
id-token: 'write'
39+
40+
name: Apply integration version
41+
runs-on: ubuntu-latest
42+
timeout-minutes: 20
43+
44+
steps:
45+
- name: Checkout Code
46+
uses: actions/checkout@1e31de5234b9f8995739874a8ce0492dc87873e2 #v4
47+
48+
- name: Authenticate Google Cloud
49+
id: 'gcp-auth'
50+
uses: google-github-actions/auth@6fc4af4b145ae7821d527454aa9bd537d1f2dc5f #v2.1.7
51+
with:
52+
workload_identity_provider: '${{ env.WORKLOAD_IDENTITY_PROVIDER_NAME }}'
53+
service_account: '${{ env.SERVICE_ACCOUNT }}'
54+
token_format: 'access_token'
55+
56+
- name: Calculate variables
57+
id: 'calc-vars'
58+
run: |
59+
echo "SHORT_SHA=$(git rev-parse --short $GITHUB_SHA)" >> $GITHUB_OUTPUT
60+
61+
- name: Create and Publish Integration
62+
id: 'publish-integration'
63+
uses: docker://us-docker.pkg.dev/appintegration-toolkit/images/integrationcli:latest #pin to version of choice
64+
with:
65+
args: integrations apply --env=${{ env.ENVIRONMENT}} --folder=. --userlabel=${{ steps.calc-vars.outputs.SHORT_SHA }} --wait=true --proj=${{ env.PROJECT_ID }} --reg=${{ env.REGION }} --token ${{ steps.gcp-auth.outputs.access_token }}
Lines changed: 35 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,70 @@
11
{
2+
"name": "projects/102128743119/locations/us-west1/integrations/sample/versions/a87f7b88-73fa-4ff0-9fac-135c12a2caff/testCases/a11fcb3c-bd72-4ad2-83ea-f2c8c50b6f5c",
23
"displayName": "test1",
3-
"name": "projects/100000000000/locations/us-west1/integrations/sample/versions/f8145f7e-173c-4c1e-ad35-c6392853b628/testCases/dc4a4be5-1625-4f0b-a8c6-b81dce8f8620",
4+
"triggerId": "api_trigger/sample_API_1",
45
"testTaskConfigs": [
56
{
6-
"assertions": [
7-
{
8-
"assertionStrategy": "ASSERT_SUCCESSFUL_EXECUTION",
9-
"parameter": {
10-
"value": {}
11-
}
12-
}
13-
],
7+
"taskNumber": "1",
148
"mockConfig": {
15-
"mockStrategy": "SPECIFIC_MOCK_STRATEGY"
9+
"mockStrategy": "NO_MOCK_STRATEGY"
1610
},
1711
"task": "JsonnetMapperTask",
1812
"taskConfig": {
19-
"displayName": "Data Transformer (Preview)",
13+
"task": "JsonnetMapperTask",
14+
"taskId": "1",
2015
"nextTasks": [
2116
{
2217
"taskId": "2"
2318
}
2419
],
25-
"task": "JsonnetMapperTask",
2620
"taskExecutionStrategy": "WHEN_ALL_SUCCEED",
27-
"taskId": "1"
28-
},
29-
"taskNumber": "1"
21+
"displayName": "Data Transformer (Preview)",
22+
"position": {
23+
"x": -210,
24+
"y": 126
25+
}
26+
}
3027
},
3128
{
29+
"taskNumber": "2",
30+
"mockConfig": {
31+
"mockStrategy": "SKIP_MOCK_STRATEGY"
32+
},
3233
"assertions": [
3334
{
34-
"assertionStrategy": "ASSERT_SUCCESSFUL_EXECUTION",
35-
"parameter": {
36-
"value": {}
37-
}
35+
"assertionStrategy": "ASSERT_SUCCESSFUL_EXECUTION"
3836
}
3937
],
40-
"mockConfig": {
41-
"mockStrategy": "SPECIFIC_MOCK_STRATEGY",
42-
"parameters": [
43-
{
44-
"key": "`Task_2_responseHeader`",
45-
"value": {
46-
"stringValue": "test"
47-
}
48-
},
49-
{
50-
"key": "`Task_2_responseBody`",
51-
"value": {
52-
"stringValue": "test"
53-
}
54-
},
55-
{
56-
"key": "`Task_2_responseStatus`",
57-
"value": {
58-
"stringValue": "tesst"
59-
}
60-
}
61-
]
62-
},
6338
"task": "GenericRestV2Task",
6439
"taskConfig": {
65-
"displayName": "Call REST Endpoint",
6640
"task": "GenericRestV2Task",
41+
"taskId": "2",
6742
"taskExecutionStrategy": "WHEN_ALL_SUCCEED",
68-
"taskId": "2"
69-
},
70-
"taskNumber": "2"
43+
"displayName": "Call REST Endpoint",
44+
"position": {
45+
"x": -210,
46+
"y": 252
47+
}
48+
}
7149
}
7250
],
51+
"createTime": "2025-02-02T22:17:04.257119Z",
52+
"updateTime": "2025-02-02T22:18:32.915372Z",
7353
"triggerConfig": {
7454
"label": "API Trigger",
75-
"properties": {
76-
"Trigger name": "sample_API_1"
77-
},
7855
"startTasks": [
7956
{
8057
"taskId": "1"
8158
}
8259
],
83-
"triggerId": "api_trigger/sample_API_1",
60+
"properties": {
61+
"Trigger name": "sample_API_1"
62+
},
63+
"triggerType": "API",
8464
"triggerNumber": "1",
85-
"triggerType": "API"
86-
},
87-
"triggerId": "api_trigger/sample_API_1"
65+
"triggerId": "api_trigger/sample_API_1",
66+
"position": {
67+
"x": -210
68+
}
69+
}
8870
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"inputParameters": {}
3+
}

0 commit comments

Comments
 (0)