Github Actions Hello World

Page content

개요

  • Github Actions 에서 Hello World를 출력하도록 한다.

강의소개

  • 인프런에서 Streamlit 관련 강의를 진행하고 있습니다.

사전준비

  • Github에 적당한 Repo를 준비한다.

메뉴선택

  • 아래 그림에서 Actions 메뉴를 선택한다.

Untitled

  • 아래 그림에서 set up a workflow yourself 선택

Untitled

YAML 파일 수정

  • .github/workflows/main.yaml 파일 선택 후 수정

Untitled

  • 소스코드는 다음과 같이 지정한다.
# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the "main" branch
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# 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 "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v3

      # Runs a single command using the runners shell
      - name: Run a one-line script
        run: echo Hello, world!

      # Runs a set of commands using the runners shell
      - name: Run a multi-line script
        run: |
          echo Add other actions to build,
          echo test, and deploy your project.          

Git Commit

  • 아래 그림에서 Commit changes 버튼을 선택한다.

Untitled

  • 커밋을 진행한다. Commit changes 버튼 클릭

Untitled

Actions 메뉴 확인

  • 만약 아래 그림과 같이 나오면 Enable Actions on this repository 버튼 클릭

Untitled

  • CI 버튼 클릭 후, Jobs/build 버튼 클릭

Untitled

Untitled

  • YAML에서 작성한 코드 내용이 출력되는 것 확인

Untitled

Python 버전 확인 yml 파일 생성

  • 코드는 다음과 같이 진행한다. (파일명 : python-hello.yml)
# This is a basic workflow to help you get started with Actions
name: Python-CI

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the "main" branch
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# 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 "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v3

      # Runs a single command using the runners shell
      - name: Python Version Check
        run: python -V
  • 간단하게 README.md 파일을 수정하고 다시 Commit을 한다.
  • 아래와 같은 화면에소 Run workflow 를 실행한다.

Untitled

  • Python Version Check가 정상적으로 있는지 확인한다.

Untitled