2022-06-19 18:14:21 +08:00
name : Flarum Frontend Jobs
on :
workflow_call :
inputs :
2022-08-08 21:48:43 +08:00
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
2023-02-11 20:19:57 +08:00
test_script :
description : "Script to run for tests. Empty value to disable."
type : string
required : false
default : test
2022-08-08 21:48:43 +08:00
2022-06-19 18:14:21 +08:00
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
2023-02-11 20:19:57 +08:00
enable_tests :
description : "Enable Tests?"
type : boolean
default : false
required : false
2022-06-20 02:01:21 +08:00
2022-06-19 18:14:21 +08:00
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
2022-06-20 02:01:21 +08:00
2022-06-19 18:14:21 +08:00
js_package_manager :
description : "Enable TypeScript?"
type : string
default : yarn
required : false
2022-06-20 02:01:21 +08:00
cache_dependency_path :
description : "The path to the cache dependency file."
type : string
required : false
2022-06-19 18:14:21 +08:00
secrets :
bundlewatch_github_token :
description : The GitHub token to use for Bundlewatch.
2022-06-20 02:01:21 +08:00
required : false
2022-06-19 18:14:21 +08:00
env :
COMPOSER_ROOT_VERSION : dev-main
ci_script : ${{ inputs.js_package_manager == 'yarn' && 'yarn install --immutable' || 'npm ci' }}
2022-06-20 02:01:21 +08:00
cache_dependency_path : ${{ inputs.cache_dependency_path || format(inputs.js_package_manager == 'yarn' && '{0}/yarn.lock' || '{0}/package-lock.json', inputs.frontend_directory) }}
2022-06-19 18:14:21 +08:00
jobs :
2022-08-08 21:48:43 +08:00
build :
name : Checks & Build
2022-06-19 18:14:21 +08:00
runs-on : ubuntu-latest
2022-08-13 16:33:37 +08:00
if : >-
((github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) || github.event_name != 'pull_request')
2022-06-19 18:14:21 +08:00
steps :
- name : Check out code
2023-02-11 20:19:57 +08:00
uses : actions/checkout@v3
2022-06-19 18:14:21 +08:00
- name : Set up Node
2023-02-11 20:19:57 +08:00
uses : actions/setup-node@v3
2022-06-19 18:14:21 +08:00
with :
node-version : ${{ inputs.node_version }}
cache : ${{ inputs.js_package_manager }}
cache-dependency-path : ${{ env.cache_dependency_path }}
2022-06-20 02:01:21 +08:00
2022-06-19 18:14:21 +08:00
- name : Setup PHP
uses : shivammathur/setup-php@v2
with :
2023-03-12 20:58:06 +08:00
php-version : '8.2'
2022-06-19 18:14:21 +08:00
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 }}
2022-08-08 21:48:43 +08:00
- name : JS Checks & Production Build
2023-02-11 20:19:57 +08:00
uses : flarum/action-build@v3
2022-06-19 18:14:21 +08:00
with :
github_token : ${{ secrets.GITHUB_TOKEN }}
2022-08-08 21:48:43 +08:00
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 || '' }}
2023-02-11 20:19:57 +08:00
test_script : ${{ inputs.enable_tests == true && inputs.test_script || '' }}
2022-06-19 18:14:21 +08:00
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' }}
2022-06-20 02:01:21 +08:00
2022-08-08 21:48:43 +08:00
- 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 }}