Hello! We are running our annual fundraising. Please consider making a donation if you value this freely available service or want to support people around the world working towards liberatory social change. https://riseup.net/donate.

Commit 1c4b7335 authored by georg's avatar georg
Browse files

Merge branch 'ci-rules-instead-of-only-except' into 'master'

CI: Transition to rules, instead of deprecated only/except clauses

Closes #469

See merge request !365
parents a6e84abc d3c6020b
Pipeline #55133 passed with stage
in 3 minutes and 21 seconds
---
default:
image: $IMAGE_REGISTRY:debian-generic
stages:
- test
- static
......@@ -6,14 +9,17 @@ stages:
variables:
IMAGE_REGISTRY: $CI_REGISTRY/schleuder/schleuder-ci-images
workflow:
rules:
# Don't create pipelines for branches, if associated MR do exist, or tags.
# Otherwise, create pipelines.
# This prevents duplicated pipelines and wasted resources.
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS || $CI_COMMIT_TAG
when: never
- when: always
# Jobs that start with a period are disabled
# This is just a template, to be used further below in the individual job definitions
.limit_non_release_branches: &limit_non_release_branches
except:
- /^master/
- /^release.*/
- tags
.test_ruby: &test_ruby
script:
- eatmydata bundle install --jobs $(nproc)
......@@ -39,23 +45,23 @@ ruby:3.0:
<<: *test_ruby
changelog:
image: $IMAGE_REGISTRY:debian-generic
rules:
- if: $CI_MERGE_REQUEST_IID
allow_failure: true
script:
- source <(./utils/ci/get-target-branch.rb)
# Ensure we work with the latest state
- git fetch origin $target_branch:$target_branch
- git fetch origin $CI_MERGE_REQUEST_TARGET_BRANCH_NAME:$CI_MERGE_REQUEST_TARGET_BRANCH_NAME
# Compare the target and current branch using their common ancestors
# to check if the changelog was edited
- if git diff --exit-code --quiet $target_branch...HEAD -- CHANGELOG.md; then
- if git diff --exit-code --quiet $CI_MERGE_REQUEST_TARGET_BRANCH_NAME...HEAD -- CHANGELOG.md; then
echo "No CHANGELOG edit found, please verify manually";
exit 1;
fi
stage: static
allow_failure: true
<<: *limit_non_release_branches
codespell:
image: $IMAGE_REGISTRY:debian-generic
rules:
- if: $CI_MERGE_REQUEST_IID
script:
# Run codespell to check for spelling errors, using a config with ignored
# words, skipping files (German translations) and the code coverage dir
......@@ -63,10 +69,10 @@ codespell:
# finally, checking file names as well.
- codespell -I utils/ci/codespell/ignored_words.txt -S ./.git,coverage,de.yml,fixtures -q 2 -f
stage: static
<<: *limit_non_release_branches
code-coverage:
image: $IMAGE_REGISTRY:debian-generic
rules:
- if: $CI_PROJECT_PATH == "schleuder/schleuder" && $CI_MERGE_REQUEST_IID
script:
- unset HISTFILE
- eval $(ssh-agent -s)
......@@ -86,24 +92,24 @@ code-coverage:
environment:
name: $DEPLOY_BASE/$CI_PROJECT_NAME/$CI_COMMIT_REF_SLUG
url: https://schleuder.org/$DEPLOY_BASE/$CI_PROJECT_NAME/$CI_COMMIT_REF_SLUG
only:
- branches@schleuder/schleuder
variables:
DEPLOY_BASE: dev/code-coverage
GIT_STRATEGY: none
allow_failure: true
stage: static
<<: *limit_non_release_branches
rubocop:
image: $IMAGE_REGISTRY:debian-generic
rules:
- if: $CI_MERGE_REQUEST_IID
script:
- rubocop
stage: static
<<: *limit_non_release_branches
spec-filenames:
image: $IMAGE_REGISTRY:debian-generic
rules:
- if: $CI_MERGE_REQUEST_IID
changes:
- spec/schleuder/**/*
- spec/schleuder-api-daemon/**/*
script:
- cd spec/
- if [[ -n $(find schleuder schleuder-api-daemon -type f -not -name '*_spec.rb') ]]; then
......@@ -111,27 +117,20 @@ spec-filenames:
exit 1;
fi
stage: static
allow_failure: true
only:
changes:
- spec/schleuder/**/*
- spec/schleuder-api-daemon/**/*
<<: *limit_non_release_branches
schema-up-to-date:
image: $IMAGE_REGISTRY:debian-generic
rules:
- if: $CI_MERGE_REQUEST_IID
changes:
- db/**/*
script:
- ruby utils/ci/rails_schema_up_to_date.rb
stage: static
only:
changes:
- db/*
<<: *limit_non_release_branches
bundler:audit:
image: ruby:2.5
only:
- schedules
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
script:
- gem install bundler-audit --no-document
- bundle install --jobs $(nproc) --path vendor
......
#!/usr/bin/env ruby
# This script gets the target branch of a specific merge request. This
# is useful for example to check for a CHANGELOG edit.
#
# To enable the "export" of the env var to the parent (calling) shell,
# this script needs to be called in the following way:
# source <(./get-target-branch.rb)
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse('https://0xacab.org/api/v4/projects/schleuder%2Fschleuder/merge_requests?state=opened')
response = Net::HTTP.get(uri)
json_data = JSON.parse(response)
if ! json_data.is_a?(Array)
puts json_data
exit 1
end
json_data.each do |merge_request|
if merge_request['sha'] == ENV['CI_COMMIT_SHA']
puts "export target_branch=#{merge_request['target_branch']}"
break
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment