Skip to content

Commit 84d2e22

Browse files
committed
Add preview branch workflow
1 parent 6004037 commit 84d2e22

File tree

1 file changed

+229
-0
lines changed

1 file changed

+229
-0
lines changed

.github/workflows/preview-branch.yml

+229
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
4+
name: Preview branch
5+
6+
on:
7+
push:
8+
branches:
9+
- preview-*
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checking out for ${{ github.ref }}
17+
uses: actions/checkout@v2
18+
19+
- name: Use Node.js ${{ matrix.node-version }}
20+
uses: actions/setup-node@v1
21+
with:
22+
node-version: ${{ matrix.node-version }}
23+
24+
- name: Run npx version-from-git --no-git-tag-version
25+
if: ${{ startsWith(github.ref, 'refs/heads/') }}
26+
run: npx version-from-git --no-git-tag-version
27+
28+
- run: npm ci
29+
30+
- run: npm run bootstrap -- --ignore=playground
31+
32+
- name: Propagate versions
33+
run: |
34+
node_modules/.bin/lerna version --force-publish --no-git-tag-version --no-push --yes `cat package.json | jq -r .version`
35+
36+
- name: Run npm run build
37+
env:
38+
NODE_ENV: production
39+
run: npm run build --if-present -- --ignore=playground
40+
41+
# - run: npm test
42+
43+
- name: Run npm pack bundle
44+
run: |
45+
cd packages/bundle
46+
npm pack
47+
48+
- name: Run npm pack component
49+
run: |
50+
cd packages/component
51+
npm pack
52+
53+
- name: Run npm pack core
54+
run: |
55+
cd packages/core
56+
npm pack
57+
58+
- name: Run npm pack directlinespeech
59+
run: |
60+
cd packages/directlinespeech
61+
npm pack
62+
63+
- name: Upload bundle
64+
uses: actions/upload-artifact@v2
65+
with:
66+
name: bundle
67+
path: 'packages/bundle/dist/**/*'
68+
69+
- name: Upload npm-tarball
70+
uses: actions/upload-artifact@v2
71+
with:
72+
name: npm-tarball
73+
path: 'packages/*/*.tgz'
74+
75+
tag-and-release:
76+
needs: build
77+
runs-on: ubuntu-latest
78+
79+
steps:
80+
- name: Checking out for ${{ github.ref }}
81+
uses: actions/checkout@v2
82+
with:
83+
path: repo
84+
85+
- name: Download bundle
86+
uses: actions/download-artifact@v2
87+
with:
88+
name: bundle
89+
path: artifacts/bundle
90+
91+
- name: Download npm-tarball
92+
uses: actions/download-artifact@v2
93+
with:
94+
name: npm-tarball
95+
path: artifacts/npm-tarball
96+
97+
- name: Read variables
98+
id: variables
99+
run: |
100+
echo "::set-output name=build_time::$(node -p "new Date().toISOString().replace('T', ' ')")"
101+
echo "::set-output name=date::$(date +%Y-%m-%d)"
102+
echo "::set-output name=version::$(tar xOf artifacts/npm-tarball/bundle/*.tgz package/package.json | jq -r '.version')"
103+
echo "::set-output name=short_sha::${GITHUB_SHA:0:7}"
104+
cd repo
105+
echo "::set-output name=branch_name::$(git rev-parse --abbrev-ref HEAD)"
106+
echo "::set-output name=last_commit_message::$(git log -1 --pretty=%B)"
107+
echo "::set-output name=tag_name::dev-$(git rev-parse --abbrev-ref HEAD)"
108+
109+
- name: Delete existing release
110+
continue-on-error: true
111+
run: |
112+
GITHUB_RELEASE_ID=$(curl --silent https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ steps.variables.outputs.tag_name }} | jq -r .id)
113+
echo Deleting release $GITHUB_RELEASE_ID.
114+
curl \
115+
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
116+
--header 'content-type: application/json' \
117+
--request DELETE \
118+
--url https://api.github.com/repos/${{ github.repository }}/releases/$GITHUB_RELEASE_ID
119+
120+
- name: Create a tag
121+
run: |
122+
cd repo
123+
git config user.name ${{ github.actor }}
124+
git config user.email ${{ github.actor }}@users.noreply.github.com
125+
git push origin :${{ steps.variables.outputs.tag_name }}
126+
git tag -f ${{ steps.variables.outputs.tag_name }} ${{ github.sha }}
127+
git push origin ${{ steps.variables.outputs.tag_name }}
128+
129+
- name: Create a release
130+
uses: actions/create-release@v1
131+
id: create-release
132+
env:
133+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
134+
with:
135+
prerelease: true
136+
release_name: '[${{ steps.variables.outputs.tag_name }}] - ${{ steps.variables.outputs.date }}'
137+
tag_name: ${{ steps.variables.outputs.tag_name }}
138+
body: |
139+
> Tarballs can be found in this workflow, https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}.
140+
141+
<table>
142+
<thead>
143+
<tr>
144+
<th>Build time</th>
145+
<th>Workflow ID</th>
146+
<th>Source version</th>
147+
<th>Branch</th>
148+
<th>Package version</th>
149+
</tr>
150+
</thead>
151+
<tbody>
152+
<tr>
153+
<td>
154+
<code>${{ steps.variables.outputs.build_time }}</code>
155+
</td>
156+
<td>
157+
<code>
158+
<a href="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}">${{ github.run_id }}</a>
159+
</code>
160+
</td>
161+
<td>
162+
<code>
163+
<a href="https://github.com/${{ github.repository }}/commit/${{ github.sha }}">${{ steps.variables.outputs.short_sha }}</a>
164+
</code>
165+
</td>
166+
<td>
167+
<code>
168+
<a href="https://github.com/${{ github.repository }}/tree/${{ steps.variables.outputs.branch_name }}">${{ steps.variables.outputs.branch_name }}</a>
169+
</code>
170+
</td>
171+
<td>
172+
<code>${{ steps.variables.outputs.version }}</code>
173+
</td>
174+
</tr>
175+
<tr>
176+
<td colspan="5">${{ steps.variables.outputs.last_commit_message }}</td>
177+
</tr>
178+
</tbody>
179+
</table>
180+
181+
## Script tags
182+
183+
```html
184+
<script src="https://github.com/${{ github.repository }}/releases/download/${{ steps.variables.outputs.tag_name }}/webchat.js"></script>
185+
186+
<script src="https://github.com/${{ github.repository }}/releases/download/${{ steps.variables.outputs.tag_name }}/webchat-es5.js"></script>
187+
188+
<script src="https://github.com/${{ github.repository }}/releases/download/${{ steps.variables.outputs.tag_name }}/webchat-minimal.js"></script>
189+
```
190+
191+
- name: Upload webchat.js to release
192+
uses: actions/upload-release-asset@v1
193+
env:
194+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
195+
with:
196+
upload_url: ${{ steps.create-release.outputs.upload_url }}
197+
asset_path: artifacts/bundle/webchat.js
198+
asset_name: webchat.js
199+
asset_content_type: text/javascript
200+
201+
- name: Upload webchat-es5.js to release
202+
uses: actions/upload-release-asset@v1
203+
env:
204+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
205+
with:
206+
upload_url: ${{ steps.create-release.outputs.upload_url }}
207+
asset_path: artifacts/bundle/webchat-es5.js
208+
asset_name: webchat-es5.js
209+
asset_content_type: text/javascript
210+
211+
- name: Upload webchat-minimal.js to release
212+
uses: actions/upload-release-asset@v1
213+
env:
214+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
215+
with:
216+
upload_url: ${{ steps.create-release.outputs.upload_url }}
217+
asset_path: artifacts/bundle/webchat-minimal.js
218+
asset_name: webchat-minimal.js
219+
asset_content_type: text/javascript
220+
221+
- name: Upload stats.json to release
222+
uses: actions/upload-release-asset@v1
223+
env:
224+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
225+
with:
226+
upload_url: ${{ steps.create-release.outputs.upload_url }}
227+
asset_path: artifacts/bundle/stats.json
228+
asset_name: stats.json
229+
asset_content_type: application/json

0 commit comments

Comments
 (0)