26
26
options :
27
27
- false
28
28
- true
29
- push :
30
- branches :
31
- - ' test/**'
29
+ # push:
30
+ # branches:
31
+ # - 'test/**'
32
32
pull_request :
33
33
34
34
schedule :
@@ -51,12 +51,11 @@ jobs:
51
51
pull-requests : write
52
52
issues : read
53
53
checks : write
54
- env : # Or as an environment variable
55
- TF_VAR_OBSERVE_CUSTOMER_ID : ${{ secrets.TF_VAR_OBSERVE_CUSTOMER_ID }}
56
- TF_VAR_OBSERVE_DATASTREAM_TOKEN : ${{ secrets.TF_VAR_OBSERVE_DATASTREAM_TOKEN }}
54
+ env :
57
55
TF_VAR_PUBLIC_KEY : ${{ secrets.TF_VAR_PUBLIC_KEY }}
58
56
TF_VAR_REGION : " us-west-2"
59
57
TF_VAR_USE_BRANCH_NAME : main
58
+
60
59
ARM_CLIENT_ID : ${{ secrets.AZURE_CLIENT_ID }}
61
60
ARM_CLIENT_SECRET : ${{ secrets.AZURE_CLIENT_SECRET }}
62
61
ARM_SUBSCRIPTION_ID : ${{ secrets.AZURE_SUBSCRIPTION_ID }}
@@ -68,86 +67,54 @@ jobs:
68
67
FAIL_FIRST_TEST : false
69
68
FAIL_SECOND_TEST : false
70
69
WORK_DIR : test_code
71
-
72
-
70
+ CLOUD : aws
71
+ MODULE : aws_machines
73
72
# TF_LOG: DEBUG
73
+
74
74
steps :
75
- - name : Value of inputs
76
- run : |
77
- echo "install_script_branch=${{ github.event.inputs.install_script_branch }}"
78
- echo "this_repo_branch=${{ github.event.inputs.this_repo_branch }}"
79
- echo "terraform_run_destroy=${{ github.event.inputs.terraform_run_destroy }}"
80
- echo "fail_first_test=${{ github.event.inputs.fail_first_test }}"
81
- echo "fail_second_test=${{ github.event.inputs.fail_second_test }}"
75
+ # AWS Login - orig role - has to occur before checkout
76
+ - name : Configure AWS Credentials
77
+ uses : aws-actions/configure-aws-credentials@v1
78
+ with :
79
+ role-to-assume : ${{ secrets.THUNDERDOME_AWS_ROLE }}
80
+ aws-region : ${{ env.TF_VAR_REGION }}
82
81
83
- - name : Set variables based on inputs
84
- if : github.event.inputs.terraform_run_destroy != ''
82
+ - name : Set code repo
85
83
run : |
86
-
87
- echo "TF_VAR_USE_BRANCH_NAME=${{ github.event.inputs.install_script_branch }}" >> $GITHUB_ENV
88
-
89
- echo "THIS_REPO_BRANCH=refs/heads/${{ github.event.inputs.this_repo_branch }}" >> $GITHUB_ENV
90
-
91
- echo "TERRAFORM_RUN_DESTROY=${{ github.event.inputs.terraform_run_destroy }}" >> $GITHUB_ENV
92
-
93
- echo "FAIL_FIRST_TEST=${{ github.event.inputs.fail_first_test }}" >> $GITHUB_ENV
84
+ if ${{ github.event.inputs.this_repo_branch != '' }}; then
85
+ echo "THIS_REPO_BRANCH=refs/heads/${{ github.event.inputs.this_repo_branch }}" >> $GITHUB_ENV
86
+ else
87
+ echo "THIS_REPO_BRANCH=refs/heads/${{ github.head_ref }}" >> $GITHUB_ENV
88
+ fi
94
89
95
- echo "FAIL_SECOND_TEST=${{ github.event.inputs.fail_second_test }}" >> $GITHUB_ENV
90
+ - name : Check out repository code
91
+ uses : actions/checkout@v3
92
+ with :
93
+ ref : ${{ env.THIS_REPO_BRANCH }}
96
94
97
- - name : Set Custom Environment Variables
95
+ - name : Set contexts
98
96
run : |
99
- # if pull request don't destroy resources
100
- if ${{ github.event_name == 'pull_request' }}; then
101
- echo "TERRAFORM_RUN_DESTROY=false" >> $GITHUB_ENV
102
- echo "THIS_REPO_BRANCH=${{ github.ref }}" >> $GITHUB_ENV
103
- fi
104
-
105
- # value for resource names
106
- echo "TF_VAR_WORKFLOW_MATRIX_VALUE=${{ matrix.test_groups }}" >> $GITHUB_ENV
107
-
108
- # This variable tells code it running on CI server
109
- echo "TF_VAR_CI=$CI" >> $GITHUB_ENV
110
-
111
- # This variable gets just the branch name without url stuff
112
- echo "GIT_HUB_SHORT_BRANCH_NAME=${GITHUB_BRANCH##*/}" >> $GITHUB_ENV
113
-
114
- # Create directory for keys and set permissions
115
- mkdir "$HOME/.ssh"
116
- chmod 700 "$HOME/.ssh"
117
- # variable for private key which is required for CI server to login to machines
118
- echo "TF_VAR_PRIVATE_KEY_PATH=$HOME/.ssh/github_actions" >> $GITHUB_ENV
119
- env :
120
- GITHUB_BRANCH : ${{ github.ref }}
97
+ mkdir context
98
+ echo '${{ toJSON(github) }}' > context/github_context.json
99
+ echo '${{ toJSON(matrix) }}' > context/matrix_context.json
100
+ echo '${{ secrets.PRIVATE_KEY }}' > context/private_key
101
+
102
+ working-directory : " ${{ env.WORK_DIR }}/python_scripts"
121
103
122
- - name : Set SSH Key
104
+ - name : workflow helper
123
105
run : |
124
- # variable for path to private key
125
- echo "${{ secrets.PRIVATE_KEY }}" > "$TF_VAR_PRIVATE_KEY_PATH"
126
- # set permissions for key file
127
- chmod 600 "$TF_VAR_PRIVATE_KEY_PATH"
128
- # display for troubleshooting
129
- cat "$TF_VAR_PRIVATE_KEY_PATH"
106
+ python3 -c "from workflow_tasks import set_custom_vars; set_custom_vars(context_dir='context')"
130
107
131
- - name : Print Environment Variables - troubleshooting
132
- run : |
133
- env | sort -f
108
+ python3 -c "from workflow_tasks import tf_override_file; tf_override_file(cloud=\"${{ env.CLOUD }}\", test_group=\"${{ matrix.test_groups }}\")"
134
109
135
- - name : Check out repository code
136
- uses : actions/checkout@v3
137
- with :
138
- ref : ${{ env.THIS_REPO_BRANCH }}
110
+ # !!! vvvvv THIS OVERWRITES MAIN.TF FILE for specific cloud module vvvvv !!!
111
+ python3 -c "from workflow_tasks import tf_main_file; tf_main_file(module=\"${{ env.MODULE }}\")"
139
112
140
- - name : Setup Terraform
141
- uses : hashicorp/setup-terraform@v2
142
- with :
143
- terraform_wrapper : false
113
+ python3 -c "from workflow_tasks import tf_output_file; tf_output_file(module=\"${{ env.MODULE }}\")"
144
114
145
- # AWS Login - orig role
146
- - name : Configure AWS Credentials
147
- uses : aws-actions/configure-aws-credentials@v1
148
- with :
149
- role-to-assume : ${{ secrets.THUNDERDOME_AWS_ROLE }}
150
- aws-region : ${{ env.TF_VAR_REGION }}
115
+ python3 -c "from workflow_tasks import config_ini; config_ini(custid=\"${{ secrets.STAGE_CUSTOMER_ID }}\", domain=\"${{ secrets.STAGE_DOMAIN }}\", token=\"${{ secrets.STAGE_DATASTREAM_TOKEN }}\")"
116
+
117
+ working-directory : " ${{ env.WORK_DIR }}/python_scripts"
151
118
152
119
# GCP Login
153
120
# This is key generated in GCP console for service account
@@ -161,33 +128,21 @@ jobs:
161
128
with :
162
129
project_id : ${{ secrets.GCP_PROJECT_ID }}
163
130
164
- - name : ' Test gcloud CLI'
165
- run : ' gcloud info'
166
-
167
- - name : terraform and config files
131
+ - name : Print Environment Variables - troubleshooting
168
132
run : |
169
- python3 -c "from workflow_tasks import tf_override_file; tf_override_file(cloud=\"aws\", test_group=\"${{ matrix.test_groups }}\")"
170
-
171
- python3 -c "from workflow_tasks import tf_main_file; tf_main_file(module=\"aws_machines\")"
172
-
173
- python3 -c "from workflow_tasks import tf_output_file; tf_output_file(module=\"aws_machines\")"
174
-
175
- python3 -c "from workflow_tasks import config_ini; config_ini(custid=\"${{ secrets.STAGE_CUSTOMER_ID }}\", domain=\"${{ secrets.STAGE_DOMAIN }}\", token=\"${{ secrets.STAGE_DATASTREAM_TOKEN }}\")"
133
+ env | sort -f
176
134
177
- working-directory : " ${{ env.WORK_DIR }}/python_scripts"
135
+ - name : Setup Terraform
136
+ uses : hashicorp/setup-terraform@v2
137
+ with :
138
+ terraform_wrapper : false
178
139
179
- - name : terraform version
140
+ - name : terraform tasks
180
141
run : |
181
142
terraform version
182
- working-directory : " ${{ env.WORK_DIR }}"
183
143
184
- - name : terraform init
185
- run : |
186
144
terraform init
187
- working-directory : " ${{ env.WORK_DIR }}"
188
145
189
- - name : terraform validate
190
- run : |
191
146
terraform validate
192
147
working-directory : " ${{ env.WORK_DIR }}"
193
148
@@ -197,7 +152,7 @@ jobs:
197
152
working-directory : " ${{ env.WORK_DIR }}"
198
153
199
154
# Run tests
200
- - name : python script
155
+ - name : run fabric tests python script
201
156
run : |
202
157
# create output directory for archive files
203
158
mkdir file_outputs
@@ -207,34 +162,27 @@ jobs:
207
162
pip3 install -r requirements.txt
208
163
209
164
# run tests
210
- fab test -a ${{ env.FAIL_FIRST_TEST }} -b ${{ env.THIS_REPO_BRANCH }}
165
+ fab test -a ${{ env.FAIL_FIRST_TEST }} -b ${{ env.THIS_REPO_BRANCH }} -o "1: run fabric tests python script"
211
166
working-directory : " ${{ env.WORK_DIR }}/python_scripts"
212
167
213
168
- name : Retry tests
214
169
if : ${{ env.TEST_RESULT == 'FAIL' }}
215
170
run : |
216
171
# run tests
217
- fab test -a ${{ env.FAIL_SECOND_TEST }} -o 2 -b ${{ env.THIS_REPO_BRANCH }}
172
+ fab test -a ${{ env.FAIL_SECOND_TEST }} -o "2: Retry tests" -b ${{ env.THIS_REPO_BRANCH }}
218
173
219
174
working-directory : " ${{ env.WORK_DIR }}/python_scripts"
220
175
221
- - name : delete ini
176
+ - name : cleanup
222
177
if : always()
223
178
run : |
224
- rm config.ini
225
- working-directory : " ${{ env.WORK_DIR }}/python_scripts"
179
+ rm -f python_scripts/config.ini
226
180
227
- - name : clean_output
228
- if : always()
229
- run : |
230
- sed -i 's/${{ secrets.STAGE_DATASTREAM_TOKEN }}/******/g' ./*
231
- working-directory : " ${{ env.WORK_DIR }}/python_scripts/file_outputs"
181
+ sed -i 's/${{ secrets.STAGE_DATASTREAM_TOKEN }}/******/g' ./python_scripts/file_outputs/*
232
182
233
- - name : clean_logs
234
- if : always()
235
- run : |
236
- sed -i 's/${{ secrets.STAGE_DATASTREAM_TOKEN }}/******/g' ./*
237
- working-directory : " ${{ env.WORK_DIR }}/python_scripts/log_outputs"
183
+ sed -i 's/${{ secrets.STAGE_DATASTREAM_TOKEN }}/******/g' ./python_scripts/log_outputs/*
184
+
185
+ working-directory : " ${{ env.WORK_DIR }}"
238
186
239
187
- name : Archive test results
240
188
uses : actions/upload-artifact@v3
0 commit comments