-
Notifications
You must be signed in to change notification settings - Fork 7
141 lines (131 loc) Β· 4.92 KB
/
deploy.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
name: Deployment
on:
push:
branches:
- dev
- rec
- main
workflow_dispatch:
inputs:
FORCE_APP_DEPLOY:
description: "Force deploy app"
required: false
default: "false"
FORCE_DOCS_DEPLOY:
description: "Force deploy docs"
required: false
default: "false"
FORCE_CRON_DEPLOY:
description: "Force deploy cron"
required: false
default: "false"
FORCE_LANDING_DEPLOY:
description: "Force deploy landing"
required: false
default: "false"
env:
# push => github.event.before
# pull_request => github.event.pull_request.base.sha
# workflow_dispatch => HEAD^
TURBO_RUN_FILTER: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event_name == 'push' && github.event.before || 'HEAD^' }}
jobs:
checks:
name: Build
runs-on: ubuntu-latest
outputs:
changed-app: ${{ steps.changed-app.outputs.result }}
changed-docs: ${{ steps.changed-docs.outputs.result }}
changed-cron: ${{ steps.changed-cron.outputs.result }}
changed-landing: ${{ steps.changed-landing.outputs.result }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20.x"
cache: "npm"
- name: Changeset
id: changeset
# 1. We need the 'output' of a turbo dry-run to get a json with all affected packages of these run.
# 2. The multi line json string is transformed to a single line string.
# 3. The single line json string is set to an 'output' (or result) of this step.
run: |
npx -y turbo build --filter="...[$TURBO_RUN_FILTER]" --dry-run=json > $GITHUB_WORKSPACE/result.json 2> error.log
content=$(cat $GITHUB_WORKSPACE/result.json)
if [ $? -ne 0 ]; then
echo 'result<<EOF' >> $GITHUB_OUTPUT
cat error.log >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
else
echo 'result<<EOF' >> $GITHUB_OUTPUT
echo "$content" >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
fi
- name: Upload Result as Artifact
uses: actions/upload-artifact@v4
with:
name: changeset-result
path: ${{ github.workspace }}/result.json
- name: Changed app?
id: changed-app
if: ${{ contains(fromJSON(steps.changeset.outputs.result).packages, '@next-boilerplate/app') || github.event.inputs.FORCE_APP_DEPLOY == 'true' }}
run: |
echo "result=true" >> $GITHUB_OUTPUT
- name: Changed docs?
id: changed-docs
if: ${{ contains(fromJSON(steps.changeset.outputs.result).packages, '@next-boilerplate/docs') || github.event.inputs.FORCE_DOCS_DEPLOY == 'true' }}
run: |
echo "result=true" >> $GITHUB_OUTPUT
- name: Changed cron?
id: changed-cron
if: ${{ contains(fromJSON(steps.changeset.outputs.result).packages, '@next-boilerplate/cron') || github.event.inputs.FORCE_CRON_DEPLOY == 'true' }}
run: |
echo "result=true" >> $GITHUB_OUTPUT
- name: Changed landing?
id: changed-landing
if: ${{ contains(fromJSON(steps.changeset.outputs.result).packages, '@next-boilerplate/landing') || github.event.inputs.FORCE_LANDING_DEPLOY == 'true' }}
run: |
echo "result=true" >> $GITHUB_OUTPUT
deploy_app:
name: Deploy app
runs-on: ubuntu-latest
needs: checks
if: ${{ needs.checks.outputs.changed-app == 'true' }}
steps:
- name: Deploy app
run: |
echo "### Deploying app π" >> $GITHUB_STEP_SUMMARY
echo "Found changes in app compared to this commit $TURBO_RUN_FILTER" >> $GITHUB_STEP_SUMMARY
deploy_docs:
name: Deploy docs
runs-on: ubuntu-latest
needs: checks
if: ${{ needs.checks.outputs.changed-docs == 'true' }}
steps:
- name: Deploy docs
run: |
echo "### Deploying docs π" >> $GITHUB_STEP_SUMMARY
echo "Found changes in docs compared to this commit $TURBO_RUN_FILTER" >> $GITHUB_STEP_SUMMARY
deploy_cron:
name: Deploy cron
runs-on: ubuntu-latest
needs: checks
if: ${{ needs.checks.outputs.changed-cron == 'true' }}
steps:
- name: Deploy cron
run: |
echo "### Deploying cron π" >> $GITHUB_STEP_SUMMARY
echo "Found changes in cron compared to this commit $TURBO_RUN_FILTER" >> $GITHUB_STEP_SUMMARY
deploy_landing:
name: Deploy landing
runs-on: ubuntu-latest
needs: checks
if: ${{ needs.checks.outputs.changed-landing == 'true' }}
steps:
- name: Deploy landing
run: |
echo "### Deploying landing π" >> $GITHUB_STEP_SUMMARY
echo "Found changes in landing compared to this commit $TURBO_RUN_FILTER" >> $GITHUB_STEP_SUMMARY