I've previously used GitLab, where I didn't checkout the repository explicitly. Instead it was done automatically by the pipeline.
Thus, I was surprised that almost all GitHub Actions workflows use e.g. actions/checkout@v3
.
But what's the purpose besides checking out a different repository?
As seen from the below screenshot, my repository is already checked out, when the job starts:
Without the checkout action GitHub wont clone your repository and you will get an empty folder. You can check this with a very basic action.yml
name: My Workflow
on: push
jobs:
myjob:
runs-on: ubuntu-latest
steps:
- name: just a simple ls command
runs: ls -la
Here is a video showing this and explaining it a bit more: https://www.youtube.com/watch?v=-61_kIikldQ
I am not sure how its showing the files in your case. Maybe you got a stale docker environment with files from previous runs because of a bug. I just tested it and I don't have any files without running the checkout first.
By default, this action will check-out to the SHA for that workflow’s event (such as push and pull_request). Otherwise, uses the default branch (usually main or master in a standard repository).
You should use the checkout action any time your workflow will use the repository's code.
https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions#understanding-the-workflow-file
This action checks-out your repository under $GITHUB_WORKSPACE, so your workflow can access it.
https://github.com/actions/checkout
So you can specify the repo, branch, path, submodule and so on to which you can checkout. Also you can use fetch-depth
to include git history as necessary.
Also note, that it's cloning the files to $GITHUB_WORKSPACE
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With