-
Notifications
You must be signed in to change notification settings - Fork 151
171 lines (145 loc) · 5 KB
/
deploy.yml
File metadata and controls
171 lines (145 loc) · 5 KB
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
name: Deploy
on:
push:
branches:
- main
paths:
- 'apps/marketing/**'
- 'apps/portal/**'
- 'apps/paste-service/**'
- 'packages/**'
workflow_dispatch:
inputs:
target:
description: 'Deploy target'
required: true
default: 'all'
type: choice
options:
- all
- marketing
- portal
- paste
permissions:
id-token: write
contents: read
jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
marketing: ${{ steps.changes.outputs.marketing }}
portal: ${{ steps.changes.outputs.portal }}
paste: ${{ steps.changes.outputs.paste }}
steps:
- uses: actions/checkout@v4
- name: Check for changes
id: changes
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
if [[ "${{ inputs.target }}" == "all" || "${{ inputs.target }}" == "marketing" ]]; then
echo "marketing=true" >> $GITHUB_OUTPUT
else
echo "marketing=false" >> $GITHUB_OUTPUT
fi
if [[ "${{ inputs.target }}" == "all" || "${{ inputs.target }}" == "portal" ]]; then
echo "portal=true" >> $GITHUB_OUTPUT
else
echo "portal=false" >> $GITHUB_OUTPUT
fi
if [[ "${{ inputs.target }}" == "all" || "${{ inputs.target }}" == "paste" ]]; then
echo "paste=true" >> $GITHUB_OUTPUT
else
echo "paste=false" >> $GITHUB_OUTPUT
fi
else
# For push events, check what changed
git fetch origin ${{ github.event.before }} --depth=1 2>/dev/null || true
MARKETING_CHANGED=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} 2>/dev/null | grep -E '^(apps/marketing/|packages/)' || true)
PORTAL_CHANGED=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} 2>/dev/null | grep -E '^(apps/portal/|packages/)' || true)
PASTE_CHANGED=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} 2>/dev/null | grep -E '^apps/paste-service/' || true)
if [[ -n "$MARKETING_CHANGED" ]]; then
echo "marketing=true" >> $GITHUB_OUTPUT
else
echo "marketing=false" >> $GITHUB_OUTPUT
fi
if [[ -n "$PORTAL_CHANGED" ]]; then
echo "portal=true" >> $GITHUB_OUTPUT
else
echo "portal=false" >> $GITHUB_OUTPUT
fi
if [[ -n "$PASTE_CHANGED" ]]; then
echo "paste=true" >> $GITHUB_OUTPUT
else
echo "paste=false" >> $GITHUB_OUTPUT
fi
fi
deploy-marketing:
needs: detect-changes
if: needs.detect-changes.outputs.marketing == 'true'
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install dependencies
run: bun install
- name: Build marketing
run: bun run build:marketing
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: us-east-1
- name: Deploy to S3
run: aws s3 sync apps/marketing/dist/ s3://plannotator-marketing/ --delete
- name: Invalidate CloudFront
run: |
aws cloudfront create-invalidation \
--distribution-id E284ON0A27O2H6 \
--paths "/*"
deploy-portal:
needs: detect-changes
if: needs.detect-changes.outputs.portal == 'true'
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install dependencies
run: bun install
- name: Build portal
run: bun run build:portal
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: us-east-1
- name: Deploy to S3
run: aws s3 sync apps/portal/dist/ s3://plannotator-portal/ --delete
- name: Invalidate CloudFront
run: |
aws cloudfront create-invalidation \
--distribution-id EP0KB9EFUWYXR \
--paths "/*"
deploy-paste:
needs: detect-changes
if: needs.detect-changes.outputs.paste == 'true'
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install dependencies
run: bun install
- name: Deploy to Cloudflare
working-directory: apps/paste-service
run: npx wrangler deploy
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}