-
Notifications
You must be signed in to change notification settings - Fork 0
188 lines (154 loc) · 4.61 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
name: ci
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
check-server:
name: check server
runs-on: ubuntu-latest
timeout-minutes: 10
env:
PACKAGE_BASE_PATH: "${{ github.workspace }}/pkg"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: ./pkg/go.mod
cache-dependency-path: ./pkg/go.sum
cache: true
- name: Run unit tests
run: make ci-test
- name: Upload test log
uses: actions/upload-artifact@v4
if: always()
with:
name: test-log
path: /tmp/gotest.log
if-no-files-found: error
check-front:
name: check front
runs-on: ubuntu-latest
timeout-minutes: 10
defaults:
run:
working-directory: front
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: 21.7.0
- name: Build
run: npm ci && npm run build
- name: Upload dist
uses: actions/upload-artifact@v4
with:
name: front-dist-${{ github.sha }}
path: ./front/dist
if-no-files-found: error
retention-days: 1
if: github.ref == 'refs/heads/main'
release-server:
name: release server
runs-on: ubuntu-latest
timeout-minutes: 20
needs: [check-server, check-front]
permissions:
contents: read
id-token: write
pull-requests: write
env:
TF_VERSION: "1.4.6"
defaults:
run:
working-directory: deploy
steps:
- name: Checkout
uses: actions/checkout@v4
# Go
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: ./pkg/go.mod
cache-dependency-path: ./pkg/go.sum
cache: true
- run: make build before-deploy
working-directory: .
# GCP
- name: Authenticate Google Cloud
uses: google-github-actions/auth@v2
id: auth
with:
project_id: haraiai
service_account: ${{ env.GCLOUD_SERVICE_ACCOUNT }}
workload_identity_provider: ${{ env.GCLOUD_WORKFLOW_IDENTITY_PROVIDER }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
with:
version: ">= 363.0.0"
- run: gcloud info
# Terraform
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TF_VERSION }}
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
- id: init
run: terraform init
- id: validate
run: terraform validate -no-color
- id: plan
if: github.event_name == 'pull_request'
run: terraform plan -no-color -input=false
continue-on-error: true
- uses: actions/github-script@v6
if: github.event_name == 'pull_request'
env:
PLAN: "${{ steps.plan.outputs.stdout }}"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`terraform\n
${process.env.PLAN}
\`\`\`
</details>
*Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
- run: exit 1
if: steps.plan.outcome == 'failure'
- run: terraform apply -auto-approve -input=false
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
release-front:
name: release front
runs-on: ubuntu-latest
timeout-minutes: 20
if: github.ref == 'refs/heads/main'
needs: [check-server, check-front]
steps:
- uses: actions/download-artifact@v4
with:
name: front-dist-${{ github.sha }}
path: ./dist
- name: Publish to Cloudflare Pages
uses: cloudflare/pages-action@1
with:
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
projectName: haraiai
directory: ./dist
gitHubToken: ${{ secrets.GITHUB_TOKEN }}