Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
22624d22c4 | ||
|
|
456f4a9cdc | ||
|
|
8c3f374dbd | ||
|
|
34b7a8a5df | ||
|
|
33a6aca4ff | ||
|
|
8d2de46efa | ||
|
|
8c8c98b756 | ||
|
|
d36d66bbf7 | ||
|
|
3b4b9952dc | ||
|
|
b3e319a21f | ||
|
|
5213f7002f | ||
|
|
20f500ebcf | ||
|
|
fd13fafd86 | ||
|
|
8926ec889b |
@@ -1,116 +0,0 @@
|
|||||||
name: Update dependencies and release
|
|
||||||
|
|
||||||
on:
|
|
||||||
schedule:
|
|
||||||
# Every Sunday at 03:17 UTC (11:17 Asia/Shanghai).
|
|
||||||
- cron: '17 3 * * 0'
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
|
|
||||||
env:
|
|
||||||
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
|
|
||||||
GITEA_SERVER_URL: ${{ github.server_url }}
|
|
||||||
GITEA_REPOSITORY: ${{ github.repository }}
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
update-and-release:
|
|
||||||
# The act_runner on the Raspberry Pi must expose the self-hosted label.
|
|
||||||
runs-on: self-hosted
|
|
||||||
timeout-minutes: 60
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Check out the default branch
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
token: ${{ secrets.GITEA_TOKEN }}
|
|
||||||
ref: ${{ env.DEFAULT_BRANCH }}
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Set up Go
|
|
||||||
uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
go-version-file: go.mod
|
|
||||||
cache: true
|
|
||||||
|
|
||||||
- name: Update modules
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
go get -u ./...
|
|
||||||
go mod tidy
|
|
||||||
|
|
||||||
- name: Run tests
|
|
||||||
shell: bash
|
|
||||||
run: go test -timeout=20m ./...
|
|
||||||
|
|
||||||
- name: Detect dependency changes
|
|
||||||
id: changes
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
if git diff --quiet -- go.mod go.sum; then
|
|
||||||
echo "changed=false" >> "$GITHUB_OUTPUT"
|
|
||||||
else
|
|
||||||
echo "changed=true" >> "$GITHUB_OUTPUT"
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Commit and push dependency update
|
|
||||||
if: steps.changes.outputs.changed == 'true'
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
git config user.name "gitea-actions[bot]"
|
|
||||||
git config user.email "gitea-actions[bot]@users.noreply.gitea.local"
|
|
||||||
git add go.mod go.sum
|
|
||||||
git commit -m "chore: update Go dependencies"
|
|
||||||
git push origin "HEAD:$DEFAULT_BRANCH"
|
|
||||||
|
|
||||||
- name: Calculate next patch version
|
|
||||||
if: steps.changes.outputs.changed == 'true'
|
|
||||||
id: version
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
latest="$(git tag --list 'v[0-9]*' --sort=-version:refname | head -n 1)"
|
|
||||||
if [[ -z "$latest" ]]; then
|
|
||||||
next="v0.1.0"
|
|
||||||
elif [[ "$latest" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
|
|
||||||
next="v${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.$((${BASH_REMATCH[3]} + 1))"
|
|
||||||
else
|
|
||||||
echo "Latest tag '$latest' is not a vMAJOR.MINOR.PATCH tag" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
echo "tag=$next" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "Releasing $next"
|
|
||||||
|
|
||||||
- name: Tag the release
|
|
||||||
if: steps.changes.outputs.changed == 'true'
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
RELEASE_TAG: ${{ steps.version.outputs.tag }}
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
git tag -a "$RELEASE_TAG" -m "Release $RELEASE_TAG"
|
|
||||||
git push origin "$RELEASE_TAG"
|
|
||||||
|
|
||||||
- name: Create Gitea release
|
|
||||||
if: steps.changes.outputs.changed == 'true'
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
||||||
RELEASE_TAG: ${{ steps.version.outputs.tag }}
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
server_url="${GITEA_SERVER_URL:-${GITHUB_SERVER_URL:-}}"
|
|
||||||
repository="${GITEA_REPOSITORY:-${GITHUB_REPOSITORY:-}}"
|
|
||||||
if [[ -z "$server_url" || -z "$repository" ]]; then
|
|
||||||
echo "GITEA_SERVER_URL and GITEA_REPOSITORY are required" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
curl --fail-with-body --silent --show-error \
|
|
||||||
--request POST \
|
|
||||||
--header "Authorization: token ${GITEA_TOKEN}" \
|
|
||||||
--header "Content-Type: application/json" \
|
|
||||||
"${server_url%/}/api/v1/repos/${repository}/releases" \
|
|
||||||
--data "$(printf '{"tag_name":"%s","name":"%s","body":"Automated Go dependency update."}' "$RELEASE_TAG" "$RELEASE_TAG")"
|
|
||||||
@@ -2,32 +2,3 @@
|
|||||||
|
|
||||||
* pb协议文件生成命令
|
* pb协议文件生成命令
|
||||||
`protoc --proto_path=pkg/websocket/codec/protobuf/protocol --go_out=pkg/websocket/codec/protobuf/protocol --go_opt=paths=source_relative base.proto`
|
`protoc --proto_path=pkg/websocket/codec/protobuf/protocol --go_out=pkg/websocket/codec/protobuf/protocol --go_opt=paths=source_relative base.proto`
|
||||||
|
|
||||||
## 自动更新依赖并发布版本
|
|
||||||
|
|
||||||
仓库包含 `.gitea/workflows/dependency-release.yml`。启用 Gitea Actions 后,它会在每周日 03:17 UTC(北京时间 11:17)运行,也可以在 Actions 页面手动运行:
|
|
||||||
|
|
||||||
1. 使用 `go get -u ./...` 和 `go mod tidy` 更新依赖。
|
|
||||||
2. 执行 `go test ./...`,测试失败时不会提交或发布。
|
|
||||||
3. 有依赖变更时提交 `go.mod`、`go.sum`,创建下一个 `vMAJOR.MINOR.PATCH` 补丁版本标签,并创建 Gitea Release。
|
|
||||||
|
|
||||||
### 树莓派上的 Runner 配置
|
|
||||||
|
|
||||||
在树莓派上安装并注册 Gitea `act_runner`,注册标签中包含 `self-hosted`,并确保 Runner 环境有 Git、Go、Node.js、`curl`。工作流使用 `runs-on: self-hosted`,因此不会依赖 GitHub-hosted Runner。
|
|
||||||
|
|
||||||
在仓库的 **Settings -> Secrets -> Actions** 中新增:
|
|
||||||
|
|
||||||
- `GITEA_TOKEN`:一个能读写仓库内容、创建标签和 Release 的 Gitea Personal Access Token。
|
|
||||||
|
|
||||||
如果默认分支启用了保护规则,还需要允许该 Token 所属账号直接推送。
|
|
||||||
|
|
||||||
首次使用时建议先在仓库中手动创建一个 `v0.1.0` 以后的 SemVer 标签;如果没有任何 `vMAJOR.MINOR.PATCH` 标签,工作流会从 `v0.1.0` 开始。
|
|
||||||
|
|
||||||
|
|
||||||
```text
|
|
||||||
1. 安装并注册 act_runner,标签包含 self-hosted
|
|
||||||
2. Runner 安装 Git、Go、Node.js、curl
|
|
||||||
3. 添加 Secret:GITEA_TOKEN
|
|
||||||
4. Token 允许读写仓库、创建标签和 Release
|
|
||||||
5. 若默认分支受保护,允许该 Token 所属账号推送
|
|
||||||
```
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package captcha
|
package captcha
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"gitea.bvbej.com/bvbej/base-golang/pkg/cache"
|
"gitea.bvbej.com/bvbej/base-golang/pkg/cache"
|
||||||
"github.com/mojocn/base64Captcha"
|
"github.com/mojocn/base64Captcha"
|
||||||
@@ -13,7 +12,7 @@ import (
|
|||||||
var _ base64Captcha.Store = (*store)(nil)
|
var _ base64Captcha.Store = (*store)(nil)
|
||||||
|
|
||||||
type store struct {
|
type store struct {
|
||||||
cache cache.RedisRepo
|
cache cache.Repo
|
||||||
ttl time.Duration
|
ttl time.Duration
|
||||||
logger *zap.Logger
|
logger *zap.Logger
|
||||||
ns string
|
ns string
|
||||||
@@ -21,7 +20,7 @@ type store struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *store) Set(id string, value string) error {
|
func (s *store) Set(id string, value string) error {
|
||||||
err := s.cache.Set(context.Background(), fmt.Sprintf("%s%s%s", s.ns, s.prefix, id), value, s.ttl)
|
err := s.cache.Set(fmt.Sprintf("%s%s%s", s.ns, s.prefix, id), value, s.ttl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -29,9 +28,9 @@ func (s *store) Set(id string, value string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *store) Get(id string, clear bool) string {
|
func (s *store) Get(id string, clear bool) string {
|
||||||
value, err := s.cache.Get(context.Background(), fmt.Sprintf("%s%s%s", s.ns, s.prefix, id))
|
value, err := s.cache.Get(fmt.Sprintf("%s%s%s", s.ns, s.prefix, id))
|
||||||
if err == nil && clear {
|
if err == nil && clear {
|
||||||
_, _ = s.cache.Del(context.Background(), fmt.Sprintf("%s%s%s", s.ns, s.prefix, id))
|
s.cache.Del(fmt.Sprintf("%s%s%s", s.ns, s.prefix, id))
|
||||||
}
|
}
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
@@ -44,7 +43,7 @@ func (s *store) Verify(id, answer string, clear bool) bool {
|
|||||||
return strings.ToLower(value) == strings.ToLower(answer)
|
return strings.ToLower(value) == strings.ToLower(answer)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStore(cache cache.RedisRepo, ttl time.Duration, namespace string) base64Captcha.Store {
|
func NewStore(cache cache.Repo, ttl time.Duration, namespace string) base64Captcha.Store {
|
||||||
return &store{
|
return &store{
|
||||||
cache: cache,
|
cache: cache,
|
||||||
ttl: ttl,
|
ttl: ttl,
|
||||||
|
|||||||
Reference in New Issue
Block a user