-
Notifications
You must be signed in to change notification settings - Fork 0
168 lines (156 loc) · 5.8 KB
/
release.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
name: Release
permissions:
actions: write
contents: write
checks: read
pull-requests: read
deployments: write
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
on:
push:
tags:
- 'web-v*.*.*'
- 'docs-v*.*.*'
- 'v*.*.*'
jobs:
check-app:
runs-on: ubuntu-latest
outputs:
app: ${{ steps.project-info.outputs.app }}
branch: ${{ steps.project-info.outputs.branch }}
pull_args: ${{ steps.project-info.outputs.pull_args }}
steps:
- name: Extract Tag Info
id: tag-info-raw
uses: actions/github-script@v6
with:
script: |
const tag = "${{ github.ref }}";
const tripTag = tag.replace('refs/tags/', '');
const regex = /^([a-z]+-)?v(\d+\.\d+(\.\d+)?)(-([a-z]+)(\.(\d+))?)?$/;
const match = tripTag.match(regex);
if (match) {
const prefix = match[1] ? match[1].slice(0, -1) : null;
const version = match[2];
const suffix = match[5] ? match[5] : null;
const revision = match[7] ? match[7] : null;
console.log(`Prefix: ${prefix}`);
console.log(`Version: ${version}`);
console.log(`Suffix: ${suffix}`);
console.log(`Revision: ${revision}`);
return {
app: prefix,
version: version,
branch: suffix,
revision: revision
}
} else {
console.log('Input string does not match expected format');
return {
app: null,
version: null,
branch: null,
revision: null
};
}
- name: Extract tag to project info
id: project-info
run: |
VERCEL_PULL_ARGS=""
APP=$(echo ${{ fromJson(steps.tag-info-raw.outputs.result).app }})
BRANCH=$(echo ${{ fromJson(steps.tag-info-raw.outputs.result).branch }})
ENV=""
if [[ $BRANCH == "beta" ]]; then
BRANCH="staging"
VERCEL_PULL_ARGS="--environment=preview --git-branch=staging"
elif [[ $BRANCH == "alpha" ]]; then
BRANCH="testing"
VERCEL_PULL_ARGS="--environment=preview --git-branch=testing"
else
BRANCH="main"
VERCEL_PULL_ARGS="--environment=production"
fi
if [[ -z "$APP" ]]; then
echo "App name is empty"
fi
echo "app=$APP" >> $GITHUB_OUTPUT
echo "pull_args=$VERCEL_PULL_ARGS" >> $GITHUB_OUTPUT
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
create_release_single_app:
runs-on: ubuntu-latest
needs: [check-app]
if: ${{ needs.check-app.outputs.app != null && needs.check-app.outputs.branch != null }}
steps:
- name: Setup Vercel Project Id
run: |
APP=$(echo ${{ needs.check-app.outputs.app }})
if [[ $APP == "docs" ]]; then
echo "Setting docs project id"
echo "VERCEL_PROJECT_ID=${{ secrets.VERCEL_DOCS_PROJECT_ID }}" >> $GITHUB_ENV
elif [[ $APP == "web" ]]; then
echo "Setting web project id"
echo "VERCEL_PROJECT_ID=${{ secrets.VERCEL_WEB_PROJECT_ID }}" >> $GITHUB_ENV
else
echo "App name is not valid"
# Exit to prevent further execution
exit 1
fi
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 2
ref: ${{ needs.check-app.outputs.branch }}
- name: Prepare Environment
uses: ./.github/actions/setup-env
timeout-minutes: 10
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy Project to Vercel
uses: ./.github/actions/build
timeout-minutes: 10
with:
vercel-token: ${{ secrets.VERCEL_ACCESS_TOKEN }}
pull-env-args: ${{ needs.check-app.outputs.pull_args }}
build-env-args: ${{ needs.check-app.outputs.branch == 'main' && '--prod' || '' }}
create_release_all_apps:
runs-on: ubuntu-latest
needs: [check-app]
if: ${{ needs.check-app.outputs.app == null && needs.check-app.outputs.branch != null }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 2
ref: ${{ needs.check-app.outputs.branch }}
- name: Prepare Environment
uses: ./.github/actions/setup-env
timeout-minutes: 10
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Get Packages
id: app-packages
run: |
echo 'result<<CHANGESET_DELIMITER' >> $GITHUB_OUTPUT
echo "$(npx -y turbo build --dry-run=json --global-deps=.github/*)" >> $GITHUB_OUTPUT
echo 'CHANGESET_DELIMITER' >> $GITHUB_OUTPUT
- name: Deploy Web to Vercel
if: contains(toJson(fromJson(steps.app-packages.outputs.result).packages), 'web')
env:
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_WEB_PROJECT_ID }}
uses: ./.github/actions/build
timeout-minutes: 10
with:
vercel-token: ${{ secrets.VERCEL_ACCESS_TOKEN }}
pull-env-args: ${{ needs.check-app.outputs.pull_args }}
build-env-args: ${{ needs.check-app.outputs.branch == 'main' && '--prod' || '' }}
- name: Deploy Docs to Vercel
if: contains(toJson(fromJson(steps.app-packages.outputs.result).packages), 'docs') && always()
env:
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_DOCS_PROJECT_ID }}
uses: ./.github/actions/build
timeout-minutes: 10
with:
vercel-token: ${{ secrets.VERCEL_ACCESS_TOKEN }}
pull-env-args: ${{ needs.check-app.outputs.pull_args }}
build-env-args: ${{ needs.check-app.outputs.branch == 'main' && '--prod' || '' }}