]> cat aescling's git repositories - mastodon.git/commitdiff
Initial attempt at GitLab CI
authorkibigo! <go@kibi.family>
Sat, 9 Apr 2022 23:23:20 +0000 (16:23 -0700)
committerkibigo! <go@kibi.family>
Tue, 10 May 2022 01:32:21 +0000 (18:32 -0700)
CI currently runs on merge requests *only*.

- Use standard[rb] for linting. Standard differs pretty significantly
  from the upstream rubocop configuration, most notably by using
  double‐quotes for all strings instead of only for strings with
  interpolation. To minimize the amount of change required, linting is
  only run on changed files, thanks to an inlined deno script which
  imports JSON from the GitLab API. Linting is also allowed to fail
  without impacting an MR’s mergability.

- Run rspec tests.

- Do not do any CI on JavaScript or (S)CSS. Tests currently do not pass
  for the GlitchSoc frontend and we aren’t planning on spending
  extensive development energy here.

.gitlab-ci.yml [new file with mode: 0644]
.nvmrc
Gemfile
Gemfile.lock

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644 (file)
index 0000000..32c30f9
--- /dev/null
@@ -0,0 +1,128 @@
+image: ruby:3.0.3
+
+workflow:
+  rules:
+    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
+
+stages:
+  - diff
+  - build
+  - test
+
+variables:
+  CONTINUOUS_INTEGRATION: "true" # not sure what this does…
+  DB_HOST: postgres
+  DB_USER: $POSTGRES_USER
+  DB_PASS: $POSTGRES_PASSWORD
+  DB_NAME: $POSTGRES_DB
+  DB_PORT: 5432
+  DISABLE_SIMPLECOV: "true" # not sure what this does…
+  NODEJS_SOURCE: https://deb.nodesource.com/setup_16.x # NodeJS 16
+  POSTGRES_DB: $POSTGRES_DB
+  POSTGRES_USER: $POSTGRES_USER
+  POSTGRES_PASSWORD: $POSTGRES_PASSWORD
+  POSTGRES_HOST_AUTH_METHOD: trust
+  RAILS_ENV: test
+  REDIS_HOST: redis
+  REDIS_PORT: 6379
+
+services:
+  - redis:6.2-alpine
+  - postgres:14-alpine
+
+cache:
+  - key:
+      files:
+        - Gemfile.lock
+    paths:
+      - vendor/ruby
+  - key:
+      files:
+        - yarn.lock
+    paths:
+      - .yarn-cache/
+
+before_script:
+  - curl -fsSL $NODEJS_SOURCE | bash -
+  - alias node=nodejs
+  - apt-get update -q && apt-get install -yqq git libicu-dev libidn11-dev nodejs
+  - corepack enable && yarn set version latest
+  - bundle config set path 'vendor'
+  - bundle config without 'development production'
+  - ruby -v
+  - bundle install -j $(nproc)
+  - yarn --version
+  - echo 'yarn-offline-mirror ".yarn-cache/"' >> .yarnrc
+  - echo 'yarn-offline-mirror-pruning true' >> .yarnrc
+  - yarn install --frozen-lockfile --no-progress
+
+diff:
+  image: denoland/deno:latest
+  stage: diff
+  before_script: []
+  script:
+    - >
+      deno eval "
+      import response from 'https://gitlab.com/api/v4/projects/$CI_MERGE_REQUEST_PROJECT_ID/merge_requests/$CI_MERGE_REQUEST_IID/changes' assert { type: 'json' };
+      const { all, rb, js } = [
+        ...function* () {
+          for (const change of response.changes) {
+            const path = change.new_path;
+            if (change.deleted_file) ;
+            else yield path;
+          }
+        }(),
+      ].reduce(
+        ({ all, rb, js }, change) => {
+          all.push(change);
+          if (/[.]rb$/.test(change)) rb.push(change);
+          else if (/[.]js$/.test(change)) js.push(change);
+          return { all, rb, js };
+        },
+        { all: [], rb: [], js: [] },
+      );
+      Deno.writeTextFileSync(
+        'build.env',
+        'CHANGED_FILES=' + all.join(' ') + String.fromCodePoint(0x0A) +
+          'CHANGED_RUBY=' + rb.join(' ') + String.fromCodePoint(0x0A) +
+          'CHANGED_JS=' + js.join(' ') + String.fromCodePoint(0x0A),
+      );"
+    - cat build.env
+  artifacts:
+    reports:
+      dotenv: build.env
+
+build:
+  stage: build
+  script:
+    - ./bin/rails assets:precompile
+  artifacts:
+    name: assets
+    expire_in: 1 week
+    paths:
+      - public/assets
+      - public/packs-test
+
+lint:
+  stage: test
+  script:
+    - 'if [ ! -z "$CHANGED_RUBY" ]; then bundle exec standardrb $CHANGED_RUBY; fi'
+  allow_failure: true
+
+test:
+  stage: test
+  dependencies:
+    - build
+  variables:
+    RAILS_ENV: test
+  script:
+    - apt-get install -yqq ffmpeg imagemagick libpam-dev
+    - ./bin/rails db:create db:schema:load db:seed
+    - bundle exec rspec --format progress --format RspecJunitFormatter --out rspec.xml
+  artifacts:
+    when: always
+    paths:
+      - rspec.xml
+    reports:
+      junit:
+        - rspec.xml
diff --git a/.nvmrc b/.nvmrc
index 8351c19397f4fcd5238d10034fa7fa384f14d580..d9f880069dc78ac5930128a18758f2bdd97c1cdf 100644 (file)
--- a/.nvmrc
+++ b/.nvmrc
@@ -1 +1 @@
-14
+16.14.2
diff --git a/Gemfile b/Gemfile
index f9ff963607f7f4d9564cd121ecb09e3ecfa82c48..fa38c88b501d6a0f5a179f8ebd9e883db82e8501 100644 (file)
--- a/Gemfile
+++ b/Gemfile
@@ -107,6 +107,7 @@ group :development, :test do
   gem 'pry-byebug', '~> 3.9'
   gem 'pry-rails', '~> 0.3'
   gem 'rspec-rails', '~> 5.1'
