Browse Source

Maintenance: Optimize GitHub Actions configuration.

Martin Gruner 2 years ago
parent
commit
5289db4369

+ 3 - 4
.github/PULL_REQUEST_TEMPLATE.md

@@ -1,10 +1,9 @@
 <!--
-Hi there - a lot of love for starting a Pull Request ๐Ÿ˜. Please ensure the following things before creation - thank you!
+Hi there - a lot of love for starting a pull request ๐Ÿ˜. Please ensure the following things before creation - thank you!
 
-- Create your Pull Request against the develop branch. We don't accept changes to stable branches.
+- Create your pull request against the develop branch. We don't accept changes to stable branches.
 - Add a reference to the issue you are trying to fix. Just add a # and the number.
-- Don't run `bundle update`. It's a honorable thought of you but some dependency versions (e.g. pg) are broken ๐Ÿ˜ข Just use `bundle install` if you introduce new dependencies instead.
-- Run `rubocop` and `coffeelint` on your changes to respect the code style guide.
+- Make sure to check out the developer manual in doc/developer_manual.
 - Add tests for your changes. Feel free to ask for support. We are happy to help you.
 
 * The upper textblock will be removed automatically when you submit your Pull Request *

+ 0 - 42
.github/ci.sh

@@ -1,42 +0,0 @@
-#!/usr/bin/env bash
-#
-# install & unit test zammad
-#
-
-set -o errexit
-set -o pipefail
-
-# install build dependencies
-sudo apt-get update
-sudo apt-get install -y --no-install-recommends autoconf automake autotools-dev bison build-essential curl git-core libffi-dev libgdbm-dev libgmp-dev libmariadbclient-dev-compat libncurses5-dev libreadline-dev libsqlite3-dev libssl-dev libtool libxml2-dev libxslt1-dev libyaml-0-2 libyaml-dev patch pkg-config postfix sqlite3 zlib1g-dev libimlib2 libimlib2-dev
-
-# create db config
-DB_CONFIG="test:\n  adapter: postgresql\n  database: zammad_test\n  host: 127.0.0.1\n  port: DB_PORT\n  pool: 50\n  timeout: 5000\n  encoding: utf8\n  username: DB_USERNAME\n  password: DB_PASSWORD"
-
-if [ "${ZAMMAD_DBS}" == "mysql" ]; then
-  DB_ADAPTER="mysql2"
-  DB_USERNAME="root"
-  DB_PASSWORD="password"
-  DB_PORT="13306"
-  INSTALL_OPTION="postgres"
-elif [ "${ZAMMAD_DBS}" == "postgresql" ]; then
-  DB_ADAPTER="postgresql"
-  DB_USERNAME="postgres"
-  DB_PASSWORD="postgres"
-  DB_PORT="5432"
-  INSTALL_OPTION="mysql"
-fi
-
-echo -e "${DB_CONFIG}" | sed -e "s/adapter: postgresql/adapter: ${DB_ADAPTER}/g" -e "s/DB_USERNAME/${DB_USERNAME}/g" -e "s/DB_PASSWORD/${DB_PASSWORD}/g" -e "s/DB_PORT/${DB_PORT}/g" > config/database.yml
-
-# install zammad
-gem install bundler:1.7.3
-bundle install --without "${INSTALL_OPTION}"
-
-# unit tests
-bundle exec rubocop
-bundle exec rake zammad:db:init
-bundle exec rspec -t ~type:system -t ~searchindex -t ~required_envs
-bundle exec rake zammad:db:reset
-bundle exec rake test:units
-ruby -I test/ test/integration/object_manager_test.rb

+ 36 - 32
.github/workflows/ci.yaml

@@ -1,45 +1,49 @@
-name: ci
+name: CI
 
 on:
   pull_request
 
 jobs:
-  ci:
+  CI:
     runs-on: ubuntu-latest
+    container:
+      image: registry.zammad.com/docker/zammad-ci:stable
+      credentials:
+        username: ${{ secrets.ZAMMAD_DOCKER_REGISTRY_USERNAME }}
+        password: ${{ secrets.ZAMMAD_DOCKER_REGISTRY_PASSWORD }}
     services:
