TYPO3:如何使用 Github 操作发布对 TER 的扩展并即时定制和添加第三方库

TYPO3: How to publish an extension to TER with Github actions and tailor and add third party library on the fly

我想使用 Github 操作和 tailor, the CLI Tool for maintaining public TYPO3 Extensions 将扩展自动发布到 TER。这适用于以下工作流配置:

name: TYPO3 Extension TER Release

on:
  push:
    tags:
      - '*'
jobs:
  publish:
    name: Publish new version to TER
    if: startsWith(github.ref, 'refs/tags/')
    runs-on: ubuntu-20.04
    env:
      TYPO3_EXTENSION_KEY: ${{ secrets.TYPO3_EXTENSION_KEY }}
      TYPO3_API_TOKEN: ${{ secrets.TYPO3_API_TOKEN }}
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Check tag
        run: |
          if ! [[ ${{ github.ref }} =~ ^refs/tags/[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$ ]]; then
            exit 1
          fi

      - name: Get version
        id: get-version
        run: echo ::set-output name=version::${GITHUB_REF/refs\/tags\//}

      - name: Get comment
        id: get-comment
        run: |
          readonly local comment=$(git tag -n10 -l ${{ steps.get-version.outputs.version }} | sed "s/^[0-9.]*[ ]*//g")

          if [[ -z "${comment// }" ]]; then
            echo ::set-output name=comment::Released version ${{ steps.get-version.outputs.version }} of ${{ env.TYPO3_EXTENSION_KEY }}
          else
            echo ::set-output name=comment::$comment
          fi

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: 7.4
          extensions: intl, mbstring, json, zip, curl
          tools: composer:v2

      - name: Install tailor
        run: composer global require typo3/tailor --prefer-dist --no-progress --no-suggest

      - name: Publish to TER
        run: php ~/.composer/vendor/bin/tailor ter:publish --comment "${{ steps.get-comment.outputs.comment }}" ${{ steps.get-version.outputs.version }}

因为我的扩展依赖于第三方 PHP 库(如果扩展与 composer 一起安装则加载)我需要在扩展部署到 TER 时即时添加这个库。因此我在 Resources/Private/PHP/ 中添加了一个 composer.json 和一个 composer.lock.

现在我想告诉 tailorResources/Private/PHP/ 中执行 composer install 并打包包含外部库的扩展。这可能吗?如果是,怎么做?

一般来说,将所有内容都放在 Composer 命令脚本中是很有用的,这样您实际上就可以在不依赖 Git 集线器操作或 CI 的情况下执行操作。

例如,您可以像这样添加一些命令:

{
    "scripts": {
        "build:cleanup": [
            "git reset --hard",
            "git clean -xfd"
        ],
        "deploy:ter:setup": [
            "@composer global require clue/phar-composer typo3/tailor"
        ],
        "build:ter:vendors": [
            "(mkdir -p /tmp/vendors && cd /tmp/vendors && composer require acme/foo:^1.0 acme/bar:^2.0 && composer global exec phar-composer build -v)",
            "cp /tmp/vendors/vendors.phar ./Resources/Private/libraries.phar",
            "echo \"require 'phar://' . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('$(composer config extra.typo3/cms.extension-key)') . 'Resources/Private/libraries.phar/vendor/autoload.php';\" >> ext_localconf.php"
        ],
        "deploy:ter:upload": [
            "composer global exec -v -- tailor ter:publish --comment \"$(git tag -l --format='%(contents)' $TAG)\" $TAG"
        ],
        "deploy:ter": [
            "@build:cleanup",
            "@deploy:ter:setup",
            "@build:ter:vendors",
            "@deploy:ter:upload"
        ]
    }
}

各种脚本解释:

  • build:cleanup 删除所有挂起的文件以确保没有不需要的文件上传到 TER
  • build:ter:setup 安装 typo3/tailor for the TER upload and clue/phar-composer 以构建供应商依赖项的 Phar
  • build:ter:vendors 在临时目录中安装手动维护的依赖项列表,并从中构建 Phar;然后它将那个 Phar 复制到当前目录并添加一个 require 调用到你的 ext_localconf.php
  • deploy:ter:upload最后调用Tailor上传当前目录包括Phar和ext_localconf.php调整并获取指定Git标签的注释;请注意,应在此处使用 --message 进行标记以具有带注释的 Git 标记(例如 git tag -a 1.2.3 -m "Bugfix release"

现在假设您 export/provide 环境变量 TYPO3_API_USERNAMETYPO3_API_PASSWORDTAG 您可以像这样立即部署最新版本:

# Provide username and password for TER, if not done yet
export TYPO3_API_USERNAME=YourName
export TYPO3_API_PASSWORD=YourSecretPassword

# Provide the tag to deploy
TAG=1.2.3 composer deploy:ter

随后相关的Github动作就变得很简单了:

jobs:
  build:
    # ...

  release-ter:
    name: TYPO3 TER release

    if: startsWith(github.ref, 'refs/tags/')
    needs: build

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3

      - name: Deploy to TER
        env:
          TYPO3_API_USERNAME: ${{secrets.TYPO3_API_USERNAME}}
          TYPO3_API_PASSWORD: ${{secrets.TYPO3_API_PASSWORD}}
          TAG: ${{github.ref_name}}
        run: composer deploy:ter

这是一个活生生的例子: