forked from element-hq/element-web
-
Notifications
You must be signed in to change notification settings - Fork 0
191 lines (171 loc) · 7.88 KB
/
build.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
189
190
191
name: Build
on:
pull_request: {}
push:
branches: [release, master]
merge_group:
types: [checks_requested]
# develop pushes and repository_dispatch handled in build_develop.yaml
env:
# These must be set for fetchdep.sh to get the right branch
REPOSITORY: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
GH_COMMIT_SHA: ${{ github.sha }}
permissions: {} # No permissions required
jobs:
build:
name: "Build on ${{ matrix.image }}"
# We build on all 3 platforms to ensure we don't have any OS-specific build incompatibilities
strategy:
fail-fast: false
matrix:
image:
- ubuntu-24.04
# - windows-2022
# - macos-14
isDevelop:
- ${{ github.event_name == 'push' && github.ref_name == 'develop' }}
# Skip the ubuntu-24.04 build for the develop branch as the dedicated CD build_develop workflow handles that
exclude:
- isDevelop: true
image: ubuntu-24.04
runs-on: ${{ matrix.image }}
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
# When a release commit is pushed to master, manage the release branch
- name: Check commit message and run release script
env:
GH_TOKEN: ${{ secrets.GH_RELEASE_TOKEN }}
if: >
github.event_name == 'push' &&
github.ref_name == 'master' &&
startsWith(github.event.head_commit.message, 'chore(release): prepare for v')
run: |
chmod +x ./scripts/branch-release.sh
./scripts/branch-release.sh
exit 0
- uses: actions/setup-node@v4
with:
cache: "yarn"
node-version: "lts/*"
# Workaround for yarn install timeouts, especially on Windows
- run: yarn config set network-timeout 300000
# For pull requests, and when pushing to master, create a dev build
- name: Switch to dev environment
if: |
github.event_name == 'push' && github.ref_name == 'master' ||
github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'master'
run: |
chmod +x ./scripts/dev-env.sh
./scripts/dev-env.sh
- name: Install Dependencies
run: "./scripts/layered.sh"
# - name: Build
# run: "yarn build"
# Build step from develop workflow
- name: Build and Package
run: "./scripts/ci_package.sh"
- run: mv dist/elecord-*.tar.gz dist/elecord.tar.gz
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: webapp
path: dist/elecord.tar.gz
deploy:
needs: build
name: Deploy webapp
runs-on: ubuntu-24.04
permissions:
pull-requests: write
steps:
# Download and extract the build folder
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: webapp
path: .
- name: Extract tarball
run: tar -xvzf elecord.tar.gz
- name: Move to dist
run: mv elecord-*/ dist
# Set the Cloudflare pages branch name
# - PR to master : test
# - Push to master : dev
# - PR to release : preview
# - Push to release : release (Production environment)
- name: Set Pages branch
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
if [[ "${{ github.event.pull_request.base.ref }}" == "master" ]]; then
echo "cf_branch=test" >> $GITHUB_ENV
elif [[ "${{ github.event.pull_request.base.ref }}" == "release" ]]; then
echo "cf_branch=preview" >> $GITHUB_ENV
echo "cf_domain=https://preview.elecord.app / " >> $GITHUB_ENV
fi
elif [[ "${{ github.event_name }}" == "push" ]]; then
if [[ "${{ github.ref_name }}" == "master" ]]; then
echo "cf_branch=dev" >> $GITHUB_ENV
echo "cf_domain=https://dev.elecord.app / " >> $GITHUB_ENV
elif [[ "${{ github.ref_name }}" == "release" ]]; then
echo "cf_branch=release" >> $GITHUB_ENV
echo "cf_domain=https://web.elecord.app / " >> $GITHUB_ENV
fi
fi
# Deploy to Cloudflare Pages (using wrangler)
- name: Deploy to Cloudflare Pages
id: cf
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_PAGES_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy dist --project-name=elecord-web --branch=${{ env.cf_branch }}
# Update PR status comment with deployment URL
- name: Update status comment (Failure)
if: ${{ github.event_name == 'pull_request' && failure() }}
uses: thollander/actions-comment-pull-request@v3
with:
message: |
## Cloudflare Pages deployment
| **Latest commit** | <code>${{ github.event.pull_request.head.sha || github.sha }}</code> |
|-------------------|:-:|
| **Status** | ❌ Failure. Check workflow logs for details |
| **Preview URL** | Not available |
pr-number: ${{ github.event.pull_request.number }}
comment-tag: CFPages-deployment
reactions: -1
mode: recreate
- name: Update status comment (Success)
if: ${{ github.event_name == 'pull_request' && success() }}
uses: thollander/actions-comment-pull-request@v3
with:
message: |
## Cloudflare Pages deployment
| **Latest commit** | <code>${{ github.event.pull_request.head.sha || github.sha }}</code> |
|-------------------|:-:|
| **Status** | ✅ Deployed! |
| **URL** | ${{ env.cf_domain }}${{ steps.cf.outputs.deployment-url != '' && steps.cf.outputs.deployment-url || 'Not available' }} |
pr-number: ${{ github.event.pull_request.number }}
comment-tag: CFPages-deployment
reactions: rocket
mode: recreate
- name: Add URL to summary
if: ${{ steps.cf.outputs.deployment-url != '' }}
run: |
echo "${{ env.cf_domain }}${{ steps.cf.outputs.deployment-url }}" >> $GITHUB_STEP_SUMMARY
- name: Draft GitHub release
uses: softprops/action-gh-release@v2
env:
GH_TOKEN: ${{ secrets.GH_RELEASE_TOKEN }}
if: >
github.event_name == 'push' &&
github.ref_name == 'release' &&
startsWith(github.event.head_commit.message, 'chore(release): prepare for v')
with:
token: $GH_TOKEN
draft: true
files: webapp
body_path: LATEST.md