GitHub Actions
GitHub Actions is a platform that allows you to create continuous integration and continuous delivery (CI/CD) pipelines to automate your build and deployment workflows.
Refer to Quickstartโ๏ธ for a brief example of a workflow.
Components:
- Workflow - defines the automated process that will run one or more tasks when an event is triggered. It is configured with YAML file/s in the
.github/workflowsdirectory in a repository. - Event - when this activity occurs in a repository, it triggers the corresponding workflow to run. An event could be a pushed commit, scheduled at specific periods or triggered manually.
- Job - a set of steps defined in a workflow that is performed by the same runner. A step could be a shell script or an action that can be run.
- Action - frequently repeated task, may be custom made or reused from marketplace.
- Runner - server that runs a workflow when it is triggred by an event.
Example Use Case: Deploying Docusaurusโ
Code for Docusaurus may be kept in a private repository (source), while the static build to be deployed in GitHub Pages can be in a separate public repository (destination/external). We will use GitHub Actions for seamless build whenever we push our code to the private repository.
Specifically, we will configure our GitHub Actions workflow to:
- Checkout the code from the source repo.
- Set up node, install dependencies and build the static Docusaurus site.
- Publish the static code to an external public github.io repository.
This workflow is triggered whenever code is pushed in the private repo.
Steps:
- Create YAML workflow file in the directory
.github/workflowsin the source repository (private). - Use action
peaceiris/actions-gh-pages@v3to deploy static pages. Set external repository as<username>/<username>.github.io.publish_diris where the static pages are typically written in the source repository (usually./buildfor docusaurus).publish_branchis the branch in the destination repository (main) where the static pages will be copied. - Set up public and private keys using
ssh-keygen -t rsa -b 4096 -C "$(git config user.email)" -f gh-pages -N ""This will generate two files:gh-pages.pubis the public key that you need to configure in the destination public repo's deploy keys (allow write access), andgh-pagesis the private key that you need to configure in the source repo's secrets. Refer to peaceirisโ๏ธ for sample screenshots. Tip ๐ก: Use VSCode to view/copy the keys.
Reference: