# GitHub Action Notes (CARTA)
- Overview
-- Basic components
- CARTA GitHub Runner Types
-- GitHub Website
-- Self-hosted
## Overview
GitHub Actions is a **continuous integration and continuous delivery (CI/CD) platform** that allows you to automate your **build, test, and deployment pipeline**. You can create workflows that build and test every pull request to your repository, or deploy merged pull requests to production.
GitHub Actions goes beyond just DevOps and lets you run <span style="background-color: #FFFF00">workflows</span> when other <span style="background-color: #FFFF00">events</span> happen in your repository. For example, you can run a workflow to automatically add the appropriate labels whenever someone creates a new issue in your repository.
GitHub provides **Linux, Windows, and macOS virtual machines** to run your workflows, or you can host your own self-hosted runners in your own data center or cloud infrastructure.

[Figure Reference](https://programmingpercy.tech/blog/github-actions-in-action/)
### Basic components
* Events:
An event is a specific activity in a repository that triggers a workflow run.
Use the `on` in the `.github/workflows/xxx.yml` key to specify what events trigger your workflow. It can be `push` on the specific branch in the GitHub, or it can be multi-events (e.g. `[push, pull_request]` in the `carta-backend/.github/workflows/continuous_integration.yml`)
[GitHub Reference](https://docs.github.com/en/actions/using-workflows/triggering-a-workflow)
* Workflows:
A workflow is a configurable automated process that will run one or more jobs. Workflows are defined by a YAML file checked in to your repository (`.github/workflows`) and will run when triggered by an event in your repository, or they can be triggered manually, or at a defined schedule. You can have multiple workflows, each of which can perform a different set of tasks. (e.g. carta_backend has one CI yml and one test yml)
* Jobs:
A job is a set of steps in a workflow that is executed on the same runner.
* Actions:
An action is a custom application for the GitHub Actions platform that performs a complex but frequently repeated task. Use an action to help reduce the amount of repetitive code that you write in your workflow files. An action can pull your git repository from GitHub, set up the correct toolchain for your build environment, or set up the authentication to your cloud provider. Usually used the default `uses: actions/checkout@v4` in yml.
* Runners:
A runner is a server that runs your workflows when they're triggered. Each runner can run a single job at a time. Physical github runner servers are in the US.
## CARTA GitHub Runner Types
### GitHub Website
Format check and Notification in the both frontend and backend.
In the `carta-backend/.github/workflows/continuous_integration.yml`
```yaml=
name: ci
on: [push, pull_request]
jobs:
format-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: ./scripts/style.py all check
...
Notify:
name: Send notifications
runs-on: ubuntu-latest
needs: [format-check, Ubuntu-Focal, macOS-12, AlmaLinux-8]
if: always()
steps:
- name: Notify Slack
uses: baijunyao/action-slack-notify@v3.0.0
if: ${{ github.event_name == 'push' }}
with:
slack_channel_id: actions-build-status
slack_bot_token: ${{ secrets.SLACK_BOT_TOKEN }}
github_context: ${{ toJson(github) }}
```

### Self-hosted
**Local computer should have Docker**
Going to the `repository -> Settings -> Actions (left hand side) -> Runners -> Add self-host runner`
Follow the description

Then the runners list will show all status of the self-host runner

Here I gave an example of running ICD-RxJS with self-host runner on my personal MacOS11 laptop (make sure the backend is running and built)
1. start the local carta-backend
`./carta_backend /Users/ming-yi/carta-test-img --debug_no_auth=true --no_http=true --log_performance=true --verbosity=5 --omp_threads=4 --log_protocol_messages=true --top_level_folder=/Users/ming-yi/carta-test-img`
2. add `carta-action-test/.github/workflows/run-local-ICD-RxJS.yml`
with following content
```yaml=
# This is a basic workflow to help you get started with Actions
name: ICD tests
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "dev" branch
push:
branches: [ "dev" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
env:
ICD_RXJS_BRANCH_NAME: dev
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "Prepare-ICD-RxJS"
Prepare-ICD-RxJS:
name: Running-ICD-RxJS
runs-on: self-hosted
timeout-minutes: 20
steps:
- name: Checkout ICD-RxJS repository
uses: actions/checkout@v4
with:
repository: CARTAvis/ICD-RxJS
ref: ${{ env.ICD_RXJS_BRANCH_NAME }}
path: ICD-RxJS
- name: Running ICD-RxJS (macOS)
run: |
ICD_DIR=$GITHUB_WORKSPACE/ICD-RxJS
cd $ICD_DIR
git submodule init && git submodule update && npm install
cd protobuf
./build_proto.sh
cd ../src/test
npm test *
echo $GITHUB_WORKSPACE
echo End Prepare ICD-RxJS!
```
3. Trigger push event on the dev branch, then trigger GitHub action to the self-host laptop, the results shows like

If there is any failure test, the job will be incomplete.

GitHub Action dashboard will show:
