본문 바로가기
카테고리 없음

깃허브(Github) 릴리즈 간편하게 하기 'aktau/github-release' 사용

by 왕 달팽이 2020. 3. 7.
반응형

깃허브(Github)에는 릴리즈 기능이 있습니다. 깃허브를 통해 협업을 하는 소스코드의 결과물을 공유할 수 있는 기능입니다.

깃허브 웹 페이지에 가보면 릴리즈를 위한 페이지를 찾아 볼 수 있습니다. 이 곳에서 'Create a new release' 버튼을 눌러서 빌드한 바이너리와 함께 릴리즈 노트를 작성하여 배포할 수 있습니다. 별도의 배포 웹 서버나 웹 페이지, FTP 서버를 운영하지 않아도 간편하게 결과물을 배포할 수 있습니다.

하지만 웹 페이지를 통해서 매번 릴리즈 버튼을 누르고 파일을 업로드하는 행위는 넘모 귀찮습니다. 우리는 게으르기 위해서 부지런한 개발자들이죠. release.sh 스크립트를 수행하면 자동으로 버전 관리도 해주고, 소스코드를 빌드해서 결과물을 깃허브 릴리즈 페이지로 업로드해줬으면 좋겠습니다. (릴리즈 노트도 커밋 로그에서 추출해 자동으로 업로드했으면 좋겠습니다.)

이럴때 사용하면 좋은게 'aktau/github-release' 입니다.

github-release

깃허브에 공개되어 있는 'aktau/github-release'는 CLI 환경을 이용해 깃허브 릴리즈를 쉽게 할 수 있는 기능을 제공합니다. 'github-release' 명령을 통해서 깃허브 릴리즈 페이지에 파일을 업로드하고, 릴리즈 노트를 수정 할 수 있습니다. (아마 내부적으로는 github api를 이용하는 것 같습니다.)

github-release 설치하기

aktau/github-release를 사용하기 위해서는 go 언어 실행 환경이 설치되어 있어야 합니다. go 환경을 설치하는 것은 따로 설명드리지는 않겠습니다.

go 언어 실행 환경이 세팅되었으면 다음을 실행하면 됩니다.

go get github.com/aktau/github-release

go 언어의 가장 큰 장점인 손쉬운 라이브러리 설치죠. 이 명령하나면 github-release가 설치됩니다. (go get으로 가즈아~) 

Bash에서 github-release --help 를 실행해봅시다. (맥북에서는 $PATH 환경변수에 안잡혀서 명령어를 찾지 못 하던데, ~/go/bin에 가보면 바이너리가 있습니다. $GOPATH를 PATH 환경 변수로 잡아줍시다.)

github-release 사용 1 - GITHUB_API 환경변수

깃허브 엔터프라이즈를 사용하는 경우 퍼블릿 깃허브가 아닌 별도의 API URL이 있을겁니다. 이 깃허브 API URL을 'GITHUB_API' 환경변수로 설정해줍니다.

export GITHUB_API=http://github.your-company.com/api/v3

github-release 사용 2 - AccessToken 설정

깃허브 엔터프라이즈의 github api 를 사용하려면 Personal AccessToken을 받아와야 합니다. 깃허브에 수행할 릴리즈 업로드 동작을 웹 페이지에서는 ID/PW를 이용해서 로그인 후 수행했는데요. 이를 AccessToken을 이용해 할 수 있습니다. (AccessToken을 ID/PW처럼 생각하면 됩니다.)

깃허브 화면의 우측 상단 프로필 사진을 클릭하면 메뉴가 나옵니다. 'setting' - 'Personal Access Token'에 들어가면 토큰을 생성할 수 있습니다. 토큰을 생성할 때, 토큰이 할 수 있는 권한들을 설정할 수 있는데요. 필요한 것들만 설정하시기 바랍니다.

이 곳에서 생성한 토큰을 GITHUB_TOKEN 환경변수로 설정해줍니다.

export GITHUB_TOKEN=?????

github-release 사용법

github-release의 --help 옵션을 실행하면 각종 옵션들에 대해서 알수 있습니다.

$ ./github-release --help
Usage: github-release [global options] <verb> [verb options]

Global options:
        -h, --help           Show this help
        -v, --verbose        Be verbose
        -q, --quiet          Do not print anything, even errors (except if --verbose is specified)
            --version        Print version

