-
Notifications
You must be signed in to change notification settings - Fork 24
146 lines (132 loc) · 4.87 KB
/
website.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
name: Website # This name is referenced in the functions.yml file under workflow_run
on:
push:
branches:
- 'main'
paths-ignore:
- 'functions/**'
pull_request:
workflow_call:
inputs:
deploy_env:
description: 'For manual deployments (prod)'
type: string
concurrency:
group: web-${{ github.ref }}
cancel-in-progress: true
jobs:
prepare-deploy:
uses: ./.github/workflows/prepare-deploy.yml
secrets: inherit
with:
wait: true
deploy_env: ${{ inputs.deploy_env }}
trigger-function-deploy:
if: github.event.action == 'opened' || github.event.action =='reopened'
uses: ./.github/workflows/functions.yml
secrets: inherit
build-web:
needs: [prepare-deploy]
runs-on: ubuntu-latest
steps:
- name: fail if URL empty
if: needs.prepare-deploy.outputs.function_URL == ''
run: |
echo "::error title=Function URL not found::Review the prepare-deploy job"
exit 1
- name: Checkout
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 #@v3.1.0
- name: only allow workflow_dispatch from main
if: ${{ github.event_name == 'workflow-dispatch' }}
env:
ref: ${{ github.ref == 'refs/heads/main' }}
run: |
if ${{ env.ref }} ; then
echo "::error title=Bad branch selected::You can only run manual workflows from the main branch"
exit 1
- name: Setup Node
uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 #@v3
with:
node-version: 18
cache: yarn
- name: Install Dependencies
run: yarn install
- name: Build
env:
GATSBY_FUNCTIONS_URL: ${{ needs.prepare-deploy.outputs.function_URL }}
SHOW_ANNOUNCEMENT_BANNER: false
run: |
yarn build
- name: Archive functions artifacts
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # @v3.1.2
with:
name: web-package
retention-days: 4
path: public/
publish-to-gcs:
needs: [build-web, prepare-deploy]
permissions:
contents: read
id-token: write
runs-on: ubuntu-latest
environment: ${{ inputs.deploy_env || 'gcloud-dev' }}
env:
bucket_url: ${{ needs.prepare-deploy.outputs.bucket_url }}
steps:
- name: download webpack
id: download
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # @v3.0.2
with:
name: web-package
path: webpack
- name: Auth gcloud
id: gauth
uses: google-github-actions/auth@ef5d53e30bbcd8d0836f4288f5e50ff3e086997d # @v1
with:
workload_identity_provider: '${{ secrets.GWIP }}'
service_account: '${{ secrets.GSA }}'
# Install gcloud, `setup-gcloud` automatically picks up authentication from `auth`.
- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v1'
- name: Create bucket
run: |
if ! gsutil ls gs://${{ env.bucket_url }} 1> /dev/null; then
gsutil mb gs://${{ env.bucket_url }}
echo "Setup bucket settings to serve the site"
gsutil iam ch allUsers:objectViewer gs://${{ env.bucket_url }}
gsutil web set -m index.html -e 404.html gs://${{ env.bucket_url }}
else
echo "Bucket ${{ env.bucket_url }} found! No need to create it"
fi
- name: push to bucket
id: push
run: gsutil -m rsync -d -c -r ${{steps.download.outputs.download-path}} gs://${{ env.bucket_url }}
outputs:
bucket_url: ${{ env.bucket_url }}
notify:
needs: publish-to-gcs
permissions:
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: PR comment with preview URL
uses: thollander/actions-comment-pull-request@v2
if: github.event_name == 'pull_request'
env:
pull_sha: ${{ github.event.pull_request.head.sha }}
with:
message: |
Deployed website in Google Cloud
URL: http://${{ needs.publish-to-gcs.outputs.bucket_url }}
Commit #: ${{ env.pull_sha }}
- run: echo "::notice title=web_url::${{ needs.publish-to-gcs.outputs.bucket_url }}"
- name: Notify prod deploy
if: inputs.deploy_env == 'production'
uses: rtCamp/action-slack-notify@12e36fc18b0689399306c2e0b3e0f2978b7f1ee7
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_MESSAGE: "Main site deployed, go to ${{ needs.publish-to-gcs.outputs.bucket_url }} to check out what's new!"
SLACK_USERNAME: 'Centrifuge GHA Bot'
SLACK_ICON: 'https://centrifuge.io/favicon.ico'
SLACK_TITLE: 'Deployment using production credentials finished'
SLACK_FOOTER: 'Automatic message from centrifuge/website repository Actions'