-
-
Notifications
You must be signed in to change notification settings - Fork 837
155 lines (140 loc) · 5.5 KB
/
REUSABLE_frontend.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
name: Flarum Frontend Jobs
on:
workflow_call:
inputs:
build_script:
description: "Script to run for production build. Empty value to disable."
type: string
required: false
default: build
build_typings_script:
description: "Script to run for typings build. Empty value to disable."
type: string
required: false
default: build-typings
format_script:
description: "Script to run for code formatting. Empty value to disable."
type: string
required: false
default: format-check
check_typings_script:
description: "Script to run for tyiping check. Empty value to disable."
type: string
required: false
default: check-typings
type_coverage_script:
description: "Script to run for type coverage. Empty value to disable."
type: string
required: false
default: check-typings-coverage
test_script:
description: "Script to run for tests. Empty value to disable."
type: string
required: false
default: test
enable_bundlewatch:
description: "Enable Bundlewatch?"
type: boolean
default: false
required: false
enable_prettier:
description: "Enable Prettier?"
type: boolean
default: true
required: false
enable_typescript:
description: "Enable TypeScript?"
type: boolean
default: true
required: false
enable_tests:
description: "Enable Tests?"
type: boolean
default: false
required: false
backend_directory:
description: The directory of the project where backend code is located. This should contain a `composer.json` file, and is generally the root directory of the repo.
type: string
required: false
default: '.'
frontend_directory:
description: The directory of the project where frontend code is located. This should contain a `package.json` file.
type: string
required: false
default: './js'
main_git_branch:
description: The main git branch to use for the workflow.
type: string
required: false
default: main
node_version:
description: The node version to use for the workflow.
type: number
required: false
default: 16
js_package_manager:
description: "Enable TypeScript?"
type: string
default: yarn
required: false
cache_dependency_path:
description: "The path to the cache dependency file."
type: string
required: false
secrets:
bundlewatch_github_token:
description: The GitHub token to use for Bundlewatch.
required: false
env:
COMPOSER_ROOT_VERSION: dev-main
ci_script: ${{ inputs.js_package_manager == 'yarn' && 'yarn install --immutable' || 'npm ci' }}
cache_dependency_path: ${{ inputs.cache_dependency_path || format(inputs.js_package_manager == 'yarn' && '{0}/yarn.lock' || '{0}/package-lock.json', inputs.frontend_directory) }}
jobs:
build:
name: Checks & Build
runs-on: ubuntu-latest
if: >-
((github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) || github.event_name != 'pull_request')
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node_version }}
cache: ${{ inputs.js_package_manager }}
cache-dependency-path: ${{ env.cache_dependency_path }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: curl, dom, gd, json, mbstring, openssl, pdo_mysql, tokenizer, zip
tools: composer:v2
# Needed since tsconfig draws typings from vendor folder.
- name: Install Composer dependencies
run: composer install
working-directory: ${{ inputs.backend_directory }}
- name: Install JS dependencies
run: ${{ env.ci_script }}
working-directory: ${{ inputs.frontend_directory }}
- name: JS Checks & Production Build
uses: flarum/action-build@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
build_script: ${{ inputs.build_script }}
build_typings_script: ${{ inputs.build_typings_script }}
format_script: ${{ inputs.enable_prettier == true && inputs.format_script || '' }}
check_typings_script: ${{ inputs.enable_typescript == true && inputs.check_typings_script || '' }}
type_coverage_script: ${{ inputs.enable_typescript == true && inputs.type_coverage_script || '' }}
test_script: ${{ inputs.enable_tests == true && inputs.test_script || '' }}
package_manager: ${{ inputs.js_package_manager }}
js_path: ${{ inputs.frontend_directory }}
do_not_commit: ${{ github.ref != format('refs/heads/{0}', inputs.main_git_branch) || github.event_name != 'push' }}
- name: Check bundle size change
if: ${{ inputs.enable_bundlewatch }}
run: node_modules/.bin/bundlewatch --config .bundlewatch.config.json
working-directory: ${{ inputs.frontend_directory }}
env:
BUNDLEWATCH_GITHUB_TOKEN: ${{ secrets.bundlewatch_github_token }}
CI_COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
CI_BRANCH_BASE: ${{ github.event.pull_request.base.ref }}