Skip to main content

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/workflows directory 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:

  1. Checkout the code from the source repo.
  2. Set up node, install dependencies and build the static Docusaurus site.
  3. Publish the static code to an external public github.io repository.

This workflow is triggered whenever code is pushed in the private repo.

Steps:

  1. Create YAML workflow file in the directory .github/workflows in the source repository (private).
  2. Use action peaceiris/actions-gh-pages@v3 to deploy static pages. Set external repository as <username>/<username>.github.io. publish_dir is where the static pages are typically written in the source repository (usually ./build for docusaurus). publish_branch is the branch in the destination repository (main) where the static pages will be copied.
  3. 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.pub is the public key that you need to configure in the destination public repo's deploy keys (allow write access), and gh-pages is 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: