-
Notifications
You must be signed in to change notification settings - Fork 16
167 lines (140 loc) · 5.46 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
#
# This workflow will perform a clean install of the node dependencies, build the
# source code and run tests on different versions of node.
#
# When we push changes to the dev branch, it will push the changes to the
# development environment. When we push to a pull request, a short-lived preview
# is generated.
#
# No automatic deployment to the master branch and production environment, this
# has to be done manually via GitHub actions executing this workflow
#
name: CI
on:
push:
branches:
- master
- dev
pull_request:
workflow_dispatch:
jobs:
build:
name: CI
runs-on: ubuntu-22.04
strategy:
matrix:
node-version: [18.x]
steps:
# Setup
- name: Checkout code
uses: actions/checkout@v3
- name: Get the environment to deploy to
id: get-environment
env:
GITHUB_EVENT_NAME: ${{ github.event_name }}
run: |
set -eu
# Default values
FIREBASE_DEPLOY="false"
FIREBASE_SERVICE_ACCOUNT_SECRET="FIREBASE_SERVICE_ACCOUNT_DEV"
# Firebase channel ID
# The ID of the channel to deploy to. If you leave this blank, a preview
# channel and its ID will be auto-generated per branch or PR. If you set
# it to live, the action deploys to the live channel of your default
# Hosting site.
# https://github.com/marketplace/actions/deploy-to-firebase-hosting#channelid-string
case "${GITHUB_EVENT_NAME}" in
# Automatically deploy pull request changes to a short-lived preview
pull_request)
EVENT="Deploy to a short-live preview"
FIREBASE_DEPLOY="true"
FIREBASE_CHANNEL_ID=""
GCP_PROJECT="cartodb-fb-storybook-react-dev"
;;
# Automatically deploy to the development environment when pushing
# changes to the dev branch
push)
if [[ "${GITHUB_REF_NAME}" == "dev" ]]; then
EVENT="Automatically deploy to the development environment"
FIREBASE_DEPLOY="true"
FIREBASE_CHANNEL_ID="live"
GCP_PROJECT="cartodb-fb-storybook-react-dev"
elif [[ "${GITHUB_REF_NAME}" == "master" ]]; then
EVENT="Pushing to master, no deploy required"
fi
;;
# Manually deploy to the production environment the changes from the
# master branch
workflow_dispatch)
EVENT="Manually deploy to the production environment"
FIREBASE_DEPLOY="true"
FIREBASE_CHANNEL_ID="live"
FIREBASE_SERVICE_ACCOUNT_SECRET="FIREBASE_SERVICE_ACCOUNT"
GCP_PROJECT="cartodb-fb-storybook-react"
;;
*)
echo "Unknown event ${GITHUB_EVENT_NAME}"
exit 1
;;
esac
echo "Event type: ${EVENT}"
echo "Deploy to Firebase?: ${FIREBASE_DEPLOY}"
echo "firebase-deploy=${FIREBASE_DEPLOY}" >> $GITHUB_OUTPUT
if [[ "${FIREBASE_DEPLOY}" == "true" ]]; then
echo "Branch: ${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}}"
echo "Google project: ${GCP_PROJECT}"
echo "firebase-channel-id=${FIREBASE_CHANNEL_ID}" >> $GITHUB_OUTPUT
echo "firebase-service-account-secret=${FIREBASE_SERVICE_ACCOUNT_SECRET}" >> $GITHUB_OUTPUT
echo "gcp-project=${GCP_PROJECT}" >> $GITHUB_OUTPUT
else
echo "Skipping deployment"
fi
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
# Configure private registry
- name: Configure private registry
run: npm set //npm.pkg.github.com/:_authToken ${{ secrets.GITHUB_TOKEN }}
# Install dependencies, lint, build and test
- name: Install dependencies
run: yarn
- name: Lint
run: yarn lint
- name: Build
run: yarn build
- name: Coverage
run: yarn test:coverage
# Coveralls
- name: Coveralls
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
env:
CI: true
# Firebase
- name: Build storybook
if: steps.get-environment.outputs.firebase-deploy == 'true'
run: yarn storybook:build
- name: Setup Firebase for deploying
if: steps.get-environment.outputs.firebase-deploy == 'true'
working-directory: packages/react-ui
env:
GCP_PROJECT: ${{ steps.get-environment.outputs.gcp-project }}
run: |
set -eu
npm install -g firebase-tools
# Generate the necessary .firebaserc
firebase \
--project ${GCP_PROJECT} \
--config firebase.json target:apply hosting default ${GCP_PROJECT}
- name: Deploy assets to Firebase
if: steps.get-environment.outputs.firebase-deploy == 'true'
uses: FirebaseExtended/action-hosting-deploy@v0
with:
firebaseServiceAccount: ${{ secrets[format('{0}', steps.get-environment.outputs.firebase-service-account-secret)] }}
target: default
entryPoint: packages/react-ui
channelId: ${{ steps.get-environment.outputs.firebase-channel-id }}
projectId: ${{ steps.get-environment.outputs.gcp-project }}
repoToken: ${{ secrets.GITHUB_TOKEN }}