GitHub Actions workflow 설정해보기!

Seungrok Yoon (Lethe)·2023년 9월 5일
1

(2023.09.05) - 작성중

학습의 계기 - 수동으로 이슈라벨을 다는 것에 대한 불편함

깃헙 이슈 기반 팀 프로젝트를 진행하면서 이슈와 PR을를 생성하는 작업에서 번거로움을 느꼈다.

이슈와 PR 내용을 채우는 것은 템플릿 을 추가하여 어느 정도 보완이 가능하지만,

  • 라벨을 다는 것
  • assignee를 설정하는 것
  • 프로젝트 칸반보드에 연결하는 작업

등의 행위들은 다 마우스로 일일이 클릭해줘야 하는 일들이었다.

나조차도 가끔 까먹어서 팀장님이 대신 라벨을 달아준 적이 있다. 팀원들이 많아질수록 이런 휴먼 에러는 많아질 것이다.

Github Actions workflow를 들어본 적이 있다. CI/CD에 사용되는 녀석이라고만 알고 있었다.

그런데 Github Actions에서 CI/CD 뿐 아니라 이벤트 설정을 통해 다양한 작업들을 자동화시킬 수 있다는 것을 알게 되었다.

이번 기회에 자동화 시스템을 통해 통해 휴먼 에러를 방지해 보자.

레츠고~!

Github Actions workflow를 통해 레포지토리에 자동화를 더하자

목표는 아래와 같다.

  • GitHub Workflow, GitHubActions 개념 이해하기
  • 이슈 생성시마다 자동으로 라벨과 assignee 달아주기, Project 칸반보드 연결해주기!
  • PR 생성시마다 자동으로 라벨과 assignee 달아주기, Project 칸반보드 연결해주기!

Understanding Github Actions

그래...! 난 이슈에 라벨을 자동으로 다는 작업을 하고 싶었단 말이야!

GitHub Actions goes beyond just DevOps and lets you run workflows when other events 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 Actions workflow 개념 이해하기

Workflows

GitHub Workflow의 5가지 핵심요소

  • Workflows
  • Events
  • Jobs
  • Actions
  • Runners

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 and will run when triggered by an event in your repository, or they can be triggered manually, or at a defined schedule.

Workflows are defined in the .github/workflows directory in a repository, and a repository can have multiple workflows, each of which can perform a different set of tasks. For example, you can have one workflow to build and test pull requests, another workflow to deploy your application every time a release is created, and still another workflow that adds a label every time someone opens a new issue.

Workflow은 하나, 또는 그 이상의 작업을 실행시키는 자동화된 프로세스이구나. 프로세스 단위가 워크플로우네.

아하, Github workflowsms configurable (설정이 가능)하고, .github/workflows디렉토리를 추가해주면 되는구나, 그리고 그 안에 YAML파일로 무언가 명시해주면 되는 거구나!

Events

An event is a specific activity in a repository that triggers a workflow run.

특정 워크플로우가 동작하기 위해서 레포지토리에서 가장 최초로 발동되어야 하는 작업인 셈이다. 이벤트들에는, PR, 이슈, 커밋활동들이 다 이벤트가 될수 있다.

Events that trigger workflows 참고!

Jobs

A job is a set of steps in a workflow that is executed on the same runner.

같은 러너 상에서 실행되는 워크플로우 내부의 세부적인 작업 단계들이다.

각각의 Job은 쉘 스크립트 또는 action으로 이루어져있다.
Job들은 순서대로 실행이 되고, 서로의 작업은 의존성을 가진다.

Job들은 동일한 러너 상에서 실행이 되기 때문에, 데이터를 잡들끼리 공유할 수도 있다!

기본적으로 잡들은 독립적으로 처리가 된다.

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.

You can write your own actions, or you can find actions to use in your workflows in the GitHub Marketplace.

반복 작업들이다.특정 워크플로우에 직접 내가 액션을 기입할 수도 있지만, 필요에 따라 마켓플레이스에서 누군가가 이미 작성한 액션을 가져와서 사용할 수도 있다.

Runners

A runner is a server that runs your workflows when they're triggered. Each runner can run a single job at a time. GitHub provides Ubuntu Linux, Microsoft Windows, and macOS runners to run your workflows; each workflow run executes in a fresh, newly-provisioned virtual machine. GitHub also offers larger runners, which are available in larger configurations. For more information, see "About larger runners." If you need a different operating system or require a specific hardware configuration, you can host your own runners. For more information about self-hosted runners, see "Hosting your own runners."

러너는 내 워크플로우 잡을 실행하는 서버이다. 이 서버들은 가상 머신이며, 이 가상 머신에 대한 사양은 사용자가 별도로 설정할 수도 있다.

이슈 생성시마다 자동으로 라벨과 assignee 달아주기, Project 칸반보드 연결해주기!

그러면 이제 위 5가지 요소들을 가지고 실제 워크플로우를 작성해보자.

YAML 파일을 .github/workflows파일 안에 넣고 작성하자.

https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#issues

https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#using-activity-types

https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions#understanding-the-workflow-file

name: assign-issue-pr-to-creator
run-name: ${{ github.actor }} is assingned an issue and pr
on:
	issues:
    	types: [opened]
	pull_request:
    	types: [opened, ready_for_review]
        
jobs:
  assign:
    runs-on: ubuntu-latest
    steps:
(작성중)

토큰을 등록하기

깃헙 액션을 등록하기 위해서는 내 토큰이 레포지토리에 등록이 되어 있어야 한다.

https://docs.github.com/en/actions/security-guides/automatic-token-authentication

PR 생성시마다 자동으로 라벨과 assignee 달아주기, Project 칸반보드 연결해주기!

profile
안녕하세요 개발자 윤승록입니다. 내 성장을 가시적으로 기록하기 위해 블로그를 운영중입니다.

0개의 댓글