Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bitbucket Pipelines] - Spec reconfiguration based off starting condition #121

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
steps:
- commands:
- echo "This script runs only on commit to the main branch."
plugins:
- docker#v5.10.0:
image: node:lts
label: Script step
if: build.branch =~ /main/
- commands:
- echo "This script runs only on commit to branches with names that match the feature/*
pattern."
plugins:
- docker#v5.10.0:
image: openjdk:8
label: Script step
if: build.branch =~ /feature\/*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
steps:
- key: execute-34fda39a698739f93a76af1583cf0b9e937f3561
prompt: Execute step 34fda39a698739f93a76af1583cf0b9e937f3561?
input: execute-34fda39a698739f93a76af1583cf0b9e937f3561
- group: deployer
depends_on:
- execute-34fda39a698739f93a76af1583cf0b9e937f3561
steps:
- key: custom-vars
fields:
- key: Username
text: Username
- key: Role
default: admin
text: Add user role
- key: Region
default: us-east-1
options:
- label: ap-southeast-2
value: ap-southeast-2
- label: us-east-1
value: us-east-1
- label: us-west-2
value: us-west-2
select: Region
input: custom-vars
- commands:
- echo "$Username manually triggered for a build for $Region as $Role!"
label: Script step
68 changes: 66 additions & 2 deletions app/spec/lib/bk/compat/bitbucket/bitbucket_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,72 @@
RSpec.describe BK::Compat::BitBucket do
let(:bitbucket) { BK::Compat::BitBucket }

context 'it runs a snapshot test on each example' do
directory_path = 'spec/lib/bk/compat/bitbucket/examples'
context 'it runs a snapshot test on each branch starting condition pipeline example' do
directory_path = 'spec/lib/bk/compat/bitbucket/examples/branches'

Dir.glob("#{directory_path}/*").each do |file|
next if File.directory?(file)

it "compares the generated pipeline for #{file} to the original" do
bb_content = File.read(file)
parsed_content = bitbucket.new(bb_content).parse

actual = parsed_content.render(colors: false)
expect(actual).to match_snapshot(file)
end
end
end

context 'it runs a snapshot test on each custom starting condition pipeline example' do
directory_path = 'spec/lib/bk/compat/bitbucket/examples/custom'

Dir.glob("#{directory_path}/*").each do |file|
next if File.directory?(file)

it "compares the generated pipeline for #{file} to the original" do
bb_content = File.read(file)
parsed_content = bitbucket.new(bb_content).parse

actual = parsed_content.render(colors: false)
expect(actual).to match_snapshot(file)
end
end
end

context 'it runs a snapshot test on each default starting condition pipeline example' do
directory_path = 'spec/lib/bk/compat/bitbucket/examples/default'

Dir.glob("#{directory_path}/*").each do |file|
next if File.directory?(file)

it "compares the generated pipeline for #{file} to the original" do
bb_content = File.read(file)
parsed_content = bitbucket.new(bb_content).parse

actual = parsed_content.render(colors: false)
expect(actual).to match_snapshot(file)
end
end
end

context 'it runs a snapshot test on each pull-request starting condition pipeline example' do
directory_path = 'spec/lib/bk/compat/bitbucket/examples/pull-request'

Dir.glob("#{directory_path}/*").each do |file|
next if File.directory?(file)

it "compares the generated pipeline for #{file} to the original" do
bb_content = File.read(file)
parsed_content = bitbucket.new(bb_content).parse

actual = parsed_content.render(colors: false)
expect(actual).to match_snapshot(file)
end
end
end

context 'it runs a snapshot test on each tags starting condition pipeline example' do
directory_path = 'spec/lib/bk/compat/bitbucket/examples/tags'

Dir.glob("#{directory_path}/*").each do |file|
next if File.directory?(file)
Expand Down
14 changes: 14 additions & 0 deletions app/spec/lib/bk/compat/bitbucket/examples/branches/branches.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# source: https://support.atlassian.com/bitbucket-cloud/docs/pipeline-start-conditions/#Branches

image: node:lts
pipelines:
branches:
main:
- step:
script:
- echo "This script runs only on commit to the main branch."
feature/*:
- step:
image: openjdk:8 # This step uses its own image
script:
- echo "This script runs only on commit to branches with names that match the feature/* pattern."