Zum Hauptinhalt springen
Version: 1.x

GitHub Actions (Workflows)

In public repos, GitHub Actions allow you to run jobs on every commit and pull request for free. These processes can be automated tests, builds, code inspections ..etc. You can find more information about GitHub Actions here.

In this guide, you will learn how to add pre-defined workflows to your extension.

You can use the CLI to automatically add and update workflows to your code:

$ flarum-cli infra githubActions

Backend

All you need to do is create a .github/workflows/backend.yml file in your extension, it will reuse a predefined workflow by the core development team which can be found here. You need to specify the configuration as follows:

name: Backend

on: [workflow_dispatch, push, pull_request]

jobs:
run:
uses: flarum/framework/.github/workflows/REUSABLE_backend.yml@main
with:
# Different types of jobs
enable_backend_testing: true
enable_phpstan: false

# Additional parameters
backend_directory: .

These are the currently available jobs:

NameKeyDescription
Tests (PHPUnit)enable_backend_testingEnables backend unit/integration tests
Static Code Analysisenable_phpstanEnables static code analysis
info

These jobs run on every commit pushed to the main branch or pull request created.

Additional Parameters

In addition, the following parameters can be provided:

NameKeyDescriptionFormat
Directorybackend_directoryBackend code location. Contains a composer.json file.string
PHP Versionsphp_versionsThe PHP versions to run jobs onString JSON Array
PHP Extensionsphp_extensionsThe PHP extensions to installComma seperated
Databasesdb_versionsThe databases to run jobs onString JSON Array
PHP ini valuesphp_ini_valuesThe PHP ini values to useComma seperated
tip

Frontend

All you need to do is create a .github/workflows/frontend.yml file in your extension, it will reuse a predefined workflow by the core development team which can be found here. You need to specify the configuration as follows:

name: Frontend

on: [workflow_dispatch, push, pull_request]

jobs:
run:
uses: flarum/framework/.github/workflows/REUSABLE_frontend.yml@main
with:
enable_bundlewatch: false
enable_prettier: true
enable_typescript: false

frontend_directory: ./js
backend_directory: .
js_package_manager: yarn
main_git_branch: main

secrets:
bundlewatch_github_token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}

Unlike the backend workflow, the frontend workflow runs everything in a single job. Here are the available parameters:

NameKeyDescriptionFormat
Build Scriptbuild_scriptScript to run for production build. Empty value to disable.string
Build Typings Scriptbuild_typings_scriptScript to run for typings build. Empty value to disable.string
Format Scriptformat_scriptScript to run for code formatting. Empty value to disable.string
Check Typings Scriptcheck_typings_scriptScript to run for tyiping check. Empty value to disable.string
Type Coverage Scripttype_coverage_scriptScript to run for type coverage. Empty value to disable.string
Test Scripttest_scriptScript to run for tests. Empty value to disable.string
Enable Bundlewatchenable_bundlewatchEnable Bundlewatch?string
Enable Prettierenable_prettierEnable Prettier?string
Enable Typescriptenable_typescriptEnable TypeScript?string
Enable Testsenable_testsEnable Tests?string
Backend Directorybackend_directoryThe 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.string
Frontend Directoryfrontend_directoryThe directory of the project where frontend code is located. This should contain a package.json file.string
Main Git Branchmain_git_branchThe main git branch to use for the workflow.string
Node Versionnode_versionThe node version to use for the workflow.string
JS Package Managerjs_package_managerThe package manager to use (ex. yarn)string
Cache Dependency Pathcache_dependency_pathThe path to the cache dependency file.string

:::tip

For more details on parameters, checkout the full predefined reusable workflow file.

:::