Browse Source

Maintenance: Improve translation catalog and file generation workflow

Martin Gruner 5 months ago
parent
commit
7d601ac0a0

+ 3 - 0
.eslintignore

@@ -12,3 +12,6 @@ public/assets/form/**/*.js
 
 public/assets/frontend/vite/**/*.js
 public/assets/frontend/vite-dev/**/*.js
+
+# Cache
+tmp/**/*

+ 1 - 0
.gitignore

@@ -32,6 +32,7 @@
 # Bundler
 /.bundle
 /Gemfile.local
+/vendor/bundle
 
 # Clutter ======================================================================
 # These files are automatically generated;

+ 2 - 1
.gitlab/ci/__includes__/cache.yml

@@ -14,7 +14,8 @@
     files:
       - pnpm-lock.yaml
   paths:
-    - .pnpm-store
+    - tmp/cache/pnpm-store
+    - tmp/cache/cypress
 
 .cache_eslint: &cache_eslint
   key:

+ 19 - 8
.gitlab/ci/__includes__/scripts.yml

@@ -6,16 +6,27 @@
     - bundle config set --local deployment 'true'
     - bundle install -j $(nproc)
     - echo -e "\\e[0Ksection_end:`date +%s`:bundle_install\\r\\e[0K"
-  pnpm_install:
-    - pnpm config set store-dir .pnpm-store
+  pnpm_init: &pnpm_init
+    - pnpm config set store-dir ${CI_PROJECT_DIR}/tmp/cache/pnpm-store
+  pnpm_install: &pnpm_install
+    - *pnpm_init
     - pnpm install
+  pnpm_install_chat: &pnpm_install_chat
+    - *pnpm_init
+    - pnpm --dir public/assets/chat install
+  pnpm_install_cypress: &pnpm_install_cypress
+    - *pnpm_install
+    - export CYPRESS_CACHE_FOLDER="${CI_PROJECT_DIR}/tmp/cache/cypress"
+    - pnpm cypress:install
+  pnpm_install_eslint_plugin_zammad: &pnpm_install_eslint_plugin_zammad
+    - *pnpm_init
+    - pnpm --dir .eslint-plugin-zammad install
   pnpm_install_all:
-    # retry on errors
-    - pnpm config set store-dir .pnpm-store
-    - pnpm install || pnpm install || pnpm install
-    - pnpm cypress:install || pnpm cypress:install || pnpm cypress:install
-    - pnpm --dir .eslint-plugin-zammad install || pnpm --dir .eslint-plugin-zammad install || pnpm --dir .eslint-plugin-zammad install
-    - pnpm --dir public/assets/chat install || pnpm --dir public/assets/chat install || pnpm --dir public/assets/chat install
+    - *pnpm_init
+    - *pnpm_install
+    - *pnpm_install_chat
+    - *pnpm_install_cypress
+    - *pnpm_install_eslint_plugin_zammad
   configure_environment:
     - bundle exec ruby .gitlab/configure_environment.rb
     - source .gitlab/environment.env

+ 2 - 11
.gitlab/ci/lint.yml

