Additional function(s): lowercase|uppercase

Noob GitHub Actions user here.

My GitHub username includes uppercase characters.

My first GitHub Actions workflow builds a container image to push to GitHub Container Registry.

Container registries require lowercase repo names.

I wanted to be able to:

tags: ghcr.io/${{ github.repository }}:${{ github.sha }}

But this errors because github.repository_owner includes uppercase.

I was unable to find a function nor any other way to pipe this value into lowercase and think such a function (and perhaps its companion uppercase) would be useful.

tags: ghcr.io/${{ lowercase(github.repository) }}:${{ github.sha }}

Or, is there a better way to achieve this?

env:
  REPO: my-username/some-repo
...
steps:
   ...
   tags: ghcr.io/${{ env.REPO }}:${{ github.sha }}

The env approach is what I’d do, except that I’d use Bash parameter expansion to convert the case instead of hardcoding it:

      - name: downcase REPO
        run: |
          echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}

Or if you need the tag in a run step you could do the parameter expansion right there.

1 Like

While using built-in shell functionality is probably more succinct, you could also use a string manipulation action if you want something that works the same regardless of the shell type:

    steps:
      - id: string
        uses: ASzc/change-string-case-action@v1
        with:
          string: ${{ github.repository }}
      - run: |
          echo "${{ steps.string.outputs.lowercase }}"
1 Like