欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Golang項目在github創(chuàng)建release后自動生成二進制文件的方法

 更新時間:2023年03月18日 10:20:41   作者:路多辛  
這篇文章主要介紹了Golang項目在github創(chuàng)建release后如何自動生成二進制文件,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

希望達(dá)到的效果

工具類的Golang項目需要編譯成二進制文件后在命令行中運行,所以希望在github里面創(chuàng)建一個新的release后能自動編譯成針對各個平臺的二進制文件,如下圖所示:

實現(xiàn)方式

借助 GoReleaser 這款工具配合 github actions 可以很方便實現(xiàn)這種效果,下面講解下具體實現(xiàn)方法。

首先需要在 Golang 項目的根目錄創(chuàng)建 GoReleaser 配置文件 .goreleaser.yaml,內(nèi)容如下:

# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
before:
  hooks:
    # You may remove this if you don't use go modules.
    - go mod tidy
    # you may remove this if you don't need go generate
    - 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:'
 
# The lines beneath this are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

然后創(chuàng)建 github actions 配置文件, 在Golang項目的根目錄創(chuàng)建 .github 文件夾,在這個文件夾里面創(chuàng)建 workflows 文件夾,在 workflows 文件夾里面創(chuàng)建 release.yaml 文件,內(nèi)容如下:

name: goreleaser
 
on:
  push:
    # run only against tags
    tags:
      - '*'
 
permissions:
  contents: write
  # packages: write
  # issues: write
 
jobs:
  goreleaser:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - run: git fetch --force --tags
      - uses: actions/setup-go@v3
        with:
          go-version: '>=1.20.2'
          cache: true
      # More assembly might be required: Docker logins, GPG, etc. It all depends
      # on your needs.
      - uses: goreleaser/goreleaser-action@v4
        with:
          # either 'goreleaser' (default) or 'goreleaser-pro':
          distribution: goreleaser
          version: latest
          args: release --clean
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          # Your GoReleaser Pro key, if you are using the 'goreleaser-pro'
          # distribution:
          # GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}

這個文件的內(nèi)容不需要做任何修改,提交代碼并將代碼 push 到 github 后,在 github 的 release 頁面新建一個 release 后,在 Actions 頁面就可以看到有一個workflow在運行:

等這個 workflow 運行完成以后,在 release 的 Assets 里面就會出現(xiàn)針對各個平臺的二進制文件。

到此這篇關(guān)于Golang項目在github創(chuàng)建release后如何自動生成二進制文件的文章就介紹到這了,更多相關(guān)go自動生成二進制文件內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • golang使用iconv報undefined:XXX的問題處理方案

    golang使用iconv報undefined:XXX的問題處理方案

    這篇文章主要介紹了golang使用iconv報undefined:XXX的問題處理方案,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-03-03
  • golang如何替換換行符

    golang如何替換換行符

    這篇文章主要介紹了golang如何替換換行符問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-07-07
  • Golang實現(xiàn)協(xié)程超時控制的方式總結(jié)

    Golang實現(xiàn)協(xié)程超時控制的方式總結(jié)

    我們知道,go協(xié)程如果不做好處理,很容易造成內(nèi)存泄漏,所以對goroutine做超時控制,才能有效避免這種情況發(fā)生,本文為大家整理了兩個常見的Golang超時控制方法,需要的可以收藏一下
    2023-05-05
  • gRPC的發(fā)布訂閱模式及REST接口和超時控制

    gRPC的發(fā)布訂閱模式及REST接口和超時控制

    這篇文章主要為大家介紹了gRPC的發(fā)布訂閱模式及REST接口和超時控制,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-06-06
  • go module使用本地包的方法示例

    go module使用本地包的方法示例

    這篇文章主要介紹了go module使用本地包的方法示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-03-03
  • Golang使用第三方包viper讀取yaml配置信息操作

    Golang使用第三方包viper讀取yaml配置信息操作

    這篇文章主要介紹了Golang使用第三方包viper讀取yaml配置信息操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-12-12
  • golang抓取網(wǎng)頁并分析頁面包含的鏈接方法

    golang抓取網(wǎng)頁并分析頁面包含的鏈接方法

    今天小編就為大家分享一篇golang抓取網(wǎng)頁并分析頁面包含的鏈接方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-08-08
  • Golang新提案:panic?能不能加個?PanicError?

    Golang新提案:panic?能不能加個?PanicError?

    這篇文章主要為大家介紹了Golang的新提案關(guān)于panic能不能加個PanicError的問題分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-12-12
  • Golang 運算符及位運算詳解

    Golang 運算符及位運算詳解

    這篇文章主要介紹了Golang 運算符及位運算詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-12-12
  • 一文帶你深入探究Go語言中的sync.Map

    一文帶你深入探究Go語言中的sync.Map

    在?Go?語言中,有一個非常實用的并發(fā)安全的?Map?實現(xiàn):sync.Map,它是在?Go?1.9?版本中引入的。本文我們將深入探討?sync.Map?的基本原理,幫助讀者更好地理解并使用這個并發(fā)安全的?Map
    2023-04-04

最新評論