Goreleaser로 Go 패키지 게시
이 자습서에서는 goreleaser를 사용하여 단순
go 패키지의 릴리스를 자동화합니다.설치
macOS에서 goreleaser를 설치하려면 다음을 사용하여 설치할 수 있습니다.
go install github.com/goreleaser/goreleaser@latest
또는 인기 있는homebrew macOS 및 Linux용 패키지 관리자를 다음과 함께 사용합니다.
brew install goreleaser/tap/goreleaser
Ubuntu Linux에서는
apt를 사용할 수 있습니다.echo 'deb [trusted=yes] https://repo.goreleaser.com/apt/ /' | sudo tee /etc/apt/sources.list.d/goreleaser.list
sudo apt update
sudo apt install goreleaser
더 많은 옵션을 찾을 수 있습니다here.
패키지 만들기
프로젝트를 보관할 새 폴더를 만듭니다. 그런 다음 다음을 사용하여 모듈을 초기화하십시오.
go mod init main
다음으로
main.go라는 파일을 만듭니다. main.go에서 다음 코드를 복사하여 붙여넣습니다.package main
func main() {
println("This is a tutorial about Goreleaser!")
}
Goreleaser 초기화
다음 단계는 goreleaser를 설정하는 것입니다. 이를 위해 다음을 실행합니다.
goreleaser init
이 명령은 디렉토리에
.goreleaser.yaml 파일을 생성합니다. 이 파일을 자세히 살펴보겠습니다..goreleaser.yaml 업데이트
생성된
.goreleaser.yaml 파일에 필드를 몇 개 더 추가했습니다. 중요한 부분을 짚어보겠습니다.release:
github:
owner: justdamilare
name: mytool
before:
hooks:
- go mod tidy
- go generate ./...
builds:
- env:
- GO_VERSION=1.19
goos:
- linux
- windows
- darwin
# replaces architecture naming in the archive name
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
format_overrides:
- goos: windows
format: zip
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
# upload binaries to gcloud bucket called `mytool`
blobs:
- provider: gs
bucket: mytool
folder: "{{ .Version }}"
# generate homebrew-tap
brews:
- name: justdamilare
tap:
owner: mytool
name: homebrew-tap
folder: Formula
homepage: https://github.com/justdamilare/mytool
description: A simple go project
# use custom download strategy in case the Github repository is private
download_strategy: GitHubPrivateRepositoryReleaseDownloadStrategy
custom_require: "../custom_download_strategy"
test: |
system "#{bin}/mytool"
install: |
bin.install "mytool"
homebrew-tap 및 blobs가 필요하지 않은 경우 섹션을 제거할 수 있습니다. homebrew-tap가 필요한 경우 homebrew-tap라는 Gitib 저장소도 생성해야 합니다.릴리스 패키지
마지막으로 패키지를 릴리스할 수 있습니다. 이를 위해서는 Git에서 릴리스에 대한 태그를 생성해야 합니다. 예를 들어 버전
0.1.0에 대한 태그를 생성하려면 다음을 실행할 수 있습니다.git tag v0.1.0
그리고
git push origin v0.1.0
그런 다음
main.go가 있는 디렉터리에서 다음을 실행합니다.goreleaser release
Goreleaser는 모든 바이너리를 빌드합니다. 이러한 바이너리는 로컬 GitHub 자격 증명을 사용하여 Github에 자동으로 업로드됩니다. 빌드는 홈 디렉터리의
/dist 폴더에도 있습니다. brew 게시 방법이 포함된 경우 생성된 *.rb 파일도 /dist 폴더에 있습니다. Goreleaser가 생성된 Formula를 homebrew-tap repo에 자동으로 복사하지 않는 경우 수동으로 복사할 수 있습니다. 비공개 홈브류 탭에 빌드를 게시하는 방법을 확인할 수 있습니다here.요약
goreleaser init로 Goreleaser 초기화.goreleaser.yaml git tag vX.X.X로 태그를 생성하여 빌드를 릴리스한 다음 goreleaser release를 실행합니다.Reference
이 문제에 관하여(Goreleaser로 Go 패키지 게시), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/justdamilare/publish-go-packages-with-goreleaser-2nej텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)