refactor: adjust CI process (#125)

* feat(cmd/lang): allow setting frontend path when generate lang files

* chore(ci): remove ci for auto_lang (done by frontend ci)
This commit is contained in:
Hantong Chen
2025-06-17 22:35:02 +08:00
committed by GitHub
parent 8822eef97e
commit 3ab309e00e
2 changed files with 7 additions and 73 deletions

View File

@@ -1,72 +0,0 @@
name: auto_lang
on:
# Disable translation generation, enable it after everything is setup.
# push:
# branches:
# - 'main'
# paths:
# - 'drivers/**'
# - 'internal/bootstrap/data/setting.go'
# - 'internal/conf/const.go'
# - 'cmd/lang.go'
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
auto_lang:
strategy:
matrix:
platform: [ ubuntu-latest ]
go-version: [ '1.21' ]
name: auto generate lang.json
runs-on: ${{ matrix.platform }}
steps:
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Checkout alist
uses: actions/checkout@v4
with:
path: OpenList
- name: Checkout OpenList-Frontend
uses: actions/checkout@v4
with:
repository: 'OpenListTeam/OpenList-Frontend'
ref: main
persist-credentials: false
fetch-depth: 0
path: OpenList-Frontend
- name: Generate lang
run: |
cd OpenList
go run ./main.go lang
cd ..
- name: Copy lang file
run: |
cp -f ./OpenList/lang/*.json ./OpenList-Frontend/src/lang/en/ 2>/dev/null || :
- name: Commit git
run: |
cd OpenList-Frontend
git add .
git config --local user.email "bot@openlist.team"
git config --local user.name "The OpenList Bot"
git commit -m "chore: auto update i18n file" -a 2>/dev/null || :
cd ..
- name: Push lang files
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.MY_TOKEN }}
branch: main
directory: OpenList-Frontend
repository: OpenListTeam/OpenList-Frontend

View File

@@ -25,6 +25,8 @@ type KV[V any] map[string]V
type Drivers KV[KV[interface{}]]
var frontendPath string
func firstUpper(s string) string {
if s == "" {
return ""
@@ -39,7 +41,7 @@ func convert(s string) string {
}
func writeFile(name string, data interface{}) {
f, err := os.Open(fmt.Sprintf("../OpenList-Frontend/src/lang/en/%s.json", name))
f, err := os.Open(fmt.Sprintf("%s/src/lang/en/%s.json", frontendPath, name))
if err != nil {
log.Errorf("failed to open %s.json: %+v", name, err)
return
@@ -138,6 +140,7 @@ var LangCmd = &cobra.Command{
Use: "lang",
Short: "Generate language json file",
Run: func(cmd *cobra.Command, args []string) {
frontendPath, _ = cmd.Flags().GetString("frontend-path")
bootstrap.InitConfig()
err := os.MkdirAll("lang", 0777)
if err != nil {
@@ -151,6 +154,9 @@ var LangCmd = &cobra.Command{
func init() {
RootCmd.AddCommand(LangCmd)
// Add frontend-path flag
LangCmd.Flags().String("frontend-path", "../OpenList-Frontend", "Path to the frontend project directory")
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command