首页 最新 热门 推荐

  • 首页
  • 最新
  • 热门
  • 推荐

如何将github开源项目发布

  • 25-03-05 12:41
  • 2495
  • 13835
blog.csdn.net

如何将github开源项目发布

当我们的开源项目完成后,如果是一些可执行程序,就最好要将开源项目发布生成Releases,Releases包含各个系统架构的分发二进制,用户可以不用源码编译安装,而是直接下载安装,这样可以提高开源项目的用户体检。我们可以使用goreleaser这个开源工具帮我们快速发布项目。本文将介绍goreleaser的基本使用。

在这里插入图片描述

安装

$ go install github.com/goreleaser/goreleaser@latest
  • 1

使用go install命令安装需要安装Go,可以去https://go.dev/dl/ 下载安装即可

使用步骤

  1. 创建github项目并克隆到本地
git clone [email protected]:jagitch/go-downloader.git
  • 1
  1. 初始化go项目
cd go-downloader
go mod init jagitch/go-downloader
touch main.go
  • 1
  • 2
  • 3
  1. 编写应用
package main

func main() {
    println("Hello, Welcome to Go downloader v0.0.0!")
}
  • 1
  • 2
  • 3
  • 4
  • 5
  1. 初始化goreleaser
$ goreleaser init
  • Generating .goreleaser.yaml file
  • config created; please edit accordingly to your needs file=.goreleaser.yaml
  • thanks for using goreleaser!
  • 1
  • 2
  • 3
  • 4

将会生成.goreleaser.yaml文件

before:
  hooks:
    - go mod tidy
    - go generate ./...
builds:
  - env:
      - CGO_ENABLED=0
    goos:
      - linux
      - windows
      - darwin

archives:
  - format: tar.gz
    # this name template makes the OS and Arch compatible with the results of uname.
    name_template: >-
      {{ .ProjectName }}_
      {{- title .Os }}_
      {{- if eq .Arch "amd64" }}x86_64
      {{- else if eq .Arch "386" }}i386
      {{- else }}{{ .Arch }}{{ end }}
      {{- if .Arm }}v{{ .Arm }}{{ end }}
    # use zip for windows archives
    format_overrides:
    - goos: windows
      format: zip
checksum:
  name_template: 'checksums.txt'
snapshot:
  name_template: "{{ incpatch .Version }}-next"
changelog:
  sort: asc
  filters:
    exclude:
      - '^docs:'
      - '^test:'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36

build.goos 可以配置生成多个系统的发行包

  1. 在本地构建发布包,文件输出到dist目录
$ goreleaser release --snapshot --clean
  • 1
  1. 修改.goreleaser.yaml符合自己需求,然后执行check检查该文件是否正确
$ goreleaser check
  • 1
  1. 登录到github,打开settings -> Developer settinng -> Personal access tokens创建访问Token

  2. 设置GITHUB_TOKEN环境变量

export GITHUB_TOKEN="ghp_HHKqB7olfSYrIf6e0NUQIGaE1iAFoS3fSuX1"
  • 1
  1. 提交代码并创建tag
git add .
git commit -m "feature x is finished"
git push
git tag -a v0.0.1 -m "version v0.0.1"
git push origin v0.0.1
  • 1
  • 2
  • 3
  • 4
  • 5

注意,在发布之前一定要先执行此步骤提交代码和tag

  1. 执行发布
goreleaser release --clean
  • 1

此条命令将会把二进制等发布到github上

执行此命令前必须先按第8步骤的顺序提交对应版本代码,创建对应版本tag,并push到远程仓库,否则发布的版本名称是新的但是代码却是上一次提交的代码。

Changelog是根据commit信息生成的,内容是基于上一个Release来的,即上一个Realse对应的commit到最新的commit之间的提交信息会体现在Changelog中。

推荐阅读

1. Go语言中局部变量的逃逸分析(从汇编的角度)
2. 使用VS Code调试Go程序
3. 使用树梅派搭建Golang、Python、NodeJs的开发服务器

文章知识点与官方知识档案匹配,可进一步学习相关知识
Go技能树首页概览4816 人正在系统学习中
注:本文转载自blog.csdn.net的gopyer的文章"https://blog.csdn.net/fuxily/article/details/139218891"。版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。如有侵权,请联系我们删除。
复制链接
复制链接
相关推荐
发表评论
登录后才能发表评论和回复 注册

/ 登录

评论记录:

未查询到任何数据!
回复评论:

分类栏目

后端 (14832) 前端 (14280) 移动开发 (3760) 编程语言 (3851) Java (3904) Python (3298) 人工智能 (10119) AIGC (2810) 大数据 (3499) 数据库 (3945) 数据结构与算法 (3757) 音视频 (2669) 云原生 (3145) 云平台 (2965) 前沿技术 (2993) 开源 (2160) 小程序 (2860) 运维 (2533) 服务器 (2698) 操作系统 (2325) 硬件开发 (2492) 嵌入式 (2955) 微软技术 (2769) 软件工程 (2056) 测试 (2865) 网络空间安全 (2948) 网络与通信 (2797) 用户体验设计 (2592) 学习和成长 (2593) 搜索 (2744) 开发工具 (7108) 游戏 (2829) HarmonyOS (2935) 区块链 (2782) 数学 (3112) 3C硬件 (2759) 资讯 (2909) Android (4709) iOS (1850) 代码人生 (3043) 阅读 (2841)

热门文章

101
推荐
关于我们 隐私政策 免责声明 联系我们
Copyright © 2020-2024 蚁人论坛 (iYenn.com) All Rights Reserved.
Scroll to Top