'GitHub Actions expression functions: string manipulation?

In a GitHub Actions workflow definition file, there's a set of built-in functions that you can use in expressions.

For example: ${{ toJson(github) }}

Are there any string manipulation functions that can be used in an expression, such as toLowerCase?

The documentation page doesn't mention any. However, I'm wondering if Github uses some sort of standard templating / expression eval library under the hood which has provides a larger set of functions out of the box.



Solution 1:[1]

Impossible. GitHub expressions doesn't allow string modification, only concatenation.

You could do almost the same with a custom step in a build job, but this means that you won't be able to use that variable everywhere (for example "processed" environment name is out of the question).

env:
  UPPERCASE_VAR: "HELLO"
steps:
  - id: toLowerCase
    run: INPUT=${{ env.UPPERCASE_VAR }} echo "::set-output name=lowerCaseValue::${INPUT,,}"

  - run: echo ${{steps.toLowerCase.outputs.lowerCaseValue}}

Solution 2:[2]

I wanted to replace some chars in git version strings and was able to make a step like so:

  - name: prepare version string
    id: prep_version
    run: |
      export test_version=$(echo ${{ steps.tag_version.outputs.new_version }} |  sed 's/[^0-9,a-z,A-Z]/\-/g')
      echo ::set-output name=version::$test_version

that worked pretty good for me... so really we have anything that we could put on a cmd line

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vilius Sutkus '89
Solution 2 Jonathan Wilson