반응형
github action 간단한 예제
최종적으로 만들어 볼 github action 의 결과입니다.
폴더와 파일 구성
작업에 필요한 폴더와 파일 목록입니다.
Project Folder
|_ .github
|_ workflows
|_ job_1.yml
|_ job_1_1.yml
|_ job_2.yml
|_ job_after_all_done_jobs.yml
|_ on_push_action.yml
on_push_action.yml 에서 job_1.yml, job_1_1.yml, job_2.yml, job_after_all_done_jobs.yml 파일을 호출하는 형태로 구성됩니다.
파일 내용
job_1.yml
name: Job 1
on:
workflow_call:
inputs:
environment:
required: true
type: string
secrets:
environment:
required: true
jobs:
deploy:
name: Deploy ${{ inputs.environment }}
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: main # branch 명
- name: github sha ${{ github.sha }}
run: |-
echo ${{ github.sha }}
- name: Execute jobs inputs ${{ inputs.environment }}
run: |-
echo ${{ inputs.environment }}
- name: Execute jobs secrets ${{ secrets.environment }}
run: |-
echo ${{ secrets.environment }}
job_1_1.yml
name: Job 1-1
on:
workflow_call:
inputs:
environment:
required: true
type: string
secrets:
environment:
required: true
jobs:
deploy:
name: Deploy ${{ inputs.environment }}
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: main # branch 명
- name: github sha ${{ github.sha }}
run: |-
echo ${{ github.sha }}
- name: Execute jobs inputs ${{ inputs.environment }}
run: |-
echo ${{ inputs.environment }}
- name: Execute jobs secrets ${{ secrets.environment }}
run: |-
echo ${{ secrets.environment }}
job_2.yml
name: Job 2
on:
workflow_call:
inputs:
environment:
required: true
type: string
secrets:
environment:
required: true
jobs:
deploy:
name: Deploy ${{ inputs.environment }}
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: main # branch 명
- name: github sha ${{ github.sha }}
run: |-
echo ${{ github.sha }}
- name: Execute jobs inputs ${{ inputs.environment }}
run: |-
echo ${{ inputs.environment }}
- name: Execute jobs secrets ${{ secrets.environment }}
run: |-
echo ${{ secrets.environment }}
job_after_all_done_jobs.yml
name: After all done jobs
on:
workflow_call:
inputs:
environment:
required: true
type: string
secrets:
environment:
required: true
jobs:
deploy:
name: Deploy ${{ inputs.environment }}
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: main # branch 명
- name: github sha ${{ github.sha }}
run: |-
echo ${{ github.sha }}
- name: Execute jobs inputs ${{ inputs.environment }}
run: |-
echo ${{ inputs.environment }}
- name: Execute jobs secrets ${{ secrets.environment }}
run: |-
echo ${{ secrets.environment }}
on_push_action.yml
name: On push github action
on:
push:
branches: ["main"]
jobs:
job_1:
uses: ./.github/workflows/job_1.yml
with:
environment: dev
secrets:
environment: dev
job_1_1:
uses: ./.github/workflows/job_1_1.yml
needs: job_1
with:
environment: dev
secrets:
environment: dev
job_2:
uses: ./.github/workflows/job_2.yml
with:
environment: dev
secrets:
environment: dev
job_after_all_done_jobs:
uses: ./.github/workflows/job_after_all_done_jobs.yml
needs: [job_1, job_1_1, job_2]
with:
environment: dev
secrets:
environment: dev
직접 실행해보시면 github.sha의 값이 모든 job에서 동일하게 나오는 것을 보실 수 있습니다.
(github.sha는 github context를 보시면 되겠습니다.)
활용방법은 다양할 것 같습니다.
그럼 이만.
참고자료
https://docs.github.com/en/actions/learn-github-actions/contexts
https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
반응형
'개발 > GIT' 카테고리의 다른 글
[Git] .md에 mermaid 적용 (0) | 2024.09.02 |
---|---|
[GIT] Windows Git Bash profile 설정 (2) | 2021.07.30 |
[Git] Git 기초 (0) | 2021.01.29 |
[GIT] Windows 10 GIT 설치 (0) | 2021.01.28 |
댓글