Verbs:
    delete:
        -s, --security-token Github token (required if $GITHUB_TOKEN not set)
        -u, --user           Github repo user or organisation (required if $GITHUB_USER not set)
        -r, --repo           Github repo (required if $GITHUB_REPO not set)
        -t, --tag            Git tag of release to delete (*)
    download:
        -s, --security-token Github token ($GITHUB_TOKEN if set). required if repo is private.
        -u, --user           Github repo user or organisation (required if $GITHUB_USER not set)
        -r, --repo           Github repo (required if $GITHUB_REPO not set)
        -l, --latest         Download latest release (required if tag is not specified)
        -t, --tag            Git tag to download from (required if latest is not specified) (*)
        -n, --name           Name of the file (*)
    edit:
        -s, --security-token Github token (required if $GITHUB_TOKEN not set)
        -u, --user           Github repo user or organisation (required if $GITHUB_USER not set)
        -r, --repo           Github repo (required if $GITHUB_REPO not set)
        -t, --tag            Git tag to edit the release of (*)
        -n, --name           New name of the release (defaults to tag)
        -d, --description    New release description, use - for reading a description from stdin (defaults to tag)
            --draft          The release is a draft
        -p, --pre-release    The release is a pre-release
    info:
        -s, --security-token Github token ($GITHUB_TOKEN if set). required if repo is private.
        -u, --user           Github repo user or organisation (required if $GITHUB_USER not set)
        -r, --repo           Github repo (required if $GITHUB_REPO not set)
        -t, --tag            Git tag to query (optional)
        -j, --json           Emit info as JSON instead of text
    release:
        -s, --security-token Github token (required if $GITHUB_TOKEN not set)
        -u, --user           Github repo user or organisation (required if $GITHUB_USER not set)
        -r, --repo           Github repo (required if $GITHUB_REPO not set)
        -t, --tag            Git tag to create a release from (*)
        -n, --name           Name of the release (defaults to tag)
        -d, --description    Release description, use - for reading a description from stdin (defaults to tag)
        -c, --target         Commit SHA or branch to create release of (defaults to the repository default branch)
            --draft          The release is a draft
        -p, --pre-release    The release is a pre-release
    upload:
        -s, --security-token Github token (required if $GITHUB_TOKEN not set)
        -u, --user           Github repo user or organisation (required if $GITHUB_USER not set)
        -r, --repo           Github repo (required if $GITHUB_REPO not set)
        -t, --tag            Git tag to upload to (*)
        -n, --name           Name of the file (*)
        -l, --label          Label (description) of the file
        -f, --file           File to upload (use - for stdin) (*)
        -R, --replace        Replace asset with same name if it already exists (WARNING: not atomic, failure to upload will remove the original asset too)

사용법은 위 화면에서 볼 수 있는 것과 같은데요. 이런거보다 예제를 통해서 알아보겠습니다.

github-release 사용예 - 릴리즈 정보 확인

info 명령을 입력하면 릴리즈 정보를 확인할 수 있습니다.

github-release info --user ${USER_NAME} --repo ${REPO_NAME} --tag ${TAG}

${USER_NAME}에는 깃허브 사용자 이름 혹은 Oraganization 이름을 명시하면 됩니다. ${REPO_NAME}에는 리파지토리 이름을 입력하면 되고, ${TAG_NAME}에는 릴리즈 된 릴리즈 번호 혹은 태그 이름을 입력하면 됩니다.

github-release 사용예 - 릴리즈 작성

release 명령을 입력하면 릴리즈를 작성할 수 있습니다.

github-release release \
    --user ${USER_NAME} \
    --repo ${REPO_NAME} \
    --tag ${TAG} \
    --name "Release Name" \
    --description "Release description(Release note)" \
    --draft

--draft 옵션을 주면 릴리즈가 초안 형식으로 만들어집니다.

github-release 사용예 - 릴리즈 수정

작성한 릴리즈 내용이 마음에 안들경우 수정할 수 있습니다. 'edit' 명령을 이용하면 됩니다.

github-release edit \
    --user ${USER_NAME} \
    --repo ${REPO_NAME} \
    --tag ${TAG} \
    --name "${RELEASE_NAME}" \
    --description "${RELEASE_DESCRIPTION}"

github-release 사용예 - 파일 업로드

빌드한 결과물을 업로드 할 수도 있습니다. 'upload' 명령을 이용하세요.

github-release upload \
    --user ${USER_NAME} \
    --repo ${REPO_NAME} \
    --tag ${TAG} \
    --name "${FILE_NAME}" \
    --file ${FILE_PATH}

github-release 사용예 - 릴리즈 삭제

delete 명령을 이용해서 릴리즈를 삭제할 수도 있습니다.

github-release delete \
    --user ${USER_NAME} \
    --repo ${REPO_NAME} \
    --tag ${TAG}

 

반응형

댓글