-      mysql:
-        image: mysql:5
-        env:
-          MYSQL_ROOT_PASSWORD: password
-        ports:
-        - 13306:3306
-        options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
-      postgres:
-        image: postgres:11
-        env:
-          POSTGRES_USER: postgres
-          POSTGRES_PASSWORD: postgres
-        ports:
-        - 5432:5432
-        options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
-    strategy:
-      matrix:
-        dbs:
-          - mysql
-          - postgresql
+      postgresql:
+        image: registry.zammad.com/docker/zammad-postgresql:stable
+        credentials:
+          username: ${{ secrets.ZAMMAD_DOCKER_REGISTRY_USERNAME }}
+          password: ${{ secrets.ZAMMAD_DOCKER_REGISTRY_PASSWORD }}
     env:
       RAILS_ENV: test
-      ZAMMAD_DBS: ${{ matrix.dbs }}
+      Z_LOCALES: "en-us:de-de"
+      # Temporary switch to enable the mobile front end for testing.
+      ENABLE_EXPERIMENTAL_MOBILE_FRONTEND: 'true'
+      # Compile assets only once.
+      CI_SKIP_ASSETS_PRECOMPILE: 'true'
+      # Avoid unnecessary DB resets.
+      CI_SKIP_DB_RESET: 'true'
     steps:
       - name: Checkout
         uses: actions/checkout@v1
-      - name: Set up Ruby
-        uses: ruby/setup-ruby@v1
+      - name: Cache node modules
+        id: cache-npm
+        uses: actions/cache@v3
         with:
-          ruby-version: 3.0.4
-      - name: Increase MySQL max_allowed_packet to 1GB (workaround for unknown/missing service option)
-        run: |
-          sudo apt-get install -y mysql-client
-          mysql --host 127.0.0.1 --port 13306 -uroot -ppassword -e "SET GLOBAL max_allowed_packet=1073741824;"
-      - name: CI
-        run: .github/ci.sh
+          path: .yarn/cache
+          key: ${{ runner.os }}-cache-npm-${{ hashFiles('yarn.lock') }}
+      - name: Cache Rubygems
+        id: cache-bundler
+        uses: actions/cache@v3
+        with:
+          path: vendor/ruby
+          key: ${{ runner.os }}-cache-bundler-${{ hashFiles('Gemfile.lock') }}
+      - name: Pre
+        run: .github/workflows/ci/pre.sh
+      - name: Lint
+        run: .github/workflows/ci/lint.sh
+      - name: Test
+        run: .github/workflows/ci/test.sh

+ 30 - 0
.github/workflows/ci/lint.sh

@@ -0,0 +1,30 @@
+#!/usr/bin/env bash
+
+set -o errexit
+set -o pipefail
+
+# shellcheck disable=SC1091
+source /etc/profile.d/rvm.sh
+# shellcheck disable=SC1091
+source .gitlab/environment.env
+
+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 translation_catalog --check
+echo "Brakeman security check..."
+bundle exec brakeman -o /dev/stdout -o tmp/brakeman-report.html
+echo "Rails zeitwerk:check autoloader check..."
+bundle exec rails zeitwerk:check
+.gitlab/check_graphql_api_consistency.sh
+echo "Rubocop check..."
+bundle exec .rubocop/validate_todos.rb
+bundle exec rubocop --parallel
+echo "Coffeelint check..."
+coffeelint --rules ./.coffeelint/rules/* app/
+echo "Stylelint check..."
+yarn lint:css
+echo "ESLint check..."
+yarn lint
+echo "Storybook test build..."
+yarn storybook:build

+ 15 - 0
.github/workflows/ci/pre.sh

@@ -0,0 +1,15 @@
+#!/usr/bin/env bash
+
+set -o errexit
+set -o pipefail
+
+# shellcheck disable=SC1091
+source /etc/profile.d/rvm.sh # ensure RVM is loaded
+
+bundle config set --local frozen 'true'
+bundle config set --local path 'vendor'
+bundle install -j "$(nproc)"
+yarn install
+yarn storybook:install
+yarn cypress:install
+bundle exec ruby .gitlab/configure_environment.rb

+ 25 - 0
.github/workflows/ci/test.sh

@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+
+set -o errexit
+set -o pipefail
+
+# shellcheck disable=SC1091
+source /etc/profile.d/rvm.sh
+# shellcheck disable=SC1091
+source .gitlab/environment.env
+
+echo "Checking assets generation..."
+bundle exec rake assets:precompile
+
+echo "Running front end tests..."
+yarn test
+yarn test:ci:ct
+
+echo "Running basic rspec tests..."
+bundle exec rake zammad:db:init
+bundle exec rspec --exclude-pattern "spec/system/**/*_spec.rb" -t ~searchindex -t ~integration -t ~required_envs
+
+echo "Running basic minitest tests..."
+bundle exec rake zammad:db:reset
+bundle exec rake test:units
+ruby -I test/ test/integration/object_manager_test.rb