+  gem 'standard', '~> 1.9'
 end
 
 group :production, :test do
@@ -134,8 +135,6 @@ group :development do
   gem 'letter_opener', '~> 1.8'
   gem 'letter_opener_web', '~> 2.0'
   gem 'memory_profiler'
-  gem 'rubocop', '~> 1.28', require: false
-  gem 'rubocop-rails', '~> 2.14', require: false
   gem 'brakeman', '~> 5.2', require: false
   gem 'bundler-audit', '~> 0.9', require: false
 
index 5c0a77c56a2e08882186dd754cd8133fd2eddafa..7d34b26c6e68d7f2590f06d4d7e32348272cb539 100644 (file)
@@ -583,10 +583,9 @@ GEM
       unicode-display_width (>= 1.4.0, < 3.0)
     rubocop-ast (1.17.0)
       parser (>= 3.1.1.0)
-    rubocop-rails (2.14.2)
-      activesupport (>= 4.2.0)
-      rack (>= 1.1)
+    rubocop-performance (1.13.3)
       rubocop (>= 1.7.0, < 2.0)
+      rubocop-ast (>= 0.4.0)
     ruby-progressbar (1.11.0)
     ruby-saml (1.13.0)
       nokogiri (>= 1.10.5)
@@ -645,6 +644,9 @@ GEM
       net-scp (>= 1.1.2)
       net-ssh (>= 2.8.0)
     stackprof (0.2.19)
+    standard (1.11.0)
+      rubocop (= 1.28.2)
+      rubocop-performance (= 1.13.3)
     statsd-ruby (1.5.0)
     stoplight (2.2.1)
     strong_migrations (0.7.9)
@@ -830,8 +832,6 @@ DEPENDENCIES
   rspec-rails (~> 5.1)
   rspec-sidekiq (~> 3.1)
   rspec_junit_formatter (~> 0.5)
-  rubocop (~> 1.28)
-  rubocop-rails (~> 2.14)
   ruby-progressbar (~> 1.11)
   sanitize (~> 6.0)
   scenic (~> 1.6)
@@ -845,6 +845,7 @@ DEPENDENCIES
   sprockets (~> 3.7.2)
   sprockets-rails (~> 3.4)
   stackprof
+  standard (~> 1.9)
   stoplight (~> 2.2.1)
   strong_migrations (~> 0.7)
   thor (~> 1.2)