Skip to content

Commit 6691b47

Browse files
committed
ci: auto-generating LICENSE
1 parent 8914158 commit 6691b47

File tree

7 files changed

+176
-142
lines changed

7 files changed

+176
-142
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 141 deletions
This file was deleted.

.github/workflows/docker.yaml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Docker Build and Push
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
inputs:
9+
version:
10+
description: 'Docker image version (e.g., v1.1.0). If empty, auto-increment.'
11+
required: false
12+
default: ''
13+
14+
permissions:
15+
contents: read
16+
17+
env:
18+
REGISTRY: docker.io
19+
USERNAME: boyuanclub
20+
IMAGE_NAME: meowpick-backend
21+
22+
jobs:
23+
build:
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v3
29+
with:
30+
fetch-depth: 0
31+
32+
# 1. 版本号逻辑
33+
- name: Determine Version
34+
run: |
35+
if [ -n "${{ github.event.inputs.version }}" ]; then
36+
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV
37+
exit 0
38+
fi
39+
40+
tags=$(curl -s "https://hub.docker.com/v2/repositories/${{ env.USERNAME }}/${{ env.IMAGE_NAME }}/tags?page_size=100" | jq -r '.results[].name')
41+
latest=$(echo "$tags" | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n 1)
42+
43+
if [ -z "$latest" ]; then
44+
next_version="v1.0.0"
45+
else
46+
base=${latest%.*}
47+
patch=${latest##*.}
48+
next_patch=$((patch + 1))
49+
next_version="${base}.${next_patch}"
50+
fi
51+
52+
echo "VERSION=$next_version" >> $GITHUB_ENV
53+
54+
# 2. Docker build & push
55+
- name: Setup Docker buildx
56+
uses: docker/setup-buildx-action@v3
57+
58+
- name: Log into registry
59+
uses: docker/login-action@v3
60+
with:
61+
registry: ${{ env.REGISTRY }}
62+
username: ${{ env.USERNAME }}
63+
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
64+
65+
- name: Build and push Docker image
66+
uses: docker/build-push-action@v5
67+
with:
68+
context: .
69+
push: true
70+
tags: |
71+
${{ env.REGISTRY }}/${{ env.USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}
72+
${{ env.REGISTRY }}/${{ env.USERNAME }}/${{ env.IMAGE_NAME }}:latest

.github/workflows/gen.yaml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Generate Swagger & License
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: write # 允许 commit & push
11+
12+
jobs:
13+
generate:
14+
# 避免死循环
15+
if: |
16+
github.event_name == 'workflow_dispatch' ||
17+
(github.event_name == 'push' && !contains(github.event.head_commit.message, '[skip ci]'))
18+
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v3
24+
with:
25+
fetch-depth: 0
26+
token: ${{ secrets.ADMIN_PAT }}
27+
28+
# 1. 安装工具
29+
- name: Setup Go
30+
uses: actions/setup-go@v5
31+
with:
32+
go-version: '1.25.5'
33+
34+
- name: Install tools
35+
run: |
36+
go install github.com/swaggo/swag/cmd/swag@latest
37+
go install github.com/google/addlicense@latest
38+
39+
# 2. 生成代码
40+
- name: Generate Swagger and License
41+
run: |
42+
make swagger
43+
make license
44+
45+
# 3. 自动提交
46+
- name: Commit generated files
47+
run: |
48+
git config user.name "github-actions[bot]"
49+
git config user.email "github-actions[bot]@users.noreply.github.com"
50+
51+
git add docs/
52+
git add .
53+
54+
if ! git diff --staged --quiet; then
55+
git commit -m "chore(ci): auto-generate swagger & license [skip ci]"
56+
git push
57+
else
58+
echo "No generated changes detected."
59+
fi

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/.idea
22
/etc
33
/docker-compose.yml
4-
/Makefile
54
/vendor/
65
/scripts/
76
/data/

Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.PHONY: license wire swagger
2+
3+
license:
4+
@ROOT=$$(git rev-parse --show-toplevel); \
5+
echo "Generating LICENSE..."; \
6+
cd $$ROOT && addlicense -c "Boyuan-IT-Club" -l apache .
7+
8+
wire:
9+
@echo "Running wire code generation..."
10+
wire gen ./provider
11+
12+
swagger:
13+
@echo "Generating swagger..."
14+
swag init \
15+
--parseDependency \
16+
--parseInternal \
17+
--output docs

docs/docs.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2025 Boyuan-IT-Club
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
// Package docs Code generated by swaggo/swag. DO NOT EDIT
216
package docs
317

docs/swagger.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright 2025 Boyuan-IT-Club
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
basePath: /
216
definitions:
317
dto.CommentVO:

0 commit comments

Comments
 (0)