WEBcoast Logo

TER publishing with GitHub Releases

I'm a big fan of automated releases procedures. That's why I wanted to use GitHub Actions and GitHub releases for publishing my extension to the TER. There is already a great tool for talking to the TER: Tailor. One challenge gave some headache though. How do I get the multline release description into the comment attribute of the `tailor ter:publish` command. The trick is to escape certain characters in the string, to keep it singleline when using the `::set-output name=` syntax in GitHub Actions.

I use `v` prefixed release tags. My worklow now looks like this:

name: publish
on:
    release:
        types: [created, edited]
jobs:
    publish:
        name: Publish to TER
        if: startsWith(github.ref, 'refs/tags/v')
        runs-on: ubuntu-20.04
        env:
            TYPO3_API_TOKEN: ${{ secrets.TYPO3_API_TOKEN }}
        steps:
            - name: Checkout repository
              uses: actions/checkout@v2

            - name: Check tag
              run: |
                  if ! [[ ${{ github.ref }} =~ ^refs/tags/v[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\/v/}

            - name: Get comment
              id: get-comment
              run: |
                  comment="${{ github.event.release.body }}"
                  comment="${comment//'%'/'%25'}"
                  comment="${comment//$'\n'/'%0A'}"
                  comment="${comment//$'\r'/'%0D'}"

                  if [[ -z "${comment// }" ]]; then
                    echo ::set-output name=comment::Released version ${{ steps.get-version.outputs.version }}
                  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 }}

Feel free to copy and adjust to your needs.