Github Action to clone a public or private Github repository and access its content on others repositories' workflows.
This action v2
is using a composite action to be compatible with all operating systems (the v1
was using a Dockerfile that was only compatible with ubuntu-*
runners).
You now have a new input parameter called depth
, which is optional and has an empty default value. If you specify a depth value when using the action, it will be passed as the value for the --depth parameter of the git clone command. Otherwise, the clone will be done with the default depth, which is the full history.
You now have a new input parameter called branch
, which is optional and uses main
as default value. If you specify a branch value when using the action, it will be passed as the value for the --branch parameter of the git clone command.
You now have a new input parameter called submodule
, which is optional and uses false
as default value. If you specify the submodule value when using the action as true
, it will clone the submodule along with the repository.
Create a new .yml
file on your .github/workflows
directory.
Field | Mandatory | Observation |
---|---|---|
owner | YES | Ex: octocat |
repository | YES | Ex: clone-github-repo-action |
branch | NO | Ex: main (default) |
depth | NO | 1 Ex: most recent commit |
submodule | NO | false or true |
access-token | NO | How to create a PAT |
You can use one of those as reference:
- name: Clone GuillaumeFalourd/poc-github-actions PUBLIC repository
uses: GuillaumeFalourd/[email protected]
with:
depth: 1
branch: 'main'
owner: 'GuillaumeFalourd'
repository: 'poc-github-actions'
To use this action to clone a PRIVATE
repository the Github User/Admin has access to, it's necessary to create a PERSONAL ACCESS TOKEN with REPOSITORY
scopes.
- name: Clone GuillaumeFalourd/formulas-training PRIVATE repository
uses: GuillaumeFalourd/[email protected]
with:
owner: 'GuillaumeFalourd'
repository: 'formulas-training'
access-token: ${{ secrets.ACCESS_TOKEN }}
After using this action in your workflow, you can use the following command to access the cloned repository content:
cd <repository-name>
- name: Access cloned repository content
run: |
cd <repository-name>
ls -la
☞ This repository uses the Apache License 2.0
(Made with contributors-img)