4

Get owner and project name from GitHub Actions

 2 years ago
source link: https://www.cazzulino.com/github-actions-repository.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Get owner and project name from GitHub Actions

Posted on October 18, 2021

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!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK