Skip to content

Commit ed40065

Browse files
committed
Merge remote-tracking branch 'origin/develop' into feature/SCALRCORE-26056
2 parents 6ee8fc5 + 178ddf7 commit ed40065

File tree

3 files changed

+261
-45
lines changed

3 files changed

+261
-45
lines changed

.github/workflows/pr.yml

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
name: Run go-scalr tests on pr in any other repo
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
repo:
6+
description: The repository with pull request
7+
required: true
8+
pr_id:
9+
description: The number of the pull request
10+
required: true
11+
pr_head_sha:
12+
description: The head sha of the pull request
13+
required: true
14+
pr_branch:
15+
description: Pull request branch
16+
base_branch:
17+
description: Base branch of pull request
18+
concurrency:
19+
group: ${{ github.ref }}-${{ github.workflow }}
20+
cancel-in-progress: true
21+
22+
jobs:
23+
tests:
24+
runs-on: ubuntu-latest
25+
name: tests
26+
env:
27+
SCALR_TOKEN: ${{ secrets.SCALR_TOKEN }}
28+
UPSTREAM_ID: ${{ github.run_number }}
29+
steps:
30+
- uses: actions/checkout@v3
31+
- name: Log pr link
32+
run: |
33+
echo ":taco: Pull request: https://github.com/Scalr/${{ inputs.repo }}/pull/${{ inputs.pr_id }} " >> $GITHUB_STEP_SUMMARY
34+
- name: Get current job log URL
35+
uses: Tiryoh/gha-jobid-action@v0
36+
id: get-job-id
37+
with:
38+
github_token: ${{ secrets.GITHUB_TOKEN }}
39+
job_name: ${{ github.job }}
40+
- name: Set pending status
41+
uses: actions/github-script@v3
42+
with:
43+
github-token: ${{ secrets.GH_PAT }}
44+
script: |
45+
github.repos.createCommitStatus({
46+
owner: 'Scalr',
47+
repo: '${{ inputs.repo }}',
48+
sha: '${{ inputs.pr_head_sha }}',
49+
state: 'pending',
50+
description: 'Starting go-scalr tests',
51+
context: 'go-scalr',
52+
target_url: '${{ steps.get-job-id.outputs.html_url }}',
53+
})
54+
- uses: actions/setup-go@v3
55+
with:
56+
go-version: "1.18"
57+
- name: Clone fatmouse repo
58+
uses: actions/checkout@v3
59+
with:
60+
repository: Scalr/fatmouse
61+
path: fatmouse
62+
token: ${{ secrets.GH_PAT }}
63+
- name: Set DB_BRANCH
64+
if: ${{ contains(github.event.head_commit.message, '[DB_BRANCH]') }}
65+
run: echo "DB_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
66+
- id: auth
67+
uses: google-github-actions/auth@v0
68+
with:
69+
credentials_json: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
70+
- name: Set up Cloud SDK
71+
uses: google-github-actions/setup-gcloud@v0
72+
- name: Copy secrets
73+
shell: bash
74+
run: |
75+
mkdir ~/.scalr-labs
76+
gsutil cp gs://drone_bucket/prod/private.d/.secrets.yaml fatmouse/tacobell/.secrets.yaml
77+
gsutil cp gs://drone_bucket/prod/private.d/github.json ~/.scalr-labs/github.json
78+
- name: Configure docker
79+
shell: bash
80+
run: gcloud auth configure-docker eu.gcr.io
81+
- name: Pull python builder
82+
shell: bash
83+
run: |
84+
echo "::group::Pull python builder image"
85+
docker pull eu.gcr.io/development-156220/fatmouse/python-builder:master
86+
docker tag eu.gcr.io/development-156220/fatmouse/python-builder:master fatmouse/python-builder:master
87+
echo "::endgroup::"
88+
- name: Get current job log URL
89+
uses: Tiryoh/gha-jobid-action@v0
90+
id: get-job-id
91+
with:
92+
github_token: ${{ secrets.GITHUB_TOKEN }}
93+
job_name: ${{ github.job }}
94+
- name: Generate run tag
95+
shell: bash
96+
run: |
97+
if [ ${{ github.run_attempt }} = 1 ]; then
98+
RERUN_SUFFIX=""
99+
else
100+
RERUN_SUFFIX=$(echo -${{ github.run_attempt }})
101+
fi
102+
echo "RUN_TAG=e2e-${{ github.workflow }}-${{ github.job }}-${{ github.run_number }}${RERUN_SUFFIX}" >> $GITHUB_ENV
103+
- name: Create container
104+
id: create
105+
shell: bash
106+
run: |
107+
FATMOUSE_BRANCH="--fatmouse-branch ${{ inputs.pr_branch }}"
108+
SCALR_BRANCH="--scalr-branch ${{ inputs.pr_branch }}"
109+
110+
TEV2_BRANCH=${{ inputs.pr_branch }}
111+
NORMALIZED_BRANCH=$(echo $TEV2_BRANCH | tr / - | tr '[:upper:]' '[:lower:]')
112+
if docker manifest inspect eu.gcr.io/development-156220/fatmouse/scalr-server-te:${NORMALIZED_BRANCH} ; then
113+
IMAGE="--scalr-server-image-tag ${NORMALIZED_BRANCH}"
114+
else
115+
if [[ "${{ inputs.base_branch }}" == release/* ]]; then
116+
NORMALIZED_IMAGE=$(echo "${{ inputs.base_branch }}" | tr / - | tr '[:upper:]' '[:lower:]')
117+
IMAGE="--scalr-server-image-tag ${NORMALIZED_IMAGE}"
118+
else
119+
IMAGE=""
120+
fi
121+
fi
122+
123+
docker run --rm \
124+
-e GITHUB_WORKSPACE=true \
125+
-e GITHUB_OUTPUT=/fatmouse/output \
126+
-w /fatmouse \
127+
-v $PWD/fatmouse:/fatmouse \
128+
-v $GITHUB_OUTPUT:/fatmouse/output \
129+
-v ~/.scalr-labs:/etc/scalr-labs \
130+
fatmouse/python-builder:master python -u clickfile.py te up \
131+
${FATMOUSE_BRANCH} ${SCALR_BRANCH} ${IMAGE} \
132+
--run-url ${{ steps.get-job-id.outputs.html_url }} \
133+
--skip-ui-build \
134+
--cpu=1 \
135+
--ram=2G \
136+
${{ env.RUN_TAG }}
137+
- name: Run tests
138+
id: run-tests
139+
env:
140+
SCALR_ADDRESS: ${{ steps.create.outputs.host }}
141+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
142+
TEST_AWS_ACCESS_KEY: ${{ secrets.TEST_AWS_ACCESS_KEY }}
143+
TEST_AWS_SECRET_KEY: ${{ secrets.TEST_AWS_SECRET_KEY }}
144+
TEST_AWS_ROLE_ARN: ${{ secrets.TEST_AWS_ROLE_ARN }}
145+
TEST_AWS_EXTERNAL_ID: ${{ secrets.TEST_AWS_EXTERNAL_ID }}
146+
TEST_ARM_CLIENT_ID: ${{ secrets.TEST_ARM_CLIENT_ID }}
147+
TEST_ARM_CLIENT_SECRET: ${{ secrets.TEST_ARM_CLIENT_SECRET }}
148+
TEST_ARM_TENANT_ID: ${{ secrets.TEST_ARM_TENANT_ID }}
149+
TEST_ARM_SUBSCRIPTION_ID: ${{ secrets.TEST_ARM_SUBSCRIPTION_ID }}
150+
run: make test
151+
- name: Set commit status after tests
152+
if: ${{ always() && (steps.run-tests.outcome == 'failure' || steps.run-tests.outcome == 'success') }}
153+
uses: actions/github-script@v3
154+
with:
155+
github-token: ${{ secrets.GH_PAT }}
156+
script: |
157+
github.repos.createCommitStatus({
158+
owner: 'Scalr',
159+
repo: '${{ inputs.repo }}',
160+
sha: '${{ inputs.pr_head_sha }}',
161+
state: '${{ steps.run-tests.outcome }}',
162+
description: 'go-scalr tests result: ${{ steps.run-tests.outcome }}',
163+
context: 'go-scalr',
164+
target_url: '${{ steps.get-job-id.outputs.html_url }}',
165+
})
166+
- name: Set commit status on interrupted workflow
167+
if: ${{ always() && steps.run-tests.outcome != 'failure' && steps.run-tests.outcome != 'success' }}
168+
uses: actions/github-script@v3
169+
with:
170+
github-token: ${{ secrets.GH_TOKEN }}
171+
script: |
172+
github.repos.createCommitStatus({
173+
owner: 'Scalr',
174+
repo: '${{ inputs.repo }}',
175+
sha: '${{ inputs.pr_head_sha }}',
176+
state: 'error',
177+
description: 'go-scalr workflow was interrupted',
178+
context: 'go-scalr',
179+
target_url: '${{ steps.get-job-id.outputs.html_url }}',
180+
})
181+
- name: Add comment on failed tests
182+
if: ${{ always() && steps.run-tests.outcome == 'failure' }}
183+
uses: actions/github-script@v5
184+
with:
185+
script: |
186+
const issue_number = ${{ inputs.pr_id }};
187+
const owner = 'Scalr';
188+
const repo = '${{ inputs.repo }}';
189+
const message = '**go-scalr tests failed**\nJob url ${{ steps.get-job-id.outputs.html_url }}';
190+
await github.rest.issues.createComment({owner, repo, issue_number, body: message});
191+
github-token: ${{ secrets.GH_PAT }}
192+
- name: Delete container
193+
id: delete
194+
if: ${{ always() }}
195+
shell: bash
196+
run: |
197+
docker run --rm \
198+
-w /fatmouse \
199+
-v $PWD/fatmouse:/fatmouse \
200+
-v ~/.scalr-labs:/etc/scalr-labs \
201+
fatmouse/python-builder:master \
202+
python -u clickfile.py te rm \
203+
--no-wait ${{ env.RUN_TAG }}

workspace.go

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -67,29 +67,30 @@ type WorkspaceList struct {
6767

6868
// Workspace represents a Scalr workspace.
6969
type Workspace struct {
70-
ID string `jsonapi:"primary,workspaces"`
71-
Actions *WorkspaceActions `jsonapi:"attr,actions"`
72-
AutoApply bool `jsonapi:"attr,auto-apply"`
73-
ForceLatestRun bool `jsonapi:"attr,force-latest-run"`
74-
CanQueueDestroyPlan bool `jsonapi:"attr,can-queue-destroy-plan"`
75-
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
76-
FileTriggersEnabled bool `jsonapi:"attr,file-triggers-enabled"`
77-
Locked bool `jsonapi:"attr,locked"`
78-
MigrationEnvironment string `jsonapi:"attr,migration-environment"`
79-
Name string `jsonapi:"attr,name"`
80-
Operations bool `jsonapi:"attr,operations"`
81-
ExecutionMode WorkspaceExecutionMode `jsonapi:"attr,execution-mode"`
82-
Permissions *WorkspacePermissions `jsonapi:"attr,permissions"`
83-
TerraformVersion string `jsonapi:"attr,terraform-version"`
84-
VCSRepo *WorkspaceVCSRepo `jsonapi:"attr,vcs-repo"`
85-
WorkingDirectory string `jsonapi:"attr,working-directory"`
86-
ApplySchedule string `jsonapi:"attr,apply-schedule"`
87-
DestroySchedule string `jsonapi:"attr,destroy-schedule"`
88-
HasResources bool `jsonapi:"attr,has-resources"`
89-
AutoQueueRuns WorkspaceAutoQueueRuns `jsonapi:"attr,auto-queue-runs"`
90-
Hooks *Hooks `jsonapi:"attr,hooks"`
91-
RunOperationTimeout *int `jsonapi:"attr,run-operation-timeout"`
92-
VarFiles []string `jsonapi:"attr,var-files"`
70+
ID string `jsonapi:"primary,workspaces"`
71+
Actions *WorkspaceActions `jsonapi:"attr,actions"`
72+
AutoApply bool `jsonapi:"attr,auto-apply"`
73+
ForceLatestRun bool `jsonapi:"attr,force-latest-run"`
74+
DeletionProtectionEnabled bool `jsonapi:"attr,deletion-protection-enabled"`
75+
CanQueueDestroyPlan bool `jsonapi:"attr,can-queue-destroy-plan"`
76+
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
77+
FileTriggersEnabled bool `jsonapi:"attr,file-triggers-enabled"`
78+
Locked bool `jsonapi:"attr,locked"`
79+
MigrationEnvironment string `jsonapi:"attr,migration-environment"`
80+
Name string `jsonapi:"attr,name"`
81+
Operations bool `jsonapi:"attr,operations"`
82+
ExecutionMode WorkspaceExecutionMode `jsonapi:"attr,execution-mode"`
83+
Permissions *WorkspacePermissions `jsonapi:"attr,permissions"`
84+
TerraformVersion string `jsonapi:"attr,terraform-version"`
85+
VCSRepo *WorkspaceVCSRepo `jsonapi:"attr,vcs-repo"`
86+
WorkingDirectory string `jsonapi:"attr,working-directory"`
87+
ApplySchedule string `jsonapi:"attr,apply-schedule"`
88+
DestroySchedule string `jsonapi:"attr,destroy-schedule"`
89+
HasResources bool `jsonapi:"attr,has-resources"`
90+
AutoQueueRuns WorkspaceAutoQueueRuns `jsonapi:"attr,auto-queue-runs"`
91+
Hooks *Hooks `jsonapi:"attr,hooks"`
92+
RunOperationTimeout *int `jsonapi:"attr,run-operation-timeout"`
93+
VarFiles []string `jsonapi:"attr,var-files"`
9394

9495
// Relations
9596
CurrentRun *Run `jsonapi:"relation,current-run"`
@@ -189,6 +190,9 @@ type WorkspaceCreateOptions struct {
189190
// Whether to automatically raise the priority of the latest new run.
190191
ForceLatestRun *bool `jsonapi:"attr,force-latest-run,omitempty"`
191192

193+
// Whether to prevent deletion when the workspace has resources.
194+
DeletionProtectionEnabled *bool `jsonapi:"attr,deletion-protection-enabled,omitempty"`
195+
192196
// The name of the workspace, which can only include letters, numbers, -,
193197
// and _. This will be used as an identifier and must be unique in the
194198
// environment.
@@ -360,6 +364,9 @@ type WorkspaceUpdateOptions struct {
360364
// Whether to automatically raise the priority of the latest new run.
361365
ForceLatestRun *bool `jsonapi:"attr,force-latest-run,omitempty"`
362366

367+
// Whether to prevent deletion when the workspace has resources.
368+
DeletionProtectionEnabled *bool `jsonapi:"attr,deletion-protection-enabled,omitempty"`
369+
363370
// A new name for the workspace, which can only include letters, numbers, -,
364371
// and _. This will be used as an identifier and must be unique in the
365372
// environment. Warning: Changing a workspace's name changes its URL in the

workspace_test.go

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,16 @@ func TestWorkspacesCreate(t *testing.T) {
9595

9696
t.Run("with valid options", func(t *testing.T) {
9797
options := WorkspaceCreateOptions{
98-
Environment: envTest,
99-
Name: String(randomString(t)),
100-
AutoApply: Bool(true),
101-
ForceLatestRun: Bool(true),
102-
ExecutionMode: WorkspaceExecutionModePtr(WorkspaceExecutionModeRemote),
103-
TerraformVersion: String("1.1.9"),
104-
WorkingDirectory: String("bar/"),
105-
RunOperationTimeout: Int(15),
106-
AutoQueueRuns: AutoQueueRunsModePtr(AutoQueueRunsModeNever),
98+
Environment: envTest,
99+
Name: String(randomString(t)),
100+
AutoApply: Bool(true),
101+
ForceLatestRun: Bool(true),
102+
DeletionProtectionEnabled: Bool(false),
103+
ExecutionMode: WorkspaceExecutionModePtr(WorkspaceExecutionModeRemote),
104+
TerraformVersion: String("1.1.9"),
105+
WorkingDirectory: String("bar/"),
106+
RunOperationTimeout: Int(15),
107+
AutoQueueRuns: AutoQueueRunsModePtr(AutoQueueRunsModeNever),
107108
}
108109

109110
ws, err := client.Workspaces.Create(ctx, options)
@@ -121,6 +122,7 @@ func TestWorkspacesCreate(t *testing.T) {
121122
assert.Equal(t, *options.Name, item.Name)
122123
assert.Equal(t, *options.AutoApply, item.AutoApply)
123124
assert.Equal(t, *options.ForceLatestRun, item.ForceLatestRun)
125+
assert.Equal(t, *options.DeletionProtectionEnabled, item.DeletionProtectionEnabled)
124126
assert.Equal(t, false, item.HasResources)
125127
assert.Equal(t, *options.ExecutionMode, item.ExecutionMode)
126128
assert.Equal(t, *options.TerraformVersion, item.TerraformVersion)
@@ -295,13 +297,14 @@ func TestWorkspacesUpdate(t *testing.T) {
295297

296298
t.Run("when updating a subset of values", func(t *testing.T) {
297299
options := WorkspaceUpdateOptions{
298-
Name: String(wsTest.Name),
299-
AutoApply: Bool(true),
300-
ForceLatestRun: Bool(true),
301-
ExecutionMode: WorkspaceExecutionModePtr(WorkspaceExecutionModeRemote),
302-
TerraformVersion: String("1.2.9"),
303-
RunOperationTimeout: Int(20),
304-
AutoQueueRuns: AutoQueueRunsModePtr(AutoQueueRunsModeAlways),
300+
Name: String(wsTest.Name),
301+
AutoApply: Bool(true),
302+
ForceLatestRun: Bool(true),
303+
DeletionProtectionEnabled: Bool(false),
304+
ExecutionMode: WorkspaceExecutionModePtr(WorkspaceExecutionModeRemote),
305+
TerraformVersion: String("1.2.9"),
306+
RunOperationTimeout: Int(20),
307+
AutoQueueRuns: AutoQueueRunsModePtr(AutoQueueRunsModeAlways),
305308
}
306309

307310
wsAfter, err := client.Workspaces.Update(ctx, wsTest.ID, options)
@@ -312,6 +315,7 @@ func TestWorkspacesUpdate(t *testing.T) {
312315
assert.Equal(t, *options.AutoQueueRuns, wsAfter.AutoQueueRuns)
313316
assert.NotEqual(t, wsTest.AutoApply, wsAfter.AutoApply)
314317
assert.NotEqual(t, wsTest.ForceLatestRun, wsAfter.ForceLatestRun)
318+
assert.NotEqual(t, wsTest.DeletionProtectionEnabled, wsAfter.DeletionProtectionEnabled)
315319
assert.NotEqual(t, wsTest.TerraformVersion, wsAfter.TerraformVersion)
316320
assert.Equal(t, wsTest.WorkingDirectory, wsAfter.WorkingDirectory)
317321
assert.Equal(t, int(20), *wsAfter.RunOperationTimeout)
@@ -340,12 +344,13 @@ func TestWorkspacesUpdate(t *testing.T) {
340344

341345
t.Run("with valid options", func(t *testing.T) {
342346
options := WorkspaceUpdateOptions{
343-
Name: String(randomString(t)),
344-
AutoApply: Bool(false),
345-
ForceLatestRun: Bool(false),
346-
ExecutionMode: WorkspaceExecutionModePtr(WorkspaceExecutionModeLocal),
347-
TerraformVersion: String("1.1.9"),
348-
WorkingDirectory: String("baz/"),
347+
Name: String(randomString(t)),
348+
AutoApply: Bool(false),
349+
ForceLatestRun: Bool(false),
350+
DeletionProtectionEnabled: Bool(false),
351+
ExecutionMode: WorkspaceExecutionModePtr(WorkspaceExecutionModeLocal),
352+
TerraformVersion: String("1.1.9"),
353+
WorkingDirectory: String("baz/"),
349354
}
350355

351356
w, err := client.Workspaces.Update(ctx, wsTest.ID, options)
@@ -362,6 +367,7 @@ func TestWorkspacesUpdate(t *testing.T) {
362367
assert.Equal(t, *options.Name, item.Name)
363368
assert.Equal(t, *options.AutoApply, item.AutoApply)
364369
assert.Equal(t, *options.ForceLatestRun, item.ForceLatestRun)
370+
assert.Equal(t, *options.DeletionProtectionEnabled, item.DeletionProtectionEnabled)
365371
assert.Equal(t, *options.ExecutionMode, item.ExecutionMode)
366372
assert.Equal(t, *options.TerraformVersion, item.TerraformVersion)
367373
assert.Equal(t, *options.WorkingDirectory, item.WorkingDirectory)

0 commit comments

Comments
 (0)