I created a new Rust project and decided, I'll give Github Actions a try to run automated builds and tests on each pull request:
name: Rust
on: [pull_request]
It took me a while to notice that by default, Github Actions does not checkout my code at all and the GITHUB_WORKSPACE is just empty. So, I tried manually cloning the repository. Doing something like this:
REPO=/tmp/path/to/repository
git clone https://github.com/myself/mycode.git $REPO
But this just checks out whatever is on the default branch. So, I investigated checking out $GITHUB_SHA which turns out to be something that is unknown to my repository. And the same is true for $GITHUB_REF which is just empty.
At this point I am clueless, about what I am doing. My initial assumption was that a job that is literally configured to run on: [pull request] should have exactly that code but it does not manage to checkout and prepare the it.
I also investigated the provided Checkout Actions:
This action checks out your repository to
$GITHUB_WORKSPACE, so that your workflow can access the contents of your repository.By default, this is equivalent to running
git fetchandgit checkout $GITHUB_SHA, so that you'll always have your repo contents at the version that triggered the workflow. See here to learn what$GITHUB_SHAis for different kinds of events.
But as I said before, the $GITHUB_WORKSPACE is entirely empty, and a git fetch will just tell you that there is no git repository.
Here's such an example failure:
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
fatal: reference is not a tree: d76745134ae45905e4a0ab8d27c92f1e2544bdc1
##[error]Process completed with exit code 128.
What is the $GITHUB_SHA if it's unknown to my repository? Do I completely misunderstand Github Actions? How to checkout the latest commit with Github Actions, i.e., on a pull request?
Here's the chronology of my failures.
- uses: actions/checkout@v1as the first step in your steps. It's an official action provided by github and is the recommended way of setting up your project in CI/CD workflows. - Arne$GITHUB_SHA... - Afrv1. Can you test the action with the exact string that I gave in my first comment? - Arne$GITHUB_SHAis still incorrect but I am now at least where I want to be:HEAD detached at pull/15/merge- Afr