Migrate From Travis CI to GitHub Actions
This post walks through migrating a build from Travis CI to GitHub Actions.
Migrate From Travis CI to GitHub Actions
This post walks through migrating a build from Travis CI to GitHub Actions.
Marco
Thanks for this article. Unfortunately, neither github.event.number nor github.head_ref work for me. I’m trying to pass their values to a build script, but both are empty.
For the branch, I’ve resolved with git branch --show-current
, but still no idea on how to detect I’m dealing with a pull request.
FeRD
I strongly suspect the workflow contexts can’t be used in script code, if you’re trying to use them that way — that is, I wouldn’t expect this to work:
jobs:
build:
steps:
- name: Something
run: if [ ${{ github.head_ref }} = “something” ]; then echo “Yep”; fi
However, you should be able to either create an envvar for use in the shell context, as Brian showed, or you can use one of Github’s built-in ones. github.event.number
doesn’t have an envvar, but $GITHUB_HEAD_REF
does. There’s a whole list of 'em. And, in fact, $GITHUB_EVENT_NAME
should be what you want, “the name of the webhook event that triggered the workflow”. So, for PRs:
jobs:
build:
steps:
- name: Something
run: if [ “x$GITHUB_EVENT_NAME” = “xpull_request” ]; then echo “I’m a PR.”; fi
ETA: (One caveat on the above, it may only run when the PR is initially opened. I’m not sure if updates to an open PR trigger as pull_request
events.)
Marco
Thanks a lot, @FeRD_NYC , I’ll try that. For the moment, I’ve seen that PRs don’t use the master branch anyway, so checking the current branch via git seems to be fine (but maybe I haven’t done enough tests).
The script I tried is
here.