Skip to content

Commit 8589bbf

Browse files
committed
feat: update workflow
1 parent fcfbc83 commit 8589bbf

File tree

4 files changed

+209
-154
lines changed

4 files changed

+209
-154
lines changed

.github/workflows/check.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Code Linting
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- dev
8+
workflow_dispatch:
9+
10+
concurrency:
11+
group: check-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
env:
15+
GO_VERSION: 1.21
16+
17+
jobs:
18+
lint:
19+
name: Code Linting
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
25+
- name: Setup Go
26+
uses: actions/setup-go@v5
27+
with:
28+
go-version: ${{ env.GO_VERSION }}
29+
30+
- name: Cache Go modules
31+
uses: actions/cache@v3
32+
with:
33+
path: |
34+
~/.cache/go-build
35+
~/go/pkg/mod
36+
key: ${{ runner.os }}-${{ github.ref_name }}-go-${{ hashFiles('**/go.sum') }}
37+
restore-keys: |
38+
${{ runner.os }}-${{ github.ref_name }}-go-
39+
40+
- name: Install revive
41+
run: go install github.com/mgechev/revive@latest
42+
43+
- name: Run revive
44+
run: revive -config revive.toml -formatter friendly ./...

.github/workflows/deploy.yaml

Lines changed: 7 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,13 @@ on:
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

169
concurrency:
1710
group: deploy-${{ github.ref }}
1811
cancel-in-progress: true
1912

2013
env:
2114
TERRAFORM_VERSION: 1.6.3
22-
GOOSE_VERSION: 3.26.0
23-
GO_VERSION: 1.21
2415
APP_CONFIG_PATH: config.json
2516

2617
jobs:
@@ -30,7 +21,6 @@ jobs:
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
@@ -41,10 +31,8 @@ jobs:
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
@@ -197,7 +85,7 @@ jobs:
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

.github/workflows/hook.yaml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Setup Telegram Webhooks
2+
3+
on:
4+
workflow_dispatch:
5+
6+
concurrency:
7+
group: hook-${{ github.ref }}
8+
cancel-in-progress: true
9+
10+
env:
11+
TERRAFORM_VERSION: 1.6.3
12+
APP_CONFIG_PATH: config.json
13+
14+
jobs:
15+
hook:
16+
name: Setup Telegram Webhooks
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: Determine workspace
23+
run: |
24+
WORKSPACE=${{ github.ref == 'refs/heads/main' && 'prod' || 'dev' }}
25+
echo "WORKSPACE=$WORKSPACE" >> $GITHUB_ENV
26+
echo "::notice::Workspace: $WORKSPACE"
27+
28+
- name: Set cache key
29+
id: set-cache-key
30+
run: |
31+
CACHE_KEY="${{ runner.os }}-${{ github.ref_name }}-terraform-${{ hashFiles('**/.terraform.lock.hcl') }}"
32+
echo "cache_key=$CACHE_KEY" >> $GITHUB_OUTPUT
33+
34+
- name: Setup Terraform Environment
35+
uses: ./.github/actions/setup-terraform
36+
with:
37+
terraform_version: ${{ env.TERRAFORM_VERSION }}
38+
terraform_wrapper: 'false'
39+
service_account_key: ${{ secrets.SERVICE_ACCOUNT_KEY }}
40+
app_config: ${{ secrets.APP_CONFIG }}
41+
app_config_path: ${{ env.APP_CONFIG_PATH }}
42+
workspace: ${{ env.WORKSPACE }}
43+
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
44+
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
45+
cache_key: ${{ steps.set-cache-key.outputs.cache_key }}
46+
47+
- name: Get Dispatcher Function ID
48+
id: get-fn-id
49+
run: |
50+
DISPATCHER_FUNCTION_ID=$(terraform output -raw dispatcher_function_id)
51+
echo "dispatcher_function_id=$DISPATCHER_FUNCTION_ID" >> $GITHUB_OUTPUT
52+
echo "::notice::Dispatcher Function ID: $DISPATCHER_FUNCTION_ID"
53+
54+
- name: Execute webhook setup script
55+
env:
56+
DISPATCHER_FUNCTION_ID: ${{ steps.get-fn-id.outputs.dispatcher_function_id }}
57+
run: |
58+
echo "::notice::Config file: $APP_CONFIG_PATH"
59+
echo "::notice::Dispatcher function ID: $DISPATCHER_FUNCTION_ID"
60+
61+
chmod +x _scripts/hook.sh
62+
bash _scripts/hook.sh
63+
continue-on-error: false
64+
65+
- name: Verify webhook setup
66+
run: |
67+
echo "::notice::Webhook setup completed successfully for $WORKSPACE environment"
68+
69+
- name: Generate summary
70+
if: always()
71+
run: |
72+
echo "## Webhook Setup Summary - $WORKSPACE environment" >> $GITHUB_STEP_SUMMARY
73+
echo "" >> $GITHUB_STEP_SUMMARY
74+
echo "**Branch:** ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
75+
echo "**Workspace:** $WORKSPACE" >> $GITHUB_STEP_SUMMARY
76+
echo "**Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
77+
echo "**Dispatcher Function ID:** ${{ steps.get-fn-id.outputs.dispatcher_function_id }}" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)