This repository has been archived by the owner on Jan 6, 2023. It is now read-only.
Refactor to run one workflow per-environment #85
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,114 @@ | ||
version: 2 | ||
jobs: | ||
test: | ||
--- | ||
version: 2.1 | ||
|
||
executors: | ||
# Common container definition used by all jobs | ||
ruby_browsers: | ||
docker: | ||
- image: circleci/ruby:2.5.5-browsers | ||
|
||
commands: | ||
# Smoke test command template | ||
smoketest: | ||
parameters: | ||
env: | ||
type: string | ||
steps: | ||
- checkout | ||
- run: | ||
name: Setup bundler | ||
command: gem install bundler | ||
- restore-cache: | ||
- restore_cache: | ||
keys: | ||
- v2-identity-monitor-bundle-{{ checksum "Gemfile.lock" }} | ||
- run: | ||
name: Install dependencies | ||
command: | | ||
bundle install --path vendor/bundle | ||
- save-cache: | ||
- save_cache: | ||
key: v2-identity-monitor-bundle-{{ checksum "Gemfile.lock" }} | ||
paths: | ||
- vendor/bundle | ||
- run: | ||
name: Setup tests | ||
command: bin/circleci-setup | ||
- run: | ||
name: Run tests | ||
command: bin/circleci-run | ||
name: Run smoketest suite against environment | ||
command: bin/circleci-run << parameters.env >> | ||
|
||
jobs: | ||
smoketest_dev: | ||
executor: ruby_browsers | ||
steps: | ||
- smoketest: | ||
env: dev | ||
|
||
smoketest_int: | ||
executor: ruby_browsers | ||
steps: | ||
- smoketest: | ||
env: int | ||
|
||
smoketest_staging: | ||
executor: ruby_browsers | ||
steps: | ||
- smoketest: | ||
env: staging | ||
|
||
smoketest_prod: | ||
executor: ruby_browsers | ||
steps: | ||
- smoketest: | ||
env: prod | ||
|
||
workflows: | ||
version: 2 | ||
hourly: | ||
triggers: | ||
- schedule: | ||
cron: "0 * * * *" | ||
filters: | ||
branches: | ||
only: | ||
- master | ||
jobs: | ||
- test | ||
# DEV - Not yet ready | ||
# smoketest_dev: | ||
# triggers: | ||
# - schedule: | ||
# cron: "20 * * * *" | ||
# filters: | ||
# branches: | ||
# only: | ||
# - master | ||
# jobs: | ||
# - prepare | ||
# - smoketest_dev: | ||
# requires: | ||
# - prepare | ||
|
||
# INT | ||
smoketest_int: | ||
triggers: | ||
- schedule: | ||
cron: "30 * * * *" | ||
filters: | ||
branches: | ||
only: | ||
- master | ||
jobs: | ||
- smoketest_int | ||
|
||
# STAGING | ||
smoketest_staging: | ||
triggers: | ||
- schedule: | ||
cron: "40 * * * *" | ||
filters: | ||
branches: | ||
only: | ||
- master | ||
jobs: | ||
- smoketest_staging | ||
|
||
# PROD | ||
smoketest_prod: | ||
triggers: | ||
- schedule: | ||
cron: "50 * * * *" | ||
filters: | ||
branches: | ||
only: | ||
- master | ||
jobs: | ||
- smoketest_prod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,58 @@ | ||
#!/usr/bin/env ruby | ||
|
||
## | ||
# There are lots of moving parts so the tests can be flaky. | ||
# For better or worse we only sound the alarm if we fail after 3 tries. | ||
# | ||
def run_and_retry_tests(environment) | ||
result = system "HEADLESS_BROWSER=true LOWER_ENV=#{environment} bundle exec rspec" | ||
return if result | ||
|
||
2.times do | ||
require 'optparse' | ||
|
||
def run_and_retry_tests(environment, retries) | ||
cmd = ['HEADLESS_BROWSER=true', "LOWER_ENV=#{environment}", 'bundle', 'exec', | ||
'rspec'] | ||
retry_flags = ['--only-failure'] | ||
|
||
retries.times do | ||
return if system cmd.join(' ') | ||
|
||
puts "Smoke tests failed in #{environment}. Retrying..." | ||
return if system "HEADLESS_BROWSER=true LOWER_ENV=#{environment} bundle exec rspec --only-failure" | ||
|
||
# Retries use '--only-failure' to skip over previous sucessful tests | ||
retry_flags.empty? or cmd << retry_flags.shift | ||
end | ||
raise "Tests failed in #{environment}" | ||
end | ||
|
||
puts 'Running tests in INT' | ||
run_and_retry_tests('int') | ||
def main | ||
basename = File.basename($PROGRAM_NAME) | ||
retries = 3 | ||
|
||
optparse = OptionParser.new do |opts| | ||
opts.banner = <<~USAGEDOC | ||
usage: #{basename} [-r NUM] ENVIRONMENT | ||
|
||
Run smoke tests for a given environment. (Intended for pipeline use.) | ||
|
||
Args: | ||
ENVIRONMENT Target to test. Sets "LOWER_ENV" in the rspec test. | ||
Environment variables for the target must be present. | ||
|
||
USAGEDOC | ||
|
||
puts 'Running tests in STAGING' | ||
run_and_retry_tests('staging') | ||
opts.on('-r', '--retry-count NUM', Integer, | ||
'Times to retry test. (Default: 3)') do |r| | ||
retries = r | ||
end | ||
end | ||
|
||
args = optparse.parse! | ||
|
||
if args.length != 1 | ||
warn optparse | ||
exit 1 | ||
end | ||
|
||
puts 'Renning tests in PROD' | ||
run_and_retry_tests('prod') | ||
env = ARGV[0] | ||
|
||
puts "Running tests in #{env}" | ||
run_and_retry_tests(env, retries) | ||
end | ||
|
||
if __FILE__ == $PROGRAM_NAME | ||
main | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may make sense to have a branch for each env. Something that matches the IdP code. These frequently break because they are looking for a button label that is deployed to one env but not the other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent idea! Going to merge this now and if no one else beats me to it look into that later in the week.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the per-branch stuff might work best if these lived in the same repo as the IDP