forked from wet-boew/wet-boew
-
Notifications
You must be signed in to change notification settings - Fork 0
176 lines (163 loc) · 6.3 KB
/
cd.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
name: Continuous Deployment
on:
push:
branches:
- master
- cd-script
tags:
- 'v*'
jobs:
deploy:
runs-on: ubuntu-latest
environment: github-cd
strategy:
matrix:
node-version: [20.x]
env:
REPO_DIST: wet-boew-dist
REPO_DIST_CDN: wet-boew-cdn
REPO_GITHUB_IO: wet-boew.github.io
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm i -g bower grunt-cli
- run: npm ci
- run: grunt deploy-build
#
# Prepare wet-boew deployment
#
- name: Extract tag or branch name
id: ref_name
uses: actions/github-script@v3
with:
github-token: ${{ secrets.my_token }}
result-encoding: string
# act use "\" and githbu use "/"
script: |
return context.ref.replace(/\/?refs\/heads\//, '').replace(/\\?refs\\heads\\/, '').replace(/\/?refs\/tags\//, '').replace(/\\?refs\\tags\\/, '')
- name: Check if it a tag
id: ref_tags
uses: actions/github-script@v3
with:
github-token: ${{ secrets.my_token }}
result-encoding: string
# act use "\" and githbu use "/"
script: |
return context.ref.startsWith("\\refs\\tags\\") || context.ref.startsWith("/refs/tags/") || context.ref.startsWith("refs/tags/") || context.ref.startsWith("refs\\tags\\") || ''
- name: Tag or branch info
env:
ref_name: ${{ steps.ref_name.outputs.result }}
is_tags: ${{ steps.ref_tags.outputs.result }}
run: |
echo Ref name: ${{ env.ref_name }}
echo Is tag: ${{ env.is_tags }}
- name: Git config
run: |
git config --global user.name "${{ secrets.my_username }}"
git config --global user.email "${{ secrets.my_email }}"
#
# Deploy wet-boew dist
#
- name: Dist - Applying changes
run: |
git clone --depth 1 https://github.com/${{ github.repository_owner }}/${{ env.REPO_DIST }}.git --branch v4.0-dist ~wet-boew-dist
rm -rf ~wet-boew-dist/*
cp -r dist/. ~wet-boew-dist/
cd ~wet-boew-dist
git add .
git commit -m "CD ${{ github.run_id }}: Update wet-boew dist files" --allow-empty
- name: Dist - Deploy in v4.0-dist branch
uses: ad-m/github-push-action@master
with:
repository: ${{ github.repository_owner }}/${{ env.REPO_DIST }}
directory: ~wet-boew-dist
branch: v4.0-dist
github_token: ${{ secrets.my_token }}
- name: Dist - Create release
if: ${{ env.is_tags != '' }}
uses: actions/github-script@v3
env:
commitish: v4.0-dist
repo: ${{ env.REPO_DIST }}
ref_name: ${{ steps.ref_name.outputs.result }}
is_tags: ${{ steps.ref_tags.outputs.result }}
with:
github-token: ${{ secrets.my_token }}
script: |
github.repos.createRelease({
owner: context.repo.owner,
repo: process.env.repo,
tag_name: process.env.ref_name,
name: 'Release ' + process.env.ref_name + ' (' + context.runId + ')',
target_commitish: process.env.commitish
});
#
# wet-boew Dist CDN
#
- name: Dist CDN - Prepare and build package.json
run: grunt build-pkg-json
- name: Dist CDN - Applying changes
run: |
git clone --depth 1 https://github.com/${{ github.repository_owner }}/${{ env.REPO_DIST_CDN }}.git --branch v4.0-dist ~wet-boew-cdn
rm -rf ~wet-boew-cdn/*
cp -r dist/wet-boew/. ~wet-boew-cdn/
cp Licence-fr.txt ~wet-boew-cdn/Licence-fr.txt
cp License-en.txt ~wet-boew-cdn/License-en.txt
cd ~wet-boew-cdn
git add .
git commit -m "CD ${{ github.run_id }}: Update wet-boew dist cdn files" --allow-empty
- name: Dist CDN - Deploy in v4.0-dist branch
uses: ad-m/github-push-action@master
with:
repository: ${{ github.repository_owner }}/${{ env.REPO_DIST_CDN }}
directory: ~wet-boew-cdn
branch: v4.0-dist
github_token: ${{ secrets.my_token }}
- name: Dist CDN - Create release
uses: actions/github-script@v3
env:
commitish: v4.0-dist
repo: ${{ env.REPO_DIST_CDN }}
ref_name: ${{ steps.ref_name.outputs.result }}
is_tags: ${{ steps.ref_tags.outputs.result }}
if: ${{ env.is_tags != '' }}
with:
github-token: ${{ secrets.my_token }}
script: |
github.repos.createRelease({
owner: context.repo.owner,
repo: process.env.repo,
tag_name: process.env.ref_name,
name: 'Release ' + process.env.ref_name + ' (' + context.runId + ')',
target_commitish: process.env.commitish
});
#
# Deploy submodule for wet-boew.github.io
#
- name: Dist wet-boew.github.io - Update submodule
run: |
git clone --depth 1 https://github.com/${{ github.repository_owner }}/${{ env.REPO_GITHUB_IO }}.git --branch master ~wet-boew-submodule
cd ~wet-boew-submodule
git submodule update --init --depth 1 v4.0-ci
git submodule update --init --depth 1 wet-boew
cd v4.0-ci
git remote add neworigin https://github.com/${{ github.repository_owner }}/${{ env.REPO_DIST }}.git
git fetch --depth 1 neworigin v4.0-dist
git reset --hard neworigin/v4.0-dist
cd ../wet-boew
git remote add neworigin https://github.com/${{ github.repository_owner }}/${{ env.REPO_DIST }}.git
git fetch --depth 1 neworigin v4.0-dist
git reset --hard neworigin/v4.0-dist
cd ..
git add .
git commit -m "CD ${{ github.run_id }}: Update submodule wet-boew dist" --allow-empty
- name: Dist - Deploy submodule updated
uses: ad-m/github-push-action@master
with:
repository: ${{ github.repository_owner }}/${{ env.REPO_GITHUB_IO }}
directory: ~wet-boew-submodule
branch: master
github_token: ${{ secrets.my_token }}