自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Golang項(xiàng)目在Github創(chuàng)建Release后如何自動(dòng)生成二進(jìn)制文件?

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

希望達(dá)到的效果

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

實(shí)現(xiàn)方式

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

首先需要在 Golang 項(xiàng)目的根目錄創(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項(xiàng)目的根目錄創(chuàng)建 .github 文件夾,在這個(gè)文件夾里面創(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 }}

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

等這個(gè) workflow 運(yùn)行完成以后,在 release 的 Assets 里面就會(huì)出現(xiàn)針對(duì)各個(gè)平臺(tái)的二進(jìn)制文件。

責(zé)任編輯:姜華 來源: 今日頭條
相關(guān)推薦

2024-02-01 09:04:12

2022-10-31 08:02:42

二進(jìn)制計(jì)算乘法

2009-12-16 10:49:42

Ruby操作二進(jìn)制文件

2009-08-12 18:06:53

C#讀取二進(jìn)制文件

2020-05-06 09:51:37

二進(jìn)制Linux命令行工具

2013-04-28 15:37:35

JBoss

2009-12-10 09:24:50

PHP函數(shù)fwrite

2023-09-18 23:50:25

二進(jìn)制文件裁剪Layout

2022-11-18 10:17:01

2021-11-10 09:15:00

CPU01 二進(jìn)制Linux

2020-05-22 18:00:26

Go二進(jìn)制文件編程語言

2023-12-26 15:10:00

處理二進(jìn)制文件

2009-11-02 11:27:42

VB.NET二進(jìn)制文件

2018-10-22 14:37:16

二進(jìn)制數(shù)據(jù)存儲(chǔ)

2009-02-27 09:37:33

Google二進(jìn)制代碼

2022-07-26 13:00:01

安全符號(hào)源代碼

2017-04-11 10:48:53

JS二進(jìn)制

2010-10-13 15:45:23

MySQL二進(jìn)制日志

2010-06-09 13:02:29

MySQL啟用二進(jìn)制日

2022-01-26 00:02:01

Go二進(jìn)制元信息
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)