Skip to content

Commit f177cc1

Browse files
committed
feat:增加自动构建
1 parent 04e2569 commit f177cc1

12 files changed

+411
-28
lines changed

.github/release-config.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name-template: 'v$RESOLVED_VERSION'
2+
tag-template: 'v$RESOLVED_VERSION'
3+
categories:
4+
- title: '🌱 新功能 Features'
5+
labels:
6+
- 'feature'
7+
- 'enhancement'
8+
- 'feat'
9+
- '新功能'
10+
- title: '🚀 性能优化 Optimization'
11+
labels:
12+
- 'perf'
13+
- 'opt'
14+
- 'refactor'
15+
- 'Optimization'
16+
- '优化'
17+
- title: '🐛 Bug修复 Bug Fixes'
18+
labels:
19+
- 'fix'
20+
- 'bugfix'
21+
- 'bug'
22+
- title: '🧰 其它 Maintenance'
23+
labels:
24+
- 'chore'
25+
- 'docs'
26+
exclude-labels:
27+
- 'no'
28+
- '无需处理'
29+
- 'wontfix'
30+
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
31+
version-resolver:
32+
major:
33+
labels:
34+
- 'major'
35+
minor:
36+
labels:
37+
- 'minor'
38+
patch:
39+
labels:
40+
- 'patch'
41+
default: patch
42+
template: |
43+
## 版本变化 What’s Changed
44+
45+
$CHANGES
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Build and Push Base Image
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
- 'dev'
8+
paths:
9+
- 'requirements.txt'
10+
- 'Dockerfile-base'
11+
12+
jobs:
13+
build-and-push-base-image:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Set up QEMU
21+
uses: docker/setup-qemu-action@v3
22+
23+
- name: Set up Docker Buildx
24+
uses: docker/setup-buildx-action@v3
25+
26+
- name: Login to DockerHub
27+
uses: docker/login-action@v3
28+
with:
29+
username: ${{ secrets.DOCKERHUB_USERNAME }}
30+
password: ${{ secrets.DOCKERHUB_TOKEN }}
31+
32+
- name: Extract date
33+
id: vars
34+
run: echo "IMAGE_TAG=$(date +'%Y%m%d_%H%M%S')" >> $GITHUB_ENV
35+
36+
- name: Extract repository name
37+
id: repo
38+
run: echo "REPO=$(basename ${{ github.repository }})" >> $GITHUB_ENV
39+
40+
- name: Build and push multi-arch image
41+
uses: docker/build-push-action@v6
42+
with:
43+
platforms: linux/amd64,linux/arm64
44+
push: true
45+
file: Dockerfile-base
46+
tags: nineaiyu/${{ env.REPO }}-base:${{ env.IMAGE_TAG }}
47+
48+
- name: Update Dockerfile
49+
run: |
50+
sed -i 's@nineaiyu/.* AS stage-build@nineaiyu/${{ env.REPO }}-base:${{ env.IMAGE_TAG }} AS stage-build@' Dockerfile
51+
52+
- name: Commit changes
53+
run: |
54+
git config --global user.name 'github-actions[bot]'
55+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
56+
git add Dockerfile
57+
git commit -m "perf: Update Dockerfile with new base image tag"
58+
git push origin ${{ github.event.pull_request.head.ref }}
59+
env:
60+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/build-image.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Build and Push Image
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
8+
jobs:
9+
build-and-push-image:
10+
runs-on: ubuntu-latest
11+
steps:
12+
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Set up QEMU
17+
uses: docker/setup-qemu-action@v3
18+
19+
- name: Set up Docker Buildx
20+
uses: docker/setup-buildx-action@v3
21+
22+
- name: Login to DockerHub
23+
uses: docker/login-action@v3
24+
with:
25+
username: ${{ secrets.DOCKERHUB_USERNAME }}
26+
password: ${{ secrets.DOCKERHUB_TOKEN }}
27+
28+
- name: Extract repository name
29+
id: repo
30+
run: |
31+
echo "REPO=$(basename ${{ github.repository }})" >> $GITHUB_ENV
32+
echo VERSION=$(grep "VERSION " server/const.py | sed "s/.*VERSION = ['|\"]\(.*\)['|\"].*/\1/") >> $GITHUB_ENV
33+
34+
- name: Extract metadata (tags, labels) for Docker
35+
id: meta
36+
uses: docker/metadata-action@v5
37+
with:
38+
images: nineaiyu/${{ env.REPO }}
39+
tags: |
40+
type=semver,pattern={{version}}, value=${{ env.VERSION }}
41+
42+
- name: Build and push multi-arch image
43+
uses: docker/build-push-action@v6
44+
with:
45+
platforms: linux/amd64,linux/arm64
46+
push: true
47+
file: Dockerfile
48+
tags: ${{ steps.meta.outputs.tags }}
49+
labels: ${{ steps.meta.outputs.labels }}
50+
51+
- name: Update docker-compose.yml
52+
run: |
53+
sed -i 's@image: nineaiyu/.*@image: nineaiyu/${{ env.REPO }}:${{ env.VERSION }}@' docker-compose.yml
54+
sed -i 's@image: nineaiyu/.*@image: nineaiyu/${{ env.REPO }}:${{ env.VERSION }}@' docker-compose-sqlite.yml
55+
56+
- name: Commit changes
57+
run: |
58+
git config --global user.name 'github-actions[bot]'
59+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
60+
git add docker-compose.yml docker-compose-sqlite.yml
61+
git commit -m "perf: Update docker-compose.yml with new image tag"
62+
git push origin ${{ github.event.pull_request.head.ref }}
63+
env:
64+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Issue Close Require
2+
3+
on:
4+
schedule:
5+
- cron: "0 0 * * *"
6+
7+
jobs:
8+
issue-close-require:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: need reproduce
12+
uses: actions-cool/issues-helper@v3
13+
with:
14+
actions: 'close-issues'
15+
labels: '⏳ Pending feedback'
16+
inactive-day: 30
17+
body: |
18+
You haven't provided feedback for over 30 days.
19+
We will close this issue. If you have any further needs, you can reopen it or submit a new issue.
20+
您超过 30 天未反馈信息,我们将关闭该 issue,如有需求您可以重新打开或者提交新的 issue。

