Skip to content

Commit

Permalink
Merge pull request #40 from Leizhenpeng/feat-ci
Browse files Browse the repository at this point in the history
chore: add binary release and Docker Hub support
  • Loading branch information
Leizhenpeng authored Mar 6, 2023
2 parents af6c4fa + 0690a2a commit b68d8b2
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 49 deletions.
26 changes: 26 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
name: 问题交流
about: 有任何问题,都可以在这里交流。
title: "[问题] "
labels: ["question"]
---

# 问题交流 💬

有任何问题,都可以在这里交流哦~

## 问题是什么呢? 🤔

请详细地描述你遇到的问题,包括出现问题的环境和步骤,以及你已经尝试过的解决方法。

另外,如果你在解决问题时已经查看过其他 GitHub Issue,请务必在文本中说明并引用相关信息。

## 附加信息 📝

请提供以下信息以帮助我们更快地解决问题:

- 输出日志,包括错误信息和堆栈跟踪
- 相关的代码片段或文件
- 你的操作系统、golang 版本等环境信息

谢谢你的反馈!🙏
6 changes: 6 additions & 0 deletions .github/pull-request-template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!-- 请务必在创建PR前,在右侧 Labels 选项中加上label的其中一个: [feature]、[fix]、[documentation]、[dependencies]、[test] 。以便于Actions自动生成Releases时自动对PR进行归类。-->


**填写PR内容:**

-
42 changes: 42 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Configuration for Release Drafter: https://github.com/toolmantim/release-drafter
name-template: 'v$NEXT_PATCH_VERSION 🌈'
tag-template: 'v$NEXT_PATCH_VERSION'
version-template: $MAJOR.$MINOR.$PATCH
# Emoji reference: https://gitmoji.carloscuesta.me/
categories:
- title: 🚀 Features
labels:
- 'feature'
- 'enhancement'
- 'kind/feature'
- title: 🚑️ Bug Fixes
labels:
- 'fix'
- 'bugfix'
- 'bug'
- 'regression'
- 'kind/bug'
- title: 📝 Documentation updates
labels:
- 'doc'
- 'documentation'
- 'kind/doc'
- title: 👷 Maintenance
labels:
- chore
- dependencies
- 'kind/chore'
- 'kind/dep'
- title: 🚦 Tests
labels:
- test
- tests
exclude-labels:
- reverted
- no-changelog
- skip-changelog
- invalid
change-template: '* $TITLE (#$NUMBER) @$AUTHOR'
template: |
## What’s Changed
$CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ name: Build Release

on:
release:
types: [created]
types: [created,published]

permissions:
contents: read

jobs:
build-go-binary:
permissions:
contents: write # for build-go-binary
runs-on: ubuntu-latest
strategy:
matrix:
goos: [linux, windows]
goarch: [amd64, arm64]
exclude:
goos: [ linux, windows, darwin ] # 需要打包的系统
goarch: [ amd64, arm64 ] # 需要打包的架构
exclude: # 排除某些平台和架构
- goarch: arm64
goos: windows
steps:
Expand All @@ -27,13 +27,13 @@ jobs:
- name: Parallel build
uses: wangyoucao577/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
goversion: 1.18
pre_command: export CGO_ENABLED=0 && export GODEBUG=http2client=0
executable_compression: "upx -9"
md5sum: false
project_path: "./code"
binary_name: "start-feishubot"
extra_files: ./code/config.example.yaml
binary_name: "feishu-chatgpt"
extra_files: ./code/config.example.yaml readme.md
76 changes: 44 additions & 32 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,59 @@
name: Docker Publish
name: build docker image

# 仅在release时触发
on:
push:
branches:
- master

env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
release:
types: [created,published]

# 可以手动触发
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
tags:
description: 'Test scenario tags'

jobs:
build-and-publish:
buildx:
runs-on: ubuntu-latest
strategy:
matrix:
architecture: [ amd64, arm64 ]

steps:
- name: Checkout code
- name: Checkout
uses: actions/checkout@v2

- name: Login to Docker Hub
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1

