GitHub Actions integrate automated workflows into a repository. We’re usually running the test suite of a given repository when pushing commits to a repository on GitHub.
This tutorial shows you how to clone other repositories in your GitHub Actions workflows.
GitHub Actions Series Overview
- Getting Started With Node.js
- Create a Testing Matrix
- Using MongoDB
- Using Redis
- Using MongoDB Replica Sets
- Run on Pull Request
- Customize the Job Name
- Run a Workflow When Creating a Tag
- Testing Against an Exact Node.js Version
- Trigger Builds on Schedule (Cron)
- How to Test Lerna Monorepos
- How to Add Comments in YAML Files
- Clone Another Repository
Use Case: the Supercharge Website
The Supercharge website is a case that needs to clone a second repository to properly run the test suite. The Supercharge website is responsible to render the documentation for the Supercharge framework and packages.
The documentation and their individual are hosted in a different repository than the website. Hosting the docs separately allows us to use git branches representing the major versions of the framework.
The test suite of the website repository contains tests calling routes that render a documentation page. Rendering a documentation page requires the docs repository to be available. That’s why we need to clone the second repository in the GitHub Actions testing workflow.
Clone Another Repository in Your GitHub Actions
GitHub provides convenient action helpers. Their actions/checkout helper comes with the functionality to clone other repositories. You can clone other repositories side-by-side with your “main” repository or nested.
In this example, we’re cloning the Supercharge docs repository into a nested path inside of the Supercharge website repo. Here’s a sample GitHub Actions workflow cloning two repositories (nested):
name: Run tests on: [push, pull_request] jobs: test: runs-on: ubuntu-latest steps: - name: Clone supercharge website repository uses: actions/checkout@v2 # This part here is cloning a second repository # While cloning the repository: # - it clones the repo into the given `path` # - it checks out the branch defined at `ref` - name: Clone supercharge docs repository uses: actions/checkout@v2 with: repository: supercharge/docs path: resources/docs/2.x ref: 2.x - name: … run: …