Skip to content

Commit 163cdcb

Browse files
authored
Merge pull request #6790 from hotosm/develop
Merge `develop` to `staging`
2 parents f18e61b + 8908197 commit 163cdcb

10 files changed

Lines changed: 494 additions & 111 deletions

File tree

.github/workflows/ecs-deploy.yml renamed to .github/workflows/backend-build-deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Deploy to Amazon ECS
1+
name: Build and Deploy Backend to ECS
22

33
on:
44
push:
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
name: Build and Deploy Frontend to Cloudfront
2+
3+
on:
4+
push:
5+
branches:
6+
- "*"
7+
paths:
8+
- "frontend/**"
9+
workflow_dispatch:
10+
11+
jobs:
12+
build:
13+
name: Build Static Files
14+
runs-on: ubuntu-latest
15+
16+
environment:
17+
name: ${{ github.ref_name == 'develop' && 'develop' || github.ref_name == 'staging' && 'staging' || github.ref_name == 'main' && 'main' || 'develop' }}
18+
url: ${{ github.ref_name == 'develop' && 'https://tasks-dev.hotosm.org' || github.ref_name == 'staging' && 'https://tasks-stage.hotosm.org' || github.ref_name == 'main' && 'https://tasks.hotosm.org' || 'https://just.build.test' }}
19+
20+
steps:
21+
- name: Clone repository
22+
uses: actions/checkout@v4
23+
24+
- name: Use Node.js 22.11.0
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: 22.11.0
28+
29+
- name: Cache node_modules
30+
uses: actions/cache@v4
31+
with:
32+
path: frontend/node_modules
33+
key: tm-fe-${{ runner.os }}-build-${{ hashFiles('frontend/package.json') }}
34+
restore-keys: |
35+
tm-fe-${{ runner.os }}-build-${{ hashFiles('frontend/package.json') }}
36+
37+
- name: Install yarn
38+
run: npm install -g yarn
39+
40+
- name: Load Environment from GitHub variables & secrets.
41+
uses: hotosm/gh-workflows/.github/actions/vars_n_secret_to_env@env_substitute/1.0.0
42+
with:
43+
vars_context: ${{ toJson(vars) }}
44+
secrets_context: ${{ toJson(secrets) }}
45+
46+
- name: Create .env file
47+
uses: hotosm/gh-workflows/.github/actions/env_substitute@env_substitute/1.0.0
48+
with:
49+
working_directory: ./frontend
50+
template_dotenv: .env.expand
51+
output_file: .env
52+
53+
- name: Install dependencies
54+
working-directory: ./frontend
55+
run: yarn install
56+
57+
- name: Generate build
58+
working-directory: ./frontend
59+
run: |
60+
yarn build
61+
62+
- name: Upload Builds Artifacts
63+
uses: actions/upload-artifact@v4
64+
with:
65+
name: tm-fe-${{ github.sha }}
66+
path: ./frontend/build
67+
68+
deploy:
69+
name: Deploy static files
70+
needs:
71+
- build
72+
runs-on: ubuntu-latest
73+
if: ${{ github.ref_name == 'develop' || github.ref_name == 'staging' || github.ref_name == 'main' }}
74+
75+
environment:
76+
name: ${{ github.ref_name == 'develop' && 'develop' || github.ref_name == 'staging' && 'staging' || github.ref_name == 'main' && 'main' || 'develop' }}
77+
url: ${{ github.ref_name == 'develop' && 'https://tasks-dev.hotosm.org' || github.ref_name == 'staging' && 'https://tasks-stage.hotosm.org' || github.ref_name == 'main' && 'https://tasks.hotosm.org' || 'https://just.build.test' }}
78+
79+
permissions:
80+
contents: read
81+
id-token: write
82+
83+
steps:
84+
- name: Clone repository
85+
uses: actions/checkout@v4
86+
87+
- name: Download Build Artifacts
88+
uses: actions/download-artifact@v4
89+
with:
90+
name: tm-fe-${{ github.sha }}
91+
path: ./build
92+
93+
- name: Setup AWS Credentials
94+
uses: hotosm/gh-workflows/.github/actions/configure_aws_credentials@configure_aws_credentials/1.0.0
95+
with:
96+
USE_OIDC_FOR_AWS: true
97+
AWS_CONFIG_FILE_PATH: ${{ github.workspace }}/.aws/credentials
98+
AWS_OIDC_ROLE_ARN: ${{ secrets.AWS_OIDC_ROLE_ARN }}
99+
AWS_REGION: ${{ vars.AWS_REGION }}
100+
101+
- name: Copy static files to S3
102+
shell: bash
103+
run: |
104+
set -ex
105+
aws s3 cp --recursive ./build s3://${{ vars.FRONTEND_S3_BUCKET }}
106+
107+
- name: Create cloudfront redistribution
108+
shell: bash
109+
run: |
110+
set -ex
111+
aws cloudfront create-invalidation --distribution-id ${{ vars.FRONTEND_CLOUDFRONT_DISTRIBUTION_ID }} --paths /

0 commit comments

Comments
 (0)