- name: Available platforms
run: echo ${{ steps.buildx.outputs.platforms }}

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ env.DOCKER_USERNAME }}
password: ${{ env.DOCKER_PASSWORD }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Set up Go
uses: actions/setup-go@v2
- name: Build and push
uses: docker/build-push-action@v2
with:
go-version: '1.18'

- name: Install dependencies
run:
cd ./code && go mod tidy

- name: Build Docker image
run: |
docker build -t feishu-chatgpt:${{ matrix.architecture }}-${{ github.sha }} --build-arg ARCHITECTURE=${{ matrix.architecture }} .
- name: Push Docker image to Docker Hub
run: |
docker tag feishu-chatgpt:${{ matrix.architecture }}-${{ github.sha }} ${{ env.DOCKER_USERNAME }}/feishu-chatgpt:${{ matrix.architecture }}-${{ github.sha }}
docker tag feishu-chatgpt:${{ matrix.architecture }}-${{ github.sha }} ${{ env.DOCKER_USERNAME }}/feishu-chatgpt:${{ matrix.architecture }}-latest
docker push ${{ env.DOCKER_USERNAME }}/feishu-chatgpt:${{ matrix.architecture }}-${{ github.sha }}
docker push ${{ env.DOCKER_USERNAME }}/feishu-chatgpt:${{ matrix.architecture }}-latest
context: .
file: ./Dockerfile
# 所需要的体系结构,可以在 Available platforms 步骤中获取所有的可用架构
platforms: linux/amd64,linux/arm64/v8
# 镜像推送时间
push: ${{ github.event_name != 'pull_request' }}
# 给清单打上多个标签
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.GITHUB_REPOSITORY_NAME_PART }}:${{ env.GITHUB_REF_NAME }}
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.GITHUB_REPOSITORY_NAME_PART }}:latest
38 changes: 38 additions & 0 deletions .github/workflows/release-draft.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Release Drafter

on:
push:
# branches to consider in the event; optional, defaults to all
branches:
- master
# pull_request event is required only for autolabeler
pull_request:
# Only following types are handled by the action, but one can default to all as well
types: [opened, reopened, synchronize]
# pull_request_target event is required for autolabeler to support PRs from forks
# pull_request_target:
# types: [opened, reopened, synchronize]

permissions:
contents: read

jobs:
update_release_draft:
permissions:
contents: write # for release-drafter/release-drafter to create a github release
pull-requests: write # for release-drafter/release-drafter to add label to PR
runs-on: ubuntu-latest
steps:
# (Optional) GitHub Enterprise requires GHE_HOST variable set
#- name: Set GHE_HOST
# run: |
# echo "GHE_HOST=${GITHUB_SERVER_URL##https:\/\/}" >> $GITHUB_ENV

# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: release-drafter/release-drafter@v5
# (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml
# with:
# config-name: my-config.yml
# disable-autolabeler: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
10 changes: 4 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,11 @@ docker run -d --restart=always --name feishu-chatgpt2 -p 9000:9000 -v /etc/local
--env APP_VERIFICATION_TOKEN=xxx \
--env BOT_NAME=chatGpt \
--env OPENAI_KEY=sk-xxx \
leizhenpeng/feishu-chatgpt:amd64-latest

//如果mac替换为
//leizhenpeng/feishu-chatgpt:arm64-latest
dockerproxy.com/leizhenpeng/feishu-chatgpt:latest
```
事件回调地址是: http://IP:9000/webhook/event
卡片回调地址是: http://IP:9000/webhook/card

事件回调地址: http://IP:9000/webhook/event
卡片回调地址: http://IP:9000/webhook/card

把它填入飞书后台
<br>
Expand Down
4 changes: 2 additions & 2 deletions s.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
edition: 1.0.0
name: hello-world-app
name: feishuBot-chatGpt
access: "aliyun" # 秘钥别名

vars: # 全局变量
region: "cn-hangzhou"
region: "cn-hongkong"

services:
helloworld:
Expand Down

0 comments on commit b68d8b2

Please sign in to comment.