55 branches :
66 - main
77 - dev
8- workflow_dispatch :
9- inputs :
10- run_hook :
11- description : ' Run webhook setup'
12- required : false
13- type : boolean
14- default : false
158
169concurrency :
1710 group : deploy-${{ github.ref }}
1811 cancel-in-progress : true
1912
2013env :
2114 TERRAFORM_VERSION : 1.6.3
22- GOOSE_VERSION : 3.26.0
23- GO_VERSION : 1.21
2415 APP_CONFIG_PATH : config.json
2516
2617jobs :
3021 environment : ${{ github.ref == 'refs/heads/main' && 'prod' || 'dev' }}
3122 outputs :
3223 workspace : ${{ steps.set-workspace.outputs.workspace }}
33- environment : ${{ steps.set-workspace.outputs.environment }}
3424 cache_key : ${{ steps.set-cache-key.outputs.cache_key }}
3525 steps :
3626 - name : Checkout code
4131 run : |
4232 if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
4333 echo "workspace=prod" >> $GITHUB_OUTPUT
44- echo "environment=prod" >> $GITHUB_OUTPUT
4534 elif [[ "${{ github.ref }}" == "refs/heads/dev" ]]; then
4635 echo "workspace=dev" >> $GITHUB_OUTPUT
47- echo "environment=dev" >> $GITHUB_OUTPUT
4836 fi
4937
5038 - name : Set cache key
@@ -66,106 +54,6 @@ jobs:
6654 aws_secret_access_key : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
6755 cache_key : ${{ steps.set-cache-key.outputs.cache_key }}
6856
69- lint :
70- name : Code Linting
71- runs-on : ubuntu-latest
72- steps :
73- - name : Checkout code
74- uses : actions/checkout@v4
75-
76- - name : Setup Go
77- uses : actions/setup-go@v5
78- with :
79- go-version : ${{ env.GO_VERSION }}
80-
81- - name : Cache Go modules
82- uses : actions/cache@v3
83- with :
84- path : |
85- ~/.cache/go-build
86- ~/go/pkg/mod
87- key : ${{ runner.os }}-${{ github.ref_name }}-go-${{ hashFiles('**/go.sum') }}
88- restore-keys : |
89- ${{ runner.os }}-${{ github.ref_name }}-go-
90-
91- - name : Install revive
92- run : go install github.com/mgechev/revive@latest
93-
94- - name : Run revive - loader
95- run : |
96- cd serverless/loader
97- revive -config ../../revive.toml -formatter friendly ./...
98-
99- - name : Run revive - dispatcher
100- run : |
101- cd serverless/dispatcher
102- revive -config ../../revive.toml -formatter friendly ./...
103-
104- - name : Run revive - reminder
105- run : |
106- cd serverless/reminder
107- revive -config ../../revive.toml -formatter friendly ./...
108-
109- migrate :
110- name : Database Migration
111- runs-on : ubuntu-latest
112- needs : [setup, lint]
113- environment : ${{ github.ref == 'refs/heads/main' && 'prod' || 'dev' }}
114- steps :
115- - name : Checkout code
116- uses : actions/checkout@v4
117-
118- - name : Install YC CLI
119- run : |
120- curl -sSL https://storage.yandexcloud.net/yandexcloud-yc/install.sh | bash
121- echo "${HOME}/yandex-cloud/bin" >> $GITHUB_PATH
122-
123- - name : Authenticate YC CLI
124- env :
125- YC_SERVICE_ACCOUNT_KEY : ${{ secrets.SERVICE_ACCOUNT_KEY }}
126- YC_CLOUD_ID : ${{ secrets.CLOUD_ID }}
127- YC_FOLDER_ID : ${{ secrets.FOLDER_ID }}
128- run : |
129- echo "$YC_SERVICE_ACCOUNT_KEY" > iam.json
130- yc config set service-account-key iam.json
131- yc config set cloud-id "$YC_CLOUD_ID"
132- yc config set folder-id "$YC_FOLDER_ID"
133-
134- - name : Generate short-lived IAM token
135- run : |
136- export YDB_ACCESS_TOKEN_CREDENTIALS=$(yc iam create-token)
137- echo "YDB_ACCESS_TOKEN_CREDENTIALS=$YDB_ACCESS_TOKEN_CREDENTIALS" >> $GITHUB_ENV
138-
139- - name : Install Goose
140- run : |
141- GOOSE_VERSION="${{ env.GOOSE_VERSION }}"
142- wget -q "https://github.com/pressly/goose/releases/download/v${GOOSE_VERSION}/goose_linux_x86_64" -O goose
143- chmod +x goose
144- mkdir -p $HOME/.goose
145- mv goose $HOME/.goose/
146- echo "$HOME/.goose" >> $GITHUB_PATH
147-
148- - name : Run Goose migrations
149- env :
150- GOOSE_DRIVER : ydb
151- # ydb connection string format
152- # grpcs://<endpoint>:<port>/?database=<database>&go_query_mode=scripting&go_fake_tx=scripting&go_query_bind=declare,numeric
153- GOOSE_DBSTRING : ${{ secrets.DB_CONNECTION_STRING }}
154- run : |
155- export PATH="$HOME/.goose:$PATH"
156- cd migrations
157-
158- # Ensure DB string uses TLS (grpcs://)
159- if ! echo "$GOOSE_DBSTRING" | grep -q "^grpcs://"; then
160- echo "::error::DB_CONNECTION_STRING must start with grpcs:// (secure)"
161- exit 1
162- fi
163-
164- echo "::notice::Running Goose migrations on $GOOSE_DBSTRING"
165- goose up
166- echo "::notice::Migration completed successfully for ${{ needs.setup.outputs.workspace }} environment"
167- continue-on-error : true
168-
16957 validate :
17058 name : Terraform Validate
17159 runs-on : ubuntu-latest
19785 plan :
19886 name : Terraform Plan
19987 runs-on : ubuntu-latest
200- needs : [setup, lint, validate]
88+ needs : [setup, validate]
20189 environment : ${{ github.ref == 'refs/heads/main' && 'prod' || 'dev' }}
20290 outputs :
20391 plan-exists : ${{ steps.plan.outputs.exitcode }}
@@ -226,6 +114,9 @@ jobs:
226114 terraform plan -out=tfplan -detailed-exitcode || EXIT_CODE=$?
227115 echo "exitcode=$EXIT_CODE" >> $GITHUB_OUTPUT
228116
117+ # Print the plan output
118+ terraform show tfplan
119+
229120 if [ $EXIT_CODE -eq 2 ]; then
230121 echo "::notice::Changes detected in Terraform plan"
231122 elif [ $EXIT_CODE -eq 0 ]; then
@@ -238,8 +129,7 @@ jobs:
238129 apply :
239130 name : Terraform Apply
240131 runs-on : ubuntu-latest
241- needs : [setup, plan, migrate]
242- if : always() && needs.plan.result == 'success' && (needs.migrate.result == 'success' || needs.migrate.result == 'skipped')
132+ needs : [setup, plan]
243133 environment : ${{ github.ref == 'refs/heads/main' && 'prod' || 'dev' }}
244134 outputs :
245135 dispatcher_fn_id : ${{ steps.outputs.outputs.dispatcher_fn_id }}
@@ -280,12 +170,7 @@ jobs:
280170 env :
281171 TF_VAR_cloud_id : ${{ secrets.CLOUD_ID }}
282172 TF_VAR_folder_id : ${{ secrets.FOLDER_ID }}
283- run : |
284- if [ -f tfplan ]; then
285- terraform apply -auto-approve
286- else
287- echo "No changes to apply"
288- fi
173+ run : terraform apply -auto-approve
289174
290175 - name : Export Terraform Outputs
291176 id : outputs
@@ -294,35 +179,10 @@ jobs:
294179 echo "dispatcher_fn_id=$DISPATCHER_FN_ID" >> $GITHUB_OUTPUT
295180 echo "::notice::Dispatcher Function ID: $DISPATCHER_FN_ID"
296181
297- hook :
298- name : Setup Telegram Webhooks
299- runs-on : ubuntu-latest
300- needs : [apply]
301- if : github.event_name == 'workflow_dispatch' && github.event.inputs.run_hook == 'true' && needs.apply.result == 'success'
302- environment : ${{ github.ref == 'refs/heads/main' && 'prod' || 'dev' }}
303- steps :
304- - name : Checkout code
305- uses : actions/checkout@v4
306-
307- - name : Execute webhook setup script
308- env :
309- DISPATCHER_FUNCTION_ID : ${{ needs.apply.outputs.dispatcher_fn_id }}
310- run : |
311- echo "::notice::Config file: $APP_CONFIG_PATH"
312- echo "::notice::Dispatcher function ID: $DISPATCHER_FUNCTION_ID"
313-
314- chmod +x _scripts/hook.sh
315- bash _scripts/hook.sh
316- continue-on-error : false
317-
318- - name : Verify webhook setup
319- run : |
320- echo "::notice::Webhook setup completed successfully for ${{ needs.setup.outputs.workspace }} environment"
321-
322182 summary :
323183 name : Deployment Summary
324184 runs-on : ubuntu-latest
325- needs : [setup, validate, lint, migrate, plan, apply, hook ]
185+ needs : [setup, validate, plan, apply]
326186 if : always()
327187 steps :
328188 - name : Generate summary
@@ -332,11 +192,8 @@ jobs:
332192 echo "| Job | Status |" >> $GITHUB_STEP_SUMMARY
333193 echo "|-----|--------|" >> $GITHUB_STEP_SUMMARY
334194 echo "| Validate | ${{ needs.validate.result }} |" >> $GITHUB_STEP_SUMMARY
335- echo "| Code Linting | ${{ needs.lint.result }} |" >> $GITHUB_STEP_SUMMARY
336- echo "| Database Migration | ${{ needs.migrate.result }} |" >> $GITHUB_STEP_SUMMARY
337195 echo "| Terraform Plan | ${{ needs.plan.result }} |" >> $GITHUB_STEP_SUMMARY
338196 echo "| Terraform Apply | ${{ needs.apply.result }} |" >> $GITHUB_STEP_SUMMARY
339- echo "| Webhook Setup | ${{ needs.hook.result }} |" >> $GITHUB_STEP_SUMMARY
340197 echo "" >> $GITHUB_STEP_SUMMARY
341198 echo "**Branch:** ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
342199 echo "**Workspace:** ${{ needs.setup.outputs.workspace }}" >> $GITHUB_STEP_SUMMARY
@@ -345,8 +202,4 @@ jobs:
345202
346203 if [ "${{ needs.apply.outputs.dispatcher_fn_id }}" != "" ]; then
347204 echo "**Dispatcher Function ID:** ${{ needs.apply.outputs.dispatcher_fn_id }}" >> $GITHUB_STEP_SUMMARY
348- fi
349-
350- if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
351- echo "**Manual Trigger:** Webhook setup requested: ${{ github.event.inputs.run_hook }}" >> $GITHUB_STEP_SUMMARY
352205 fi
0 commit comments