@@ -36,8 +36,8 @@
     - !reference [.scripts, pnpm_install]
     - echo "Checking .po file syntax…"
     - for FILE in i18n/*.pot i18n/*.po; do echo "Checking $FILE"; msgfmt -o /dev/null -c $FILE; done
-    - echo "Checking .pot catalog consistency…"
-    - bundle exec rails generate zammad:translation_catalog --check
+    # - echo "Checking .pot catalog consistency…"
+    # - bundle exec rails generate zammad:translation_catalog --check
     - echo "Checking consistency of Settings types file…"
     - bundle exec rails generate zammad:setting_types --check
     - echo "Rails zeitwerk:check autoloader check…"
@@ -87,12 +87,6 @@
     - coffeelint --rules ./.dev/coffeelint/rules/* app/
     - echo "Stylelint check…"
     - pnpm lint:css
-    - echo "Checking if chat assets need a rebuild…"
-    - echo "Please see public/assets/chat/README.md for build instructions."
-    - cp public/assets/chat/chat.js tmp/chat.js
-    - pnpm install --dir public/assets/chat
-    - (cd public/assets/chat && pnpm exec gulp build)
-    - cmp public/assets/chat/chat.js tmp/chat.js
 
 'lint: js':
   extends:
@@ -101,12 +95,9 @@
     - !reference [.cache, read_only_nodejs]
     - !reference [.cache, read_write_eslint]
   before_script:
-    - cp pnpm-lock.yaml tmp/pnpm-lock.yaml  # Save original state of pnpm-lock.yaml
     - !reference [.scripts, pnpm_install]
     - !reference [.scripts, source_rvm]
   script:
-    - echo "Checking if pnpm-lock.yaml is up-to-date"
-    - "if ! diff pnpm-lock.yaml tmp/pnpm-lock.yaml; then echo 'Error: pnpm-lock.yaml is not up-to-date'; exit 1; fi"
     - echo "TypeScript compiler check…"
     - pnpm lint:ts
     - echo "ESLint check…"

+ 39 - 4
.gitlab/ci/pre.yml

@@ -1,5 +1,5 @@
 # Write CI cache once for faster runs
-'write runner cache: ruby':
+'write cache: ruby':
   stage: pre
   cache: !reference [.cache, read_write_ruby]
   before_script:
@@ -8,14 +8,12 @@
     - !reference [.scripts, bundle_install]
   after_script: []
 
-'write runner cache: nodejs':
+'write cache: nodejs':
   stage: pre
   cache: !reference [.cache, read_write_nodejs]
   before_script: []
   script:
     - !reference [.scripts, pnpm_install_all]
-    - pnpm cypress:install
-    - pnpm --dir ./.eslint-plugin-zammad install
   after_script: []
 
 'push to github':
@@ -56,3 +54,40 @@
   script:
     - script/build/deploy_archives.sh
   after_script: []
+
+# This job will create commits in pipelines pushed from Weblate.
+# It re-generates the catalog, and any additional files such as view templates and chat assets.
+'push translations update commit':
+  stage: pre
+  needs: ['write cache: ruby', 'write cache: nodejs']
+  rules:
+    - if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_COMMIT_MESSAGE =~ /Translations update from translations[.]zammad[.]org/
+      when: always
+    - when: never
+  cache:
+    - !reference [.cache, read_only_ruby]
+    - !reference [.cache, read_only_nodejs]
+  services:
+    - !reference [.services, postgresql]
+  before_script:
+    - !reference [.scripts, source_rvm]
+    - !reference [.scripts, bundle_install]
+    - !reference [.scripts, configure_environment]
+    - !reference [.scripts, zammad_db_init]
+    - !reference [.scripts, pnpm_install_chat]
+  variables:
+    ZAMMAD_SAFE_MODE: 1
+  script:
+    - bundle exec rails generate zammad:translation_catalog --full
+    - (cd public/assets/chat && pnpm exec gulp build)
+    - git status
+    - git config user.email "noreply@weblate.org"
+    - git config user.name "Weblate"
+    # TODO drop usage of dedicated access token when CI_JOB_TOKEN support for commit pushing was added to weblate
+    #   https://docs.gitlab.com/ee/ci/jobs/ci_job_token.html#git-push-to-your-project-repository
+    - git remote add gitlab_origin https://oauth2:${WEBLATE_ACCESS_TOKEN}@${CI_SERVER_FQDN}/${CI_PROJECT_PATH}.git
+    - git add .
+    - git status --porcelain | grep "^[MA]" || exit 0 # check if files were added/changed
+    - 'git commit -m "Maintenance: Update translated files and catalog"'
+    - git show --stat
+    - git push gitlab_origin HEAD:$CI_COMMIT_REF_NAME

+ 2 - 3
.gitlab/ci/test/frontend.yml

@@ -5,6 +5,7 @@
   cache: !reference [.cache, read_only_nodejs]
   before_script:
     - !reference [.scripts, pnpm_install]
+    - !reference [.scripts, pnpm_install_eslint_plugin_zammad]
   script:
     # Only run one worker to avoid load peaks affecting other jobs.
     - pnpm test -- --min-workers=1 --max-workers=1 --shard $VITEST_SHARD
@@ -12,7 +13,6 @@
     - "[[ $VITEST_SHARD = 1/* ]] || exit 0"
     - echo "Also test eslint-plugin-zammad…"
     - cd .eslint-plugin-zammad
-    - pnpm install || pnpm install || pnpm install # retry on errors
     - pnpm test
 
 frontend:vitest:1:
@@ -40,8 +40,7 @@ frontend:cypress:
     - .tags_docker_low_concurrency
   cache: !reference [.cache, read_only_nodejs]
   before_script:
-    - !reference [.scripts, pnpm_install]
-    - pnpm cypress:install
+    - !reference [.scripts, pnpm_install_cypress]
   script:
     - sysctl -w fs.inotify.max_user_watches=524288 # see https://github.com/cypress-io/cypress/issues/6960
     - pnpm test:ci:ct

+ 6 - 6
.overcommit.yml

@@ -35,12 +35,12 @@ PreCommit:
       - '**/*.scss'
       - '**/*.css'
       - '**/*.vue'
-  TranslationCatalogCheck:
-    required_executable: 'rails'
-    enabled: true
-    env:
-      ZAMMAD_SAFE_MODE: '1'
-    command: ['rails', 'generate', 'zammad:translation_catalog', '--check']
+  # TranslationCatalogCheck:
+  #   required_executable: 'rails'
+  #   enabled: true
+  #   env:
+  #     ZAMMAD_SAFE_MODE: '1'
+  #   command: ['rails', 'generate', 'zammad:translation_catalog', '--check']
   SettingsTypesCheck:
     required_executable: 'rails'
     enabled: true

+ 2 - 1
.prettierignore

@@ -2,4 +2,5 @@
 !**/graphql/**/mocks/*.ts
 !**/graphql/**/*.spec.ts
 !**/tests/graphql/**
-public/**/*
+public/**/*
+tmp/**/*

+ 1 - 0
.stylelintrc.json

@@ -56,6 +56,7 @@
     "**/fineuploader.css",
     "**/qunit*.css",
     "**/svg-dimensions.css",
+    "tmp/**",
     "vendor/**",
     "coverage/**"
   ]

Some files were not shown because too many files changed in this diff