gha_config 0.10 → 0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b9d19ff5b1e9e5061ace6d37d397e5e7404525d6ce101b74cb9532db251d30b4
4
- data.tar.gz: '09ec807d50a2b8c55e50ddc0691a577458a0a62967d540f67402e0c38b39a87a'
3
+ metadata.gz: 494d88f660f4f7b6aac5ab217afa7afb34e6c88c09ec357c811aca471ca19c8f
4
+ data.tar.gz: 1306d388bec13893965e811a8349a34e7b44b8fbc5be2bbe18a064d07a98931f
5
5
  SHA512:
6
- metadata.gz: d7973193d71d199bf15c9a858e7ab307fe6e6f58d606acdeb26127906f7f1125cf102236f9b62ecfcdb38fbc25548cfce640e33edd6318d1048235de1b9019f3
7
- data.tar.gz: cfc3111a028a9bb696b51030aa66b9ccc62146153d312b31bc98f19114b3a18a8e432ad2f68347f09f6a433019aeab613b9bd06d66f8385dd91fca9e12bfb77f
6
+ metadata.gz: 5b572dd14a4804d5ea444955d0b859acb920024d1341bee55d84b634a63d961c9199e31f10fc7416e05ee9c9381d88b77be073b3b6185c902e9038cbbc81da75
7
+ data.tar.gz: 7c1621af6526c97f81698d8499a9289e8353901ca52a49c071a8341eaa38a03bc8cea5880488694fab5f6b09cfe94570f8e51586e25f3624e233fb009dd608a8
@@ -0,0 +1,7 @@
1
+ prod_branch: main
2
+ ci_image: ruby-2.6-stretch
3
+ mysql: false
4
+ kafka: false
5
+ datadog: false
6
+ redis: false
7
+
@@ -0,0 +1,68 @@
1
+ name: CI
2
+
3
+ on: push
4
+
5
+ env:
6
+ HOME: /home/circleci
7
+ AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
8
+ AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
9
+ AWS_REGION: ${{ secrets.AWS_REGION }}
10
+ AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
11
+ DEPLOYMENT_TYPE: ${{ secrets.DEPLOYMENT_TYPE }}
12
+ ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
13
+ ECS_CLUSTER_PROD: ${{ secrets.ECS_CLUSTER_PROD }}
14
+ ECS_CLUSTER_STG: ${{ secrets.ECS_CLUSTER_STG }}
15
+ ECS_SERVICE_PROD: ${{ secrets.ECS_SERVICE_PROD }}
16
+ ECS_SERVICE_STG: ${{ secrets.ECS_SERVICE_STG }}
17
+ SERVICE_NAME: ${{ secrets.SERVICE_NAME }}
18
+ SERVICE_PROFILE: ${{ secrets.SERVICE_PROFILE }}
19
+ SERVICE_TOKEN: ${{ secrets.SERVICE_TOKEN }}
20
+ WISHABI_ENVIRONMENT: ${{ secrets.WISHABI_ENVIRONMENT }}
21
+
22
+ jobs:
23
+ build:
24
+ runs-on: [ubuntu, runner-fleet]
25
+ container:
26
+ image: ghcr.io/wishabi/ci-build-environment:ruby-3.0-buster
27
+ credentials:
28
+ username: ${{ github.repository_owner }}
29
+ password: ${{ secrets.GHCR_TOKEN }}
30
+
31
+ steps:
32
+ - name: Checkout code
33
+ uses: actions/checkout@v2
34
+ - name: Bundle cache
35
+ uses: actions/cache@v1
36
+ with:
37
+ path: vendor/bundle
38
+ key: rails-{{ arch }}-{{ checksum "Gemfile.lock" }}
39
+ restore-keys: rails-{{ arch }}-
40
+ - name: Bundle install
41
+ run: |
42
+ sudo chmod 1777 -R /home/circleci/.bundle && bundle config path 'vendor/bundle' && bundle install --jobs=4
43
+
44
+ deploy-gem:
45
+ runs-on: [ubuntu, runner-fleet]
46
+ needs: [build]
47
+ container:
48
+ image: ghcr.io/wishabi/ci-build-environment:ruby-3.0-buster
49
+ credentials:
50
+ username: ${{ github.repository_owner }}
51
+ password: ${{ secrets.GHCR_TOKEN }}
52
+ if: github.ref == 'refs/heads/main'
53
+ steps:
54
+ - name: Checkout code
55
+ uses: actions/checkout@v2
56
+ - name: Bundle cache
57
+ uses: actions/cache@v1
58
+ with:
59
+ path: vendor/bundle
60
+ key: rails-{{ arch }}-{{ checksum "Gemfile.lock" }}
61
+ restore-keys: rails-{{ arch }}-
62
+ - name: Bundle install
63
+ run: |
64
+ sudo chmod 1777 -R /home/circleci/.bundle && bundle config path 'vendor/bundle' && bundle install --jobs=4
65
+ - name: Deploy to production
66
+ run: |
67
+ chmod +x ./deploy/artifactory.sh && ./deploy/artifactory.sh
68
+
data/.gitignore ADDED
@@ -0,0 +1,41 @@
1
+ # Created by .ignore support plugin (hsz.mobi)
2
+ ### Ruby template
3
+ *.gem
4
+ *.rbc
5
+ /.config
6
+ /coverage/
7
+ /InstalledFiles
8
+ /pkg/
9
+ /spec/reports/
10
+ /spec/examples.txt
11
+ /test/tmp/
12
+ /test/version_tmp/
13
+ /tmp/
14
+ /log/
15
+
16
+ # Used by dotenv library to load environment variables.
17
+ # .env
18
+
19
+ ## Documentation cache and generated files:
20
+ /.yardoc/
21
+ /_yardoc/
22
+ /doc/
23
+ /rdoc/
24
+
25
+ ## Environment normalization:
26
+ /.bundle/
27
+ /vendor/bundle
28
+ /lib/bundler/man/
29
+
30
+ # for a library or gem, you might want to ignore these files since the code is
31
+ # intended to run in multiple environments; otherwise, check them in:
32
+ # Gemfile.lock
33
+ # .ruby-version
34
+ # .ruby-gemset
35
+
36
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
37
+ .rvmrc
38
+
39
+ test.sqlite3
40
+
41
+ .idea
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ inherit_gem:
2
+ flipp_ruby_style: rubocop.yml
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 2.5
6
+
7
+ Style/Documentation:
8
+ Exclude:
9
+ - 'lib/gha_config/step_definitions/**/*'
10
+ - 'lib/gha_config/workflows/**/*'
11
+
12
+ Style/DocumentationMethod:
13
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.0.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.11] - 2021-07-15
9
+ - First public version.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://flipplib.jfrog.io/flipplib/api/gems/flipp-gems/'
4
+
5
+ # Specify your gem's dependencies in boilerplate.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,38 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gha_config (0.11)
5
+
6
+ GEM
7
+ remote: https://flipplib.jfrog.io/flipplib/api/gems/flipp-gems/
8
+ specs:
9
+ ast (2.4.2)
10
+ parallel (1.20.1)
11
+ parser (3.0.1.1)
12
+ ast (~> 2.4.1)
13
+ rainbow (3.0.0)
14
+ regexp_parser (2.1.1)
15
+ rexml (3.2.5)
16
+ rubocop (0.90.0)
17
+ parallel (~> 1.10)
18
+ parser (>= 2.7.1.1)
19
+ rainbow (>= 2.2.2, < 4.0)
20
+ regexp_parser (>= 1.7)
21
+ rexml
22
+ rubocop-ast (>= 0.3.0, < 1.0)
23
+ ruby-progressbar (~> 1.7)
24
+ unicode-display_width (>= 1.4.0, < 2.0)
25
+ rubocop-ast (0.8.0)
26
+ parser (>= 2.7.1.5)
27
+ ruby-progressbar (1.11.0)
28
+ unicode-display_width (1.7.0)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ gha_config!
35
+ rubocop
36
+
37
+ BUNDLED WITH
38
+ 2.2.21
data/bin/gha_config ADDED
@@ -0,0 +1,19 @@
1
+ #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'yaml'
5
+ require 'active_support/all'
6
+ require 'fileutils'
7
+
8
+ require_relative '../lib/gha_config/parser'
9
+ require_relative '../lib/gha_config/writer'
10
+ require_relative '../lib/gha_config/config'
11
+
12
+ file = ARGV[1] || '.github/workflow-src/CI.yml'
13
+ unless File.exist?(file)
14
+ puts "File #{file} does not exist!"
15
+ exit(1)
16
+ end
17
+ results = GhaConfig::Parser.parse(file)
18
+ GhaConfig::Writer.write(results, '.github/workflows/CI.yml')
19
+ puts "Wrote results to .github/workflows/CI.yml"
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'gha_config/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'gha_config'
9
+ spec.version = GhaConfig::VERSION
10
+ spec.authors = ['Daniel Orner']
11
+ spec.email = ['daniel.orner@flipp.com']
12
+ spec.summary = 'Process GitHub Action workflow files'
13
+ spec.description = 'Write a longer description. Optional.'
14
+ spec.homepage = ''
15
+ spec.required_ruby_version = '>= 2.3'
16
+
17
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency('rubocop')
23
+ end
data/lib/gha_config.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module GhaConfig
5
+ end
@@ -0,0 +1,13 @@
1
+ module GhaConfig
2
+ class Config
3
+ attr_accessor :defaults
4
+ attr_accessor :env
5
+ attr_accessor :parsed_config
6
+
7
+ def initialize
8
+ @env = {}
9
+ @defaults = []
10
+ @parsed_config = {}
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,36 @@
1
+ require 'byebug'
2
+
3
+ module GhaConfig
4
+ module Parser
5
+ def self.parse(input_file)
6
+ input = File.read(input_file)
7
+ input.gsub!(/(^|\n)on:/, %(\n"on":))
8
+ hash = YAML.safe_load(input)
9
+ config = GhaConfig::Config.new
10
+ config.defaults = hash.delete('_defaults_') || []
11
+ config.env = hash.delete('env') || {}
12
+
13
+ hash['jobs'] = replace_defaults(config, hash['jobs'])
14
+ config.parsed_config = hash
15
+ config
16
+ end
17
+
18
+ def self.replace_defaults(config, hash)
19
+ if hash.is_a?(Array)
20
+ return hash.map { |v| self.replace_defaults(config, v)}.flatten
21
+ elsif hash.is_a?(Hash)
22
+ return hash.map { |k, v| [k, self.replace_defaults(config, v)] }.to_h
23
+ end
24
+ return hash unless hash.is_a?(String) && hash =~ /_.*_/
25
+ val = config.defaults[hash]
26
+ return hash if val.nil?
27
+ if val.is_a?(Array)
28
+ val.map { |v| self.replace_defaults(config, v) }.flatten
29
+ else
30
+ self.replace_defaults(config, val)
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GhaConfig
4
+ VERSION = '0.11'
5
+ end
@@ -0,0 +1,63 @@
1
+ module GhaConfig
2
+ module Writer
3
+ def self.write(config, output_file)
4
+ output_hash = {}
5
+ output_hash['name'] = 'CI'
6
+ output_hash['on'] = config.parsed_config['on']
7
+
8
+ output_hash['env'] = config.env.
9
+ merge({
10
+ 'HOME' => '/home/circleci',
11
+ 'AWS_ACCESS_KEY_ID' => '${{ secrets.AWS_ACCESS_KEY_ID }}',
12
+ 'AWS_ACCOUNT_ID' => '${{ secrets.AWS_ACCOUNT_ID }}',
13
+ 'AWS_REGION' => '${{ secrets.AWS_REGION }}',
14
+ 'AWS_SECRET_ACCESS_KEY' => '${{ secrets.AWS_SECRET_ACCESS_KEY }}',
15
+ 'DEPLOYMENT_TYPE' => '${{ secrets.DEPLOYMENT_TYPE }}',
16
+ 'ECR_REPOSITORY' => '${{ secrets.ECR_REPOSITORY }}',
17
+ 'ECS_CLUSTER_PROD' => '${{ secrets.ECS_CLUSTER_PROD }}',
18
+ 'ECS_CLUSTER_STG' => '${{ secrets.ECS_CLUSTER_STG }}',
19
+ 'ECS_SERVICE_PROD' => '${{ secrets.ECS_SERVICE_PROD }}',
20
+ 'ECS_SERVICE_STG' => '${{ secrets.ECS_SERVICE_STG }}',
21
+ 'SERVICE_NAME' => '${{ secrets.SERVICE_NAME }}',
22
+ 'SERVICE_PROFILE' => '${{ secrets.SERVICE_PROFILE }}',
23
+ 'SERVICE_TOKEN' => '${{ secrets.SERVICE_TOKEN }}',
24
+ 'WISHABI_ENVIRONMENT' => '${{ secrets.WISHABI_ENVIRONMENT }}'
25
+ })
26
+
27
+ output_hash['jobs'] = {}
28
+ config.parsed_config['jobs'].each do |name, job|
29
+ new_job = {
30
+ 'runs-on' => '[ubuntu, runner-fleet]'
31
+ }
32
+ job['runs-on'] = '[ubuntu, runner-fleet]'
33
+ job['steps'].unshift({
34
+ 'name' => 'Checkout code',
35
+ 'uses' => 'actions/checkout@v2'
36
+ })
37
+ job['needs'] = "[#{job['needs'].join(', ')}]" if job['needs'].is_a?(Array)
38
+ new_job.merge!(job)
39
+ output_hash['jobs'][name] = new_job
40
+ end
41
+ output = output_hash.to_yaml
42
+ output = cleanup(output)
43
+ File.write(output_file, output)
44
+ end
45
+
46
+ def self.cleanup(out)
47
+ out = out.sub("---\n", '')
48
+ out = out.gsub(/'on'/, 'on') # replace 'on' with on
49
+ out = out.gsub(/: ''/, ':') # replace : '' with :
50
+ out = out.gsub(/\n(\S)/) { "\n\n#{$1}" } # add empty line before top level keys
51
+ out = out.gsub(/"\[/, '[')
52
+ out = out.gsub(/\]"/, ']') # change "[...]" to [...]
53
+
54
+ first, last = out.split("\njobs:")
55
+ first = first.gsub(/"/, '') # remove quotes from env block
56
+ last = last.gsub(/\n (\S)/) { "\n\n #{$1}" } # add empty line before job keys
57
+ out = first + "\njobs:" + last
58
+
59
+ out
60
+ end
61
+
62
+ end
63
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gha_config
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.10'
4
+ version: '0.11'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Orner
@@ -27,11 +27,27 @@ dependencies:
27
27
  description: Write a longer description. Optional.
28
28
  email:
29
29
  - daniel.orner@flipp.com
30
- executables: []
30
+ executables:
31
+ - gha_config
31
32
  extensions: []
32
33
  extra_rdoc_files: []
33
34
  files:
35
+ - ".github/workflow-src"
36
+ - ".github/workflows/CI.yml"
37
+ - ".gitignore"
38
+ - ".rubocop.yml"
39
+ - ".ruby-version"
40
+ - CHANGELOG.md
41
+ - Gemfile
42
+ - Gemfile.lock
34
43
  - README.md
44
+ - bin/gha_config
45
+ - gha_config.gemspec
46
+ - lib/gha_config.rb
47
+ - lib/gha_config/config.rb
48
+ - lib/gha_config/parser.rb
49
+ - lib/gha_config/version.rb
50
+ - lib/gha_config/writer.rb
35
51
  homepage: ''
36
52
  licenses: []
37
53
  metadata: {}