From 059d82637b5ab046c727df9a8150a6903ef32681 Mon Sep 17 00:00:00 2001 From: James Lopez <james@jameslopez.es> Date: Wed, 3 Feb 2016 14:37:17 +0100 Subject: [PATCH 01/13] update ci configuration to send slack notifications on failure and added rake task --- .gitlab-ci.yml | 33 ++++++++++++++++++++++++++++++++- lib/tasks/ci/slack.rake | 9 +++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 lib/tasks/ci/slack.rake diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index dbdbae9d787..4397c5add5a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -19,7 +19,12 @@ before_script: - bundle install --without postgres production --jobs $(nproc) "${FLAGS[@]}" - RAILS_ENV=test bundle exec rake db:drop db:create db:schema:load db:migrate +stages: +- test +- notifications + spec:feature: + stage: test script: - RAILS_ENV=test bundle exec rake assets:precompile 2>/dev/null - RAILS_ENV=test SIMPLECOV=true bundle exec rake spec:feature @@ -28,6 +33,7 @@ spec:feature: - mysql spec:api: + stage: test script: - RAILS_ENV=test SIMPLECOV=true bundle exec rake spec:api tags: @@ -35,6 +41,7 @@ spec:api: - mysql spec:models: + stage: test script: - RAILS_ENV=test SIMPLECOV=true bundle exec rake spec:models tags: @@ -42,6 +49,7 @@ spec:models: - mysql spec:lib: + stage: test script: - RAILS_ENV=test SIMPLECOV=true bundle exec rake spec:lib tags: @@ -49,6 +57,7 @@ spec:lib: - mysql spec:services: + stage: test script: - RAILS_ENV=test SIMPLECOV=true bundle exec rake spec:services tags: @@ -56,6 +65,7 @@ spec:services: - mysql spec:benchmark: + stage: test script: - RAILS_ENV=test bundle exec rake spec:benchmark tags: @@ -64,6 +74,7 @@ spec:benchmark: allow_failure: true spec:other: + stage: test script: - RAILS_ENV=test SIMPLECOV=true bundle exec rake spec:other tags: @@ -71,6 +82,7 @@ spec:other: - mysql spinach:project:half: + stage: test script: - RAILS_ENV=test SIMPLECOV=true bundle exec rake spinach:project:half tags: @@ -78,6 +90,7 @@ spinach:project:half: - mysql spinach:project:rest: + stage: test script: - RAILS_ENV=test SIMPLECOV=true bundle exec rake spinach:project:rest tags: @@ -85,6 +98,7 @@ spinach:project:rest: - mysql spinach:other: + stage: test script: - RAILS_ENV=test SIMPLECOV=true bundle exec rake spinach:other tags: @@ -92,6 +106,7 @@ spinach:other: - mysql teaspoon: + stage: test script: - RAILS_ENV=test bundle exec teaspoon tags: @@ -99,6 +114,7 @@ teaspoon: - mysql rubocop: + stage: test script: - bundle exec rubocop tags: @@ -106,6 +122,7 @@ rubocop: - mysql brakeman: + stage: test script: - bundle exec rake brakeman tags: @@ -113,6 +130,7 @@ brakeman: - mysql flog: + stage: test script: - bundle exec rake flog tags: @@ -120,6 +138,7 @@ flog: - mysql flay: + stage: test script: - bundle exec rake flay tags: @@ -127,6 +146,7 @@ flay: - mysql bundler:audit: + stage: test script: - "bundle exec bundle-audit update" - "bundle exec bundle-audit check" @@ -135,9 +155,10 @@ bundler:audit: - mysql allow_failure: true -# Ruby 2.1 jobs +## Ruby 2.1 jobs spec:ruby21: + stage: test image: ruby:2.1 script: - RAILS_ENV=test bundle exec rake assets:precompile 2>/dev/null @@ -149,6 +170,7 @@ spec:ruby21: - master spinach:ruby21: + stage: test image: ruby:2.1 script: - RAILS_ENV=test SIMPLECOV=true bundle exec rake spinach @@ -157,3 +179,12 @@ spinach:ruby21: - mysql only: - master + +notify:slack: + stage: notifications + script: + - bundle exec rake ci:slack + when: on_failure +# only: +# - master +# - tags \ No newline at end of file diff --git a/lib/tasks/ci/slack.rake b/lib/tasks/ci/slack.rake new file mode 100644 index 00000000000..c4edda466ac --- /dev/null +++ b/lib/tasks/ci/slack.rake @@ -0,0 +1,9 @@ +namespace :ci do + namespace :slack do + desc "GitLab CI | Send slack notification on build failure" + task error: :environment do + error_text = 'Build failed for master/tags' + Kernel.system "curl -X POST --data-urlencode 'payload={\"channel\": \"#ci-test\", \"username\": \"gitlab-ci\", \"text\": \"#{error_text}\", \"icon_emoji\": \":gitlab:\"}' $CI_SLACK_WEBHOOK_URL" + end + end +end -- GitLab From 0e7891249156ed613e9c7daeb7bdc23f7da49f5c Mon Sep 17 00:00:00 2001 From: James Lopez <james@jameslopez.es> Date: Wed, 3 Feb 2016 15:16:12 +0100 Subject: [PATCH 02/13] make build fail so we can test notifications... --- app/models/project.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index 043f08b9a13..165c21288ca 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -42,7 +42,7 @@ require 'carrierwave/orm/activerecord' require 'file_size_validator' -class Project < ActiveRecord::Base +glass Project < ActiveRecord::Base include Gitlab::ConfigHelper include Gitlab::ShellAdapter include Gitlab::VisibilityLevel -- GitLab From 26ae450dfaede7487d371b4a670a6372b0ee1c4e Mon Sep 17 00:00:00 2001 From: James Lopez <james@jameslopez.es> Date: Wed, 3 Feb 2016 15:47:59 +0100 Subject: [PATCH 03/13] update gitlab ci config --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4397c5add5a..9caa3135377 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -183,7 +183,7 @@ spinach:ruby21: notify:slack: stage: notifications script: - - bundle exec rake ci:slack + - bundle exec rake ci:slack:error when: on_failure # only: # - master -- GitLab From 63a950a5a07a399a1d99c2bf30a55385e7dfe984 Mon Sep 17 00:00:00 2001 From: James Lopez <james@jameslopez.es> Date: Wed, 3 Feb 2016 16:09:15 +0100 Subject: [PATCH 04/13] testing build failure --- app/models/project.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index 165c21288ca..2313cad05d3 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -42,7 +42,8 @@ require 'carrierwave/orm/activerecord' require 'file_size_validator' -glass Project < ActiveRecord::Base + +lass Project < ActiveRecord::Base include Gitlab::ConfigHelper include Gitlab::ShellAdapter include Gitlab::VisibilityLevel -- GitLab From 5fe354ef8374290d47a5ad35d50c084f0a96cd92 Mon Sep 17 00:00:00 2001 From: James Lopez <james@jameslopez.es> Date: Wed, 3 Feb 2016 16:55:20 +0100 Subject: [PATCH 05/13] refactored rake task and make build pass --- .gitlab-ci.yml | 2 +- app/models/project.rb | 3 +-- lib/tasks/ci/slack.rake | 6 +++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9caa3135377..d78d87cb18c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -183,7 +183,7 @@ spinach:ruby21: notify:slack: stage: notifications script: - - bundle exec rake ci:slack:error + - bundle exec rake ci:slack:error["#ci-test","Build failed for master/tags"] when: on_failure # only: # - master diff --git a/app/models/project.rb b/app/models/project.rb index 2313cad05d3..043f08b9a13 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -42,8 +42,7 @@ require 'carrierwave/orm/activerecord' require 'file_size_validator' - -lass Project < ActiveRecord::Base +class Project < ActiveRecord::Base include Gitlab::ConfigHelper include Gitlab::ShellAdapter include Gitlab::VisibilityLevel diff --git a/lib/tasks/ci/slack.rake b/lib/tasks/ci/slack.rake index c4edda466ac..0afc0e908d1 100644 --- a/lib/tasks/ci/slack.rake +++ b/lib/tasks/ci/slack.rake @@ -1,9 +1,9 @@ namespace :ci do namespace :slack do desc "GitLab CI | Send slack notification on build failure" - task error: :environment do - error_text = 'Build failed for master/tags' - Kernel.system "curl -X POST --data-urlencode 'payload={\"channel\": \"#ci-test\", \"username\": \"gitlab-ci\", \"text\": \"#{error_text}\", \"icon_emoji\": \":gitlab:\"}' $CI_SLACK_WEBHOOK_URL" + task :error, [:channel, :error] do |t, args| + next unless !"#{ENV['CI_SLACK_WEBHOOK_URL']}".blank? && args.channel && args.error + Kernel.system "curl -X POST --data-urlencode 'payload={\"channel\": \"#{args.channel}\", \"username\": \"gitlab-ci\", \"text\": \"#{args.error}\", \"icon_emoji\": \":gitlab:\"}' $CI_SLACK_WEBHOOK_URL" end end end -- GitLab From 70f82cc5ac08c2129f3a10dd1155f43eaecd2e03 Mon Sep 17 00:00:00 2001 From: James Lopez <james@jameslopez.es> Date: Wed, 3 Feb 2016 17:43:26 +0100 Subject: [PATCH 06/13] uncomment restriction to branches or tags --- .gitlab-ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d78d87cb18c..997994485da 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -185,6 +185,6 @@ notify:slack: script: - bundle exec rake ci:slack:error["#ci-test","Build failed for master/tags"] when: on_failure -# only: -# - master -# - tags \ No newline at end of file + only: + - master + - tags \ No newline at end of file -- GitLab From 0309e0818a9d73af0157ce36b2306d5723e7fb97 Mon Sep 17 00:00:00 2001 From: James Lopez <james@jameslopez.es> Date: Fri, 5 Feb 2016 11:04:13 +0100 Subject: [PATCH 07/13] removed slack task and added bash script instead. Updated gitlab-ci config file --- .gitlab-ci.yml | 11 +++++++---- lib/tasks/ci/slack.rake | 9 --------- scripts/notify_slack.sh | 13 +++++++++++++ 3 files changed, 20 insertions(+), 13 deletions(-) delete mode 100644 lib/tasks/ci/slack.rake create mode 100755 scripts/notify_slack.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 997994485da..290fa120812 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -183,8 +183,11 @@ spinach:ruby21: notify:slack: stage: notifications script: - - bundle exec rake ci:slack:error["#ci-test","Build failed for master/tags"] + - source ./scripts/notify_slack.sh "#ci-test" "Build failed for master/tags!" when: on_failure - only: - - master - - tags \ No newline at end of file + # TODO: uncomment these lines. + #only: + # - master@gitlab-org/gitlab-ce + # - tags@gitlab-org/gitlab-ce + # - master@gitlab-org/gitlab-ee + # - tags@gitlab-org/gitlab-ee \ No newline at end of file diff --git a/lib/tasks/ci/slack.rake b/lib/tasks/ci/slack.rake deleted file mode 100644 index 0afc0e908d1..00000000000 --- a/lib/tasks/ci/slack.rake +++ /dev/null @@ -1,9 +0,0 @@ -namespace :ci do - namespace :slack do - desc "GitLab CI | Send slack notification on build failure" - task :error, [:channel, :error] do |t, args| - next unless !"#{ENV['CI_SLACK_WEBHOOK_URL']}".blank? && args.channel && args.error - Kernel.system "curl -X POST --data-urlencode 'payload={\"channel\": \"#{args.channel}\", \"username\": \"gitlab-ci\", \"text\": \"#{args.error}\", \"icon_emoji\": \":gitlab:\"}' $CI_SLACK_WEBHOOK_URL" - end - end -end diff --git a/scripts/notify_slack.sh b/scripts/notify_slack.sh new file mode 100755 index 00000000000..0a4239e132c --- /dev/null +++ b/scripts/notify_slack.sh @@ -0,0 +1,13 @@ +#!/bin/bash +# Sends Slack notification ERROR_MSG to CHANNEL +# An env. variable CI_SLACK_WEBHOOK_URL needs to be set. + +CHANNEL=$1 +ERROR_MSG=$2 + +if [ -z "$CHANNEL" ] || [ -z "$ERROR_MSG" ] || [ -z "$CI_SLACK_WEBHOOK_URL" ]; then + echo "Missing argument(s) - Use: $0 channel message" + echo "and set CI_SLACK_WEBHOOK_URL environment variable." +else + curl -X POST --data-urlencode 'payload={"channel": "'"$CHANNEL"'", "username": "gitlab-ci", "text": "'"$ERROR_MSG"'", "icon_emoji": ":gitlab:"}' "$CI_SLACK_WEBHOOK_URL" +fi \ No newline at end of file -- GitLab From 27a82b2fbf7ea3227ac18d6f1bb3eacd61c81dc9 Mon Sep 17 00:00:00 2001 From: James Lopez <james@jameslopez.es> Date: Fri, 5 Feb 2016 11:45:44 +0100 Subject: [PATCH 08/13] typo to make build fail --- app/models/project.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index 043f08b9a13..165c21288ca 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -42,7 +42,7 @@ require 'carrierwave/orm/activerecord' require 'file_size_validator' -class Project < ActiveRecord::Base +glass Project < ActiveRecord::Base include Gitlab::ConfigHelper include Gitlab::ShellAdapter include Gitlab::VisibilityLevel -- GitLab From ff4a1f7287ce2e2c395d24f69253084e0c7b6943 Mon Sep 17 00:00:00 2001 From: James Lopez <james@jameslopez.es> Date: Fri, 5 Feb 2016 12:15:03 +0100 Subject: [PATCH 09/13] update with branch and tags restriction --- .gitlab-ci.yml | 11 +++++------ app/models/project.rb | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 290fa120812..1c817ce359a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -185,9 +185,8 @@ notify:slack: script: - source ./scripts/notify_slack.sh "#ci-test" "Build failed for master/tags!" when: on_failure - # TODO: uncomment these lines. - #only: - # - master@gitlab-org/gitlab-ce - # - tags@gitlab-org/gitlab-ce - # - master@gitlab-org/gitlab-ee - # - tags@gitlab-org/gitlab-ee \ No newline at end of file + only: + - master@gitlab-org/gitlab-ce + - tags@gitlab-org/gitlab-ce + - master@gitlab-org/gitlab-ee + - tags@gitlab-org/gitlab-ee \ No newline at end of file diff --git a/app/models/project.rb b/app/models/project.rb index 165c21288ca..043f08b9a13 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -42,7 +42,7 @@ require 'carrierwave/orm/activerecord' require 'file_size_validator' -glass Project < ActiveRecord::Base +class Project < ActiveRecord::Base include Gitlab::ConfigHelper include Gitlab::ShellAdapter include Gitlab::VisibilityLevel -- GitLab From 8006d025139a506f732137209c85935353bae276 Mon Sep 17 00:00:00 2001 From: James Lopez <james@jameslopez.es> Date: Mon, 8 Feb 2016 18:35:57 +0100 Subject: [PATCH 10/13] default slack notification channel --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1c817ce359a..2115b379e70 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -183,7 +183,7 @@ spinach:ruby21: notify:slack: stage: notifications script: - - source ./scripts/notify_slack.sh "#ci-test" "Build failed for master/tags!" + - source ./scripts/notify_slack.sh "#notifications" "Build failed for master/tags!" when: on_failure only: - master@gitlab-org/gitlab-ce -- GitLab From c3fe7388caa1bd49f25434b8109c4a1ab42d5b27 Mon Sep 17 00:00:00 2001 From: James Lopez <james@jameslopez.es> Date: Thu, 18 Feb 2016 11:12:51 +0100 Subject: [PATCH 11/13] resolve merge conflict --- .gitlab-ci.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2107e07c1f6..cc711bf9d6b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -179,6 +179,7 @@ spec:feature:ruby21: - mysql spec:api:ruby21: + stage: test image: ruby:2.1 only: - master @@ -208,6 +209,7 @@ spec:models:ruby21: - mysql spec:lib:ruby21: + stage: test image: ruby:2.1 only: - master @@ -222,6 +224,7 @@ spec:lib:ruby21: - mysql spec:services:ruby21: + stage: test image: ruby:2.1 only: - master @@ -236,6 +239,7 @@ spec:services:ruby21: - mysql spec:benchmark:ruby21: + stage: test image: ruby:2.1 only: - master @@ -251,6 +255,7 @@ spec:benchmark:ruby21: allow_failure: true spec:other:ruby21: + stage: test image: ruby:2.1 only: - master @@ -265,6 +270,7 @@ spec:other:ruby21: - mysql spinach:project:half:ruby21: + stage: test image: ruby:2.1 only: - master @@ -279,6 +285,7 @@ spinach:project:half:ruby21: - mysql spinach:project:rest:ruby21: + stage: test image: ruby:2.1 only: - master @@ -293,6 +300,7 @@ spinach:project:rest:ruby21: - mysql spinach:other:ruby21: + stage: test image: ruby:2.1 only: - master @@ -310,7 +318,7 @@ spinach:other:ruby21: notify:slack: stage: notifications script: - - source ./scripts/notify_slack.sh "#notifications" "Build failed for master/tags!" + - source ./scripts/notify_slack.sh "#builds" "Build failed for master/tags!" when: on_failure only: - master@gitlab-org/gitlab-ce -- GitLab From 2c02915c78c79b0cb8229ad51cafe592da832d52 Mon Sep 17 00:00:00 2001 From: James Lopez <james@jameslopez.es> Date: Mon, 22 Feb 2016 16:56:23 +0100 Subject: [PATCH 12/13] fix gitlab-ci.yml --- .gitlab-ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c1b753f25d5..3af347b4281 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -160,7 +160,7 @@ bundler:audit: - mysql allow_failure: true -# Ruby 2.1 jobs +# Ruby 2.2 jobs spec:feature:ruby22: stage: test @@ -239,8 +239,8 @@ spec:services:ruby22: - mysql spec:benchmark:ruby22: - stage: test - image: ruby:2.2 + stage: test + image: ruby:2.2 only: - master script: -- GitLab From 86b97ce1961c7d63749bd20de3f34dd10c24b865 Mon Sep 17 00:00:00 2001 From: James Lopez <james@jameslopez.es> Date: Wed, 24 Feb 2016 16:31:33 +0100 Subject: [PATCH 13/13] updated gitlab ci based on feedback --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3af347b4281..498c7447ede 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -164,7 +164,7 @@ bundler:audit: spec:feature:ruby22: stage: test - image: ruby:2.1 + image: ruby:2.2 only: - master script: @@ -318,7 +318,7 @@ spinach:other:ruby22: notify:slack: stage: notifications script: - - source ./scripts/notify_slack.sh "#builds" "Build failed for master/tags!" + - ./scripts/notify_slack.sh "#builds" "Build failed for master/tags!" when: on_failure only: - master@gitlab-org/gitlab-ce -- GitLab