返回介绍

GitHub Actions (Workflows)

发布于 2024-06-22 20:04:58 字数 7530 浏览 0 评论 0 收藏 0

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.

Flarum CLI

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
信息

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
提示

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

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.

:::

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文