CI : 지속적 통합 워크플로우Deployments : 배포 워크플로우Automation : 자동화 워크플로우Code Scanning : 코드 스캐닝 워크플로우Pages : Pages 워크플로우github/workflows 디렉토리에 github-actions-demo.yml 파일을 생성함name: GitHub Actions Demo
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
on: [push]
jobs:
Explore-GitHub-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v4
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ github.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."

github 폴더에서 해당 yml을 작업해서 올리면 위와 같이 actions가 실행되는 것을 볼 수 있다.
name : Github Actions Demo # 워크 플로우 이름
run-name : ${{ guthub.actor }} is testing out Github Actions
# ㄴ 실행될 때 표시될 이름(github.actor : 실행한 사람)
on : [push] # 트리거 조건: push이벤트가 발생할 때마다 실행
jobs:
Explore-Github-Actions: #작업이름
runs-on: ubuntu-latest #Ubuntu 최신 버전에서 실행
steps:
# 1단계: 이벤트 정보 출력
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
# 2단계: 실행 환경 정보 출력
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
# 3단계: 브랜치와 저장소 정보 출력
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
# 4단계: 저장소 코드 체크아웃 (중요!)
- name: Check out repository code
uses: actions/checkout@v4 # GitHub 제공 액션 사용
# 5-6단계: 체크아웃 완료 메시지
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
# 7단계: 저장소 파일 목록 출력
- name: List files in the repository
run: |
ls ${{ github.workspace }}
# 8단계: 작업 상태 출력
- run: echo "🍏 This job's status is ${{ job.status }}."
4단계, 저장소 코드 체크아웃이 중요한 이유
: 코드 접근의 시작점이기 때문
- name: Check out repository code
uses:: actions/checkout@v4
jobs:
build:
runs-on: ubuntu-latest
steps:
# checkout 없이 바로 npm install을 실행한다면?
- run: npm install # ❌ 실패! package.json이 없음
# 올바른 방법
- uses: actions/checkout@v4 # ✅ 먼저 코드를 가져오고
- run: npm install # 그 다음 npm install 실행
실제 사용예시
jobs:
test:
runs-on: ubuntu-latest
steps:
# 1. 먼저 코드를 가져옴
- uses: actions/checkout@v4
# 2. 이제 코드 관련 작업 가능
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
jobs:
Explore-GitHub-Actions:
runs-on: ubuntu-latest
Github Actions에서 runs-on: ubuntu-latest를 사용하는 이유
1. 러너의 개념
# 선택 가능한 운영체제들
runs-on: ubuntu-latest # Ubuntu
runs-on: windows-latest # Windows
runs-on: macos-latest # macOS
jobs:
build:
runs-on: ubuntu-latest # GitHub가 Ubuntu 가상머신을 생성
steps:
- uses: actions/checkout@v4 # 이 가상머신에 코드를 내려받고
- run: npm install # 필요한 작업을 수행하고
- run: npm test # 작업이 끝나면 가상머신은 삭제됨
즉, github는 매번 새로운 가상머신을 만들어서 제공함.
작업이 끝나면 이 가상머신은 삭제되어 다음 실행 시에는 새로운 가상머신이 만들어짐