-
Notifications
You must be signed in to change notification settings - Fork 0
177 lines (146 loc) · 4.29 KB
/
workflow.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
name: workflow
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
check-server:
name: check server
runs-on: ubuntu-latest
env:
PACKAGE_BASE_PATH: "${{ github.workspace }}/pkg"
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version-file: ./pkg/go.mod
cache-dependency-path: ./pkg/go.sum
cache: true
- name: Test code
run: make ci-test
- name: Upload test log
uses: actions/upload-artifact@v3
if: always()
with:
name: test-log
path: /tmp/gotest.log
if-no-files-found: error
check-front:
name: check front
runs-on: ubuntu-latest
defaults:
run:
working-directory: front
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18.x
- run: npm ci
- run: npm run build
- uses: actions/upload-artifact@v3
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
permissions:
pull-requests: write
needs:
- check-server
- check-front
env:
TF_VERSION: "1.4.6"
defaults:
run:
working-directory: deploy
steps:
- uses: actions/checkout@v3
# Go
- uses: actions/setup-go@v3
with:
go-version-file: ./pkg/go.mod
cache-dependency-path: ./pkg/go.sum
cache: true
- run: make build before-deploy
working-directory: .
# GCP
- id: "auth"
uses: "google-github-actions/auth@v0"
with:
credentials_json: "${{ secrets.GCP_CREDENTIALS }}"
- uses: "google-github-actions/setup-gcloud@v0"
with:
project_id: haraiai
export_default_credentials: true
- run: "gcloud info"
# Terraform
- uses: hashicorp/setup-terraform@v2
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@v3
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 }}