From 3ab309e00e5af9196acb34c29ebeb9bfe356d3b1 Mon Sep 17 00:00:00 2001 From: Hantong Chen <70561268+cxw620@users.noreply.github.com> Date: Tue, 17 Jun 2025 22:35:02 +0800 Subject: [PATCH] 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) --- .github/workflows/auto_lang.yml | 72 --------------------------------- cmd/lang.go | 8 +++- 2 files changed, 7 insertions(+), 73 deletions(-) delete mode 100644 .github/workflows/auto_lang.yml diff --git a/.github/workflows/auto_lang.yml b/.github/workflows/auto_lang.yml deleted file mode 100644 index ddf637b4..00000000 --- a/.github/workflows/auto_lang.yml +++ /dev/null @@ -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 diff --git a/cmd/lang.go b/cmd/lang.go index d128739b..679b9cee 100644 --- a/cmd/lang.go +++ b/cmd/lang.go @@ -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