Skip to content

Set Up GitHub Actions Runner

henrygdavies edited this page Jul 21, 2024 · 1 revision

Setting Up GitHub Actions Runner for hng_boilerplate_expressjs

Prerequisites

  • An Ubuntu server (e.g., Ubuntu 22.04)
  • Sudo access to the server
  • A GitHub repository (https://github.com/hngprojects/hng_boilerplate_expressjs)

Step 1: SSH into Your Server

First, SSH into your Ubuntu server:

ssh your_username@your_server_ip

Step 2: Create a Directory for the Runner

Navigate to the /opt directory and create a directory for the GitHub Actions runner:

sudo mkdir /opt/aiforhomework
cd /opt/aiforhomework

Step 3: Download the GitHub Actions Runner

Download the latest version of the GitHub Actions runner:

curl -o actions-runner-linux-x64-2.303.0.tar.gz -L https://github.com/actions/runner/releases/download/v2.303.0/actions-runner-linux-x64-2.303.0.tar.gz

Step 4: Extract the Runner

Extract the downloaded archive:

sudo tar xzf actions-runner-linux-x64-2.303.0.tar.gz

Step 5: Configure the Runner

Generate a token from your GitHub repository's settings:

  1. Go to your repository https://github.com/hngprojects/hng_boilerplate_expressjs.
  2. Navigate to Settings > Actions > Runners.
  3. Click New self-hosted runner.
  4. Follow the instructions to generate a token.

Use the token to configure the runner:

./config.sh --url https://github.com/hngprojects/hng_boilerplate_expressjs --token YOUR_GENERATED_TOKEN

Step 6: Install Dependencies

Install the necessary dependencies for the runner:

sudo apt-get install -y libicu66

Step 7: Install the Runner as a Service

Use the svc.sh script to install and start the service:

sudo ./svc.sh install
sudo ./svc.sh start

Step 8: Verify the Runner

Check the status of the runner to ensure it is running:

./svc.sh status

You should see output indicating that the service is active and running.

Step 9: Check Runner Status on GitHub

Navigate to your repository on GitHub and go to Settings > Actions > Runners. You should see your runner listed as Online.

Summary

By following these steps, you have successfully set up a GitHub Actions runner for your repository hng_boilerplate_expressjs on your Ubuntu server in the /opt/aiforhomework directory. This runner is now ready to execute workflows for your repository.


Additional Steps

Prevent Direct Pushes to Main and Dev Branches

To prevent direct pushes to the main and dev branches, set up branch protection rules:

  1. Go to Your Repository Settings:

    • Navigate to Settings > Branches.
  2. Create a Branch Protection Rule:

    • Click on Add rule.
    • Under Branch name pattern, enter main (and repeat for dev).
    • Enable Require pull request reviews before merging.
    • Optionally, enable Include administrators to apply the rule to administrators as well.
    • Save the changes.

This ensures that all changes to these branches must go through a pull request review process.