惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threat Research - Cisco Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Register - Security
The Register - Security
A
About on SuperTechFans
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
L
LangChain Blog
N
Netflix TechBlog - Medium
量子位
博客园 - 三生石上(FineUI控件)
宝玉的分享
宝玉的分享
H
Help Net Security
D
Docker
D
DataBreaches.Net
T
Tailwind CSS Blog
阮一峰的网络日志
阮一峰的网络日志
B
Blog
博客园 - 聂微东
Apple Machine Learning Research
Apple Machine Learning Research
Google DeepMind News
Google DeepMind News
The Cloudflare Blog
F
Full Disclosure
GbyAI
GbyAI
F
Fortinet All Blogs
Last Week in AI
Last Week in AI
Y
Y Combinator Blog
人人都是产品经理
人人都是产品经理
Recent Announcements
Recent Announcements
博客园 - Franky
MongoDB | Blog
MongoDB | Blog
有赞技术团队
有赞技术团队
博客园 - 叶小钗
小众软件
小众软件
V
Visual Studio Blog
月光博客
月光博客
Stack Overflow Blog
Stack Overflow Blog
The GitHub Blog
The GitHub Blog
Recorded Future
Recorded Future
J
Java Code Geeks
雷峰网
雷峰网
P
Privacy & Cybersecurity Law Blog
C
Cisco Blogs
C
Cyber Attacks, Cyber Crime and Cyber Security
AWS News Blog
AWS News Blog
Webroot Blog
Webroot Blog
美团技术团队
N
News | PayPal Newsroom
G
Google Developers Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
博客园_首页
V
Vulnerabilities – Threatpost

iTimothy

那些让人笑出声的Meme排序算法 再谈费曼学习法 第一性原理读书笔记 我的2025 AWS Certified Developer Associate 认证备考指北 我的 AWS Certified Machine Learning – Specialty 认证之旅 2024年的年终总结:转变与沉淀 迟来的2023年终总结 The Heap Sort Algorithm Explained Modern C++ 学习笔记 -- 左值与右值 告别2022 客制化键盘初体验 RAMA WORKS KARA 聊聊被动收入与躺赚 新加坡驾照转换指北 逝去的2021 使用Caddy2托管静态博客 美股期权投资策略学习笔记--期权的基本概念 我的2020 CKAD认证备考经验分享 Emacs启动加速篇
利用GitHub Actions实现版本自动构建与发布流程
Timothy · 2022-05-03 · via iTimothy

GitHub Actions 是 GitHub 自家推出的持续集成和持续交付工作流服务。自从上次利用GitHub Actions实现Blog自动部署与发布过后,构建和发布blog从此变得轻松。这次,我打算充分利用 GitHub Actions, 把开源项目的持续构建和发布流程做成完全自动化。

用我经常维护的一个项目 GoDNS 举个栗子,每次发布的时候,需要手动执行的两个任务:

  • 基于不同平台进行交叉编译,把编译好的二进制文件分别上传到GitHub上,进行新版本的发布。
  • 另外,这个项目还需要构建基于不同平台的 Docker 镜像,然后推送到 Docker Hub 上。

在使用 GitHub Actions 之前,我的做法就是在本机使用 Makefile 分别构建二进制文件和 Docker 镜像。这一系列操作在 Mac OS 下的结果就是:无法避免的风扇狂转,以及CPU温度的陡然上升。为了减轻笔记本的负担,后来我把构建 Docker 镜像的流程迁移到了VPS上。不过,这也使发布流程略显繁琐。

有了 GitHub Actions,事情就变得简单了,通过设置一个触发流程的事件,就可以用两个并行的流程分别构建二进制文件和 Docker 镜像了:

GoDNS 的构建流程中,触发条件是当每次有新的 tag 被创建的时候。通过把新创建的 tag push 到GitHub,两个 actions 就会并行执行。其中一个 action 负责构建跨平台二进制文件,完成后自动 release 一个相应的新版本。另外一个 action 负责构建 Docker 镜像,并 push 到 Docker Hub。

不得不说,自从用上了 GitHub Actions,我的笔记本被彻底解放了。附上两个自动构建发布流程,供参考。

Workflow 及定义

  1. 二进制包自动构建与发布流程
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
name: Auto Release

on:
push:
tags:
- '*'

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:

distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
  1. Docker 镜像自动构建与发布流程
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
name: Docker Image CI

on:
push:
tags:
- '*'

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Get git tag
id: tag
uses: dawidd6/action-get-tag@v1
with:
strip_v: true
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push the docker image
uses: docker/build-push-action@v2
with:
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
tags: timothyye/godns:latest,timothyye/godns:${{steps.tag.outputs.tag}}