-
Notifications
You must be signed in to change notification settings - Fork 19
188 lines (185 loc) · 8.23 KB
/
check-projects.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
176
177
178
179
180
181
182
183
184
185
186
187
188
name: Check projects
on:
push:
branches:
- master
paths:
- '.github/workflows/check-projects.yml'
- 'projects/**/*'
- '!projects/**/*.md'
pull_request:
branches:
- master
paths:
- '.github/workflows/check-projects.yml'
- 'projects/**/*'
- '!projects/**/*.md'
jobs:
build_bpmn-visualization_development_npm_package:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
repository: 'process-analytics/bpmn-visualization-js'
# to test a specific feature under development, uncomment the following line and use the related branch
# ref: 'specific_branch'
- name: Build Setup
uses: ./.github/actions/build-setup
- name: Build npm package
run: npm pack
- name: Upload npm package
uses: actions/upload-artifact@v3
with:
name: bpmn-visualization-npm-package
path: bpmn-visualization-*.tgz
build_projects:
runs-on: ubuntu-22.04
needs: 'build_bpmn-visualization_development_npm_package'
strategy:
# don't cancel running jobs even if one fails
fail-fast: false
matrix:
project:
- javascript-vanilla-with-webpack
- typescript-angular
- typescript-lit-element
- typescript-vanilla-with-parcel
- typescript-vanilla-with-rollup
- typescript-vanilla-with-vitejs
- typescript-vue
bv-npm-package:
- development
- release
defaults:
run:
working-directory: ${{github.workspace}}/projects/${{matrix.project}}
steps:
- name: Download the bpmn-visualization development npm package
if: ${{ matrix.bv-npm-package == 'development' }}
id: 'download'
uses: actions/download-artifact@v3
with:
name: bpmn-visualization-npm-package
path: ${{github.workspace}}/../bpmn-visualization-npm-package
- uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: Install dependencies
run: npm install
- name: Install bpmn-visualization development npm package
if: ${{ matrix.bv-npm-package == 'development' }}
# use wildcard as the file contains the version, and we don't know it
run: npm install ${{steps.download.outputs.download-path}}/bpmn-visualization*.tgz
- name: Build project
run: npm run build
- name: Upload project archive
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v3
with:
name: ${{matrix.project}}-${{matrix.bv-npm-package}}
path: ${{github.workspace}}/projects/${{matrix.project}}/dist
# WARN: use a short job-id to ensure the surge.sh subdomain is valid i.e. up to 63 characters (the surge-preview action includes the job-id in the generated surge domain)
# For instance, using 'publish_pr_preview' would create the "process-analytics-bpmn-visualization-examples-publish_pr_preview-pr-438" subdomain
# This subdomain is 71 characters long
# See https://github.com/bonitasoft/actions/issues/101 for more details
pr_preview:
if: github.event_name == 'pull_request'
runs-on: ubuntu-22.04
needs: 'build_projects'
permissions:
pull-requests: write # surge-preview: PR comments
steps:
- name: Download all artifacts
uses: actions/download-artifact@v3
with:
path: tmp
- name: Display structure of downloaded files
run: ls -lhR
working-directory: tmp
- name: Build the final directories layout
run: |
mkdir -p build/development build/release
cp -R tmp/*-development build/development
cp -R tmp/*-release build/release
# remove the '-development' and '-release' postfixes from directory names
for element in build/development/*-development; do
mv "$element" "${element%-development}"
done
for element in build/release/*-release; do
mv "$element" "${element%-release}"
done
- name: List projects that will be referenced in the home page
id: list_projects
run: |
# for the ls option, see https://serverfault.com/a/1095912
echo "projects_development=$(ls -xw0 build/development/)" >> $GITHUB_OUTPUT
echo "projects_release=$(ls -xw0 build/release/)" >> $GITHUB_OUTPUT
- name: Create the home page
uses: actions/github-script@v7
env:
PR_NUMBER: ${{github.event.pull_request.number}}
PR_URL: ${{github.server_url}}/${{github.repository}}/pull/${{github.event.pull_request.number}}
PROJECTS_DEVELOPMENT: ${{ steps.list_projects.outputs.projects_development }}
PROJECTS_RELEASE: ${{ steps.list_projects.outputs.projects_release }}
with:
script: |
const {PR_NUMBER, PR_URL, PROJECTS_DEVELOPMENT, PROJECTS_RELEASE} = process.env;
let htmlContent = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Examples of bpmn-visualization projects for PR #${PR_NUMBER}</title>
</head>
<body>
<h1>Examples of <code>bpmn-visualization</code> projects for <a href="${PR_URL}">PR #${PR_NUMBER}</a></h1>
<p>
Projects built using the <a href="https://github.com/process-analytics/bpmn-visualization-js/releases/latest" target="_blank">latest released version</a> of <code>bpmn-visualization</code>
<ul>
@release_projects@
</ul>
<p>
Projects built using the <a href="https://github.com/process-analytics/bpmn-visualization-js/" target="_blank">development version</a> of <code>bpmn-visualization</code>
<ul>
@development_projects@
</ul>
</body>
</html>
`
htmlContent = htmlContent.replaceAll('@release_projects@', PROJECTS_RELEASE.split(' ').filter(name => name.trim() !== '').map(name => `<li><a href="release/${name}/index.html" target="_blank">${name}</a></li>`).join('\n'));
htmlContent = htmlContent.replaceAll('@development_projects@', PROJECTS_DEVELOPMENT.split(' ').filter(name => name.trim() !== '').map(name => `<li><a href="development/${name}/index.html" target="_blank">${name}</a></li>`).join('\n'));
console.info('Generated page', htmlContent);
// Create the file
require('fs').writeFileSync('build/index.html', htmlContent);
- name: Display the final structure of files
run: |
ls -lhR build
- uses: bonitasoft/actions/packages/surge-preview-tools@v2
id: surge-preview-tools
with:
surge-token: ${{ secrets.SURGE_TOKEN }}
- name: Manage surge preview
if: steps.surge-preview-tools.outputs.can-run-surge-command == 'true'
uses: afc163/surge-preview@v1
with:
surge_token: ${{ secrets.SURGE_TOKEN }}
github_token: ${{ secrets.GITHUB_TOKEN }}
dist: build
failOnError: true
# We are not doing teardown here.
# The teardown must be performed in the same job as the one which creates the domain (as the surge-action uses the job id to compute the surge domain).
# Here, the job is run after other jobs run. Teardown run typically on PR close, and we don't want to run the parent job on PR close.
# If the parent jobs don't run, this job cannot run. So we are in a dead end.
# In the process-analytics GitHub organization, we have a workflow that is scheduled periodically to teardown old domain.
# The domain created here will be removed by this scheduled run.
teardown: 'false'
build: echo 'Already built!'
# Fallback when it is not possible to deploy to surge.sh
- name: Upload artifact (preview not deployed)
if: steps.surge-preview-tools.outputs.can-run-surge-command == 'false'
uses: actions/upload-artifact@v3
with:
name: bpmn-visualization-examples-projects-${{github.sha}}
path: build