UnderStanding GitHub Actions

JeongChaeJin·2022년 11월 17일

GitHubAction

목록 보기
1/1

Overview

  • Continuous intergration & Continuous delivery platform
    • build, test, deployment pipeline 자동화
  • repository의 pull request를 build, test OR merged pull request를 production level로 deploy
  • worflow를 정의함에 따라 DevOps 그 이상을 수행해준다.

The components of GitHub Actions

  • pull request open, issue create 등의 event로 trigger를 줘서 Github Actions을 worflow에 맞게 동작 하도록 설정할 수 있다.

  • 각 job은 가상 머신 runner or container 돌아간다.

1. Worflows

  • 1개 이상의 job을 run할 수 있는 configurable automoated process다.
  • 해당 Repository의 .github/workflows directory에 yaml로 정의해놓으면 된다.

2. Events

  • RepositoryZ에서 workflow가 동작할 specific activity다.
  • 이는 REST API를 통해서도, 수동으로도 할 수 있다. (자세한건 나중에)

3. Jobs

  • 같은 runner안에 실행할 수 있는 step들의 set이다.
  • step은 shell script 이거나 실행하는 어떤 action이다.
  • step은 의존적으로 순서대로 작동한다.
  • 같은 runner에서 동작하여 step들은 data를 공유할 수 있다.
  • job은 기본적으로 dependency를 갖지는 않고, 설정해준다면 dependency를 갖도록 수정할 수 있다.

4. Actions

  • 빈번하게 반복되는 작업을 수행하는 GitHub Action platfor에 대한 custom application이다.

5. Runners

  • trigger 발생 시 worflow를 실행할 server다.
  • 각 runner는 한번에 single job을 수행할 수 있다.

Create an example workflow

  • .github/worflows direcotry안에 yaml파일을 분리해서 worflow는 저장해 놓는다.
name: learn-github-actions
run-name: ${{ github.actor }} is learning GitHub Actions
on: [push]
jobs:
  check-bats-version:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: '14'
      - run: npm install -g bats
      - run: bats -v
  • 위와 같은 learning-github-actions.yaml 을 만들었다고 해보자.
name: learn-github-actions
  • Optional이며 Actions에서 나타날 worflow의 이름이다.
run-name: ${{ github.actor }} is learning GitHub Actions
  • Optional이며 worflow에 의해 만들어진 worflow run의 이름
  • github.actor는 worflow run을 triggering한 actor의 이름이다.
on: [push]
  • worflow를 위한 Trigger다.
  • 위처럼 push event를 했을 경우 매번 repository에 changes를 push할 때마다 triggering된다.
jobs:
  • 해당 worflow의 실행되는 jobs
check-bats-version:
  • job의 이름을 정의한 것이다.
  runs-on: ubuntu-latest
  • runner가 수행될 최신버전을 나타낸다.
  • 이는 job이 GitHub에 의해 호스팅된 가상머신에서 수행됨을 의미한다.
  steps:
  • 수행될 step
    - uses: actions/checkout@v3
  • 이 step이 actions/checkout action의 v3 으로 진행될 것이라는 것을 보여준다.
    - uses: actions/setup-node@v3
      with:
        node-version: '14'
  • 이 step은 actions/setup-node@v3 action을 사용하는데, Node.js의 특정 버전이 설치되어있는 action을 의미한다.
    - run: npm install -g bats
  • run keyword는 runner에서 실행할 command이다.

  • 대충 이런식의 worflow를 만든거다.

Viewing the activity for a worflow run

profile
OnePunchLotto

0개의 댓글