.github/workflows/issue-close.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Issue Close Check
2+
3+
on:
4+
issues:
5+
types: [closed]
6+
7+
jobs:
8+
issue-close-remove-labels:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Remove labels
12+
uses: actions-cool/issues-helper@v3
13+
if: ${{ !github.event.issue.pull_request }}
14+
with:
15+
actions: 'remove-labels'
16+
labels: '🔔 Pending processing,⏳ Pending feedback'
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
on:
2+
issue_comment:
3+
types: [created]
4+
5+
name: Add issues workflow labels
6+
7+
jobs:
8+
add-label-if-is-author:
9+
runs-on: ubuntu-latest
10+
if: (github.event.issue.user.id == github.event.comment.user.id) && !github.event.issue.pull_request && (github.event.issue.state == 'open')
11+
steps:
12+
- name: Add require handle label
13+
uses: actions-cool/issues-helper@v3
14+
with:
15+
actions: 'add-labels'
16+
labels: '🔔 Pending processing'
17+
18+
- name: Remove require reply label
19+
uses: actions-cool/issues-helper@v3
20+
with:
21+
actions: 'remove-labels'
22+
labels: '⏳ Pending feedback'
23+
24+
add-label-if-is-member:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v4
29+
30+
- name: Get Organization name
31+
id: org_name
32+
run: echo "data=$(echo '${{ github.repository }}' | cut -d '/' -f 1)" >> $GITHUB_OUTPUT
33+
34+
- name: Get Organization public members
35+
uses: octokit/[email protected]
36+
id: members
37+
with:
38+
route: GET /orgs/${{ steps.org_name.outputs.data }}/public_members
39+
env:
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
42+
- name: Process public members data
43+
# 将 members 中的数据转化为 login 字段的拼接字符串
44+
id: member_names
45+
run: echo "data=$(echo '${{ steps.members.outputs.data }}' | jq '[.[].login] | join(",")')" >> $GITHUB_OUTPUT
46+
47+
48+
- run: "echo members: '${{ steps.members.outputs.data }}'"
49+
- run: "echo member names: '${{ steps.member_names.outputs.data }}'"
50+
- run: "echo comment user: '${{ github.event.comment.user.login }}'"
51+
- run: "echo contains? : '${{ contains(steps.member_names.outputs.data, github.event.comment.user.login) }}'"
52+
53+
- name: Add require replay label
54+
if: contains(steps.member_names.outputs.data, github.event.comment.user.login)
55+
uses: actions-cool/issues-helper@v3
56+
with:
57+
actions: 'add-labels'
58+
labels: '⏳ Pending feedback'
59+
60+
- name: Remove require handle label
61+
if: contains(steps.member_names.outputs.data, github.event.comment.user.login)
62+
uses: actions-cool/issues-helper@v3
63+
with:
64+
actions: 'remove-labels'
65+
labels: '🔔 Pending processing'

.github/workflows/issue-open.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Issue Open Check
2+
3+
on:
4+
issues:
5+
types: [opened]
6+
7+
jobs:
8+
issue-open-add-labels:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Add labels
12+
uses: actions-cool/issues-helper@v3
13+
if: ${{ !github.event.issue.pull_request }}
14+
with:
15+
actions: 'add-labels'
16+
labels: '🔔 Pending processing'
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Build and Push Image
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
create-release:
10+
name: Create Release
11+
runs-on: ubuntu-latest
12+
outputs:
13+
upload_url: ${{ steps.create_release.outputs.upload_url }}
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
- name: Get version
18+
id: get_version
19+
run: |
20+
TAG=$(basename ${GITHUB_REF})
21+
echo "{TAG}={$TAG}" >> $GITHUB_OUTPUT
22+
- name: Create Release
23+
id: create_release
24+
uses: release-drafter/release-drafter@v6
25+
env:
26+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27+
with:
28+
config-name: release-config.yml
29+
version: ${{ steps.get_version.outputs.TAG }}
30+
tag: ${{ steps.get_version.outputs.TAG }}
31+
32+
- name: Release Upload Assets
33+
uses: softprops/action-gh-release@v2
34+
if: startsWith(github.ref, 'refs/tags/')
35+
with:
36+
draft: true
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)