From: kibigo! Date: Sat, 9 Apr 2022 23:23:20 +0000 (-0700) Subject: Initial attempt at GitLab CI X-Git-Url: https://git.xn--scling-oua.cat.family/?a=commitdiff_plain;h=91226578f37eaad07798e687dc5ff500390a5c6e;p=mastodon.git Initial attempt at GitLab CI 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. --- diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 000000000..32c30f99d --- /dev/null +++ b/.gitlab-ci.yml @@ -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 8351c1939..d9f880069 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -14 +16.14.2 diff --git a/Gemfile b/Gemfile index f9ff96360..fa38c88b5 100644 --- 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 diff --git a/Gemfile.lock b/Gemfile.lock index 5c0a77c56..7d34b26c6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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)