Say you need to access a GitHub repository owner and project name, separately. We know GitHub Actions environment variables exposes this information as:

  • GITHUB_REPOSITORY: The owner and repository name. For example, octocat/Hello-World.

So what’s the simplest way in a bash action step to get both separately? The answer is using parameter expansion.

Say you want to invoke the github_changelog_generator, you could use:

github_changelog_generator --user ${GITHUB_REPOSITORY%/*} --project ${GITHUB_REPOSITORY#*/} --token $ --o changelog.md 

The %/* will get the owner by getting everything before the matching expression /*, and #*/ will get the project name by getting everything after the matching expression */. Super convenient, and now I wish PowerShell had something similar and equally terse!