gha_config 0.10 → 0.15

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: cb2d82c82325e3c26d5f4163f8eada040efa9060761ea1aa815645be44644326
4
+ data.tar.gz: 884c6e758132c49edb32aa64b438c41f9647782f3949ebe5e034a64e1d281176
5
5
  SHA512:
6
- metadata.gz: d7973193d71d199bf15c9a858e7ab307fe6e6f58d606acdeb26127906f7f1125cf102236f9b62ecfcdb38fbc25548cfce640e33edd6318d1048235de1b9019f3
7
- data.tar.gz: cfc3111a028a9bb696b51030aa66b9ccc62146153d312b31bc98f19114b3a18a8e432ad2f68347f09f6a433019aeab613b9bd06d66f8385dd91fca9e12bfb77f
6
+ metadata.gz: d086bec6a7a35df73466318ea33866ec1d1997353ab16d59e560aede723da1ea78e0f11c444b8730550287463a6fa34731ebc5b896b88bf1dca97f2d8c85744b
7
+ data.tar.gz: a86fb656b87c140425c7a735c00679815fe101f58741f066f29457ae7a3a4091be60edab580c6bd46840ef3c56ccbf38b51f7007346611dd060b4c718832bd57
@@ -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,18 @@
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.15] - 2021-07-27
9
+ - Fix bug where defaults are not given (uses [] instead of {})
10
+
11
+ ## [0.14] - 2021-07-22
12
+ - Update global action to v0.4
13
+
14
+ ## [0.13] - 2021-07-19
15
+ - Fixes related to global action
16
+
17
+ ## [0.11] - 2021-07-15
18
+ - 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.14)
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/README.md CHANGED
@@ -4,7 +4,7 @@ This gem will process a templated file and output a GitHub Action workflow file
4
4
 
5
5
  ## Installation
6
6
 
7
- You will need Ruby 2.3 or greater to run this (most Macs have this preinstalled). Make sure you have the latest version of Rubygems as well.
7
+ You will need Ruby 2.3 or greater to run this (you can install this via Homebrew if you don't have it). Make sure you have the latest version of Rubygems as well.
8
8
 
9
9
  Install using `gem install gha_config`.
10
10
 
@@ -23,7 +23,7 @@ Template keys are very similar to [YAML anchors](http://blogs.perl.org/users/tin
23
23
 
24
24
  Template keys all begin and end with underscores: `_`. You define template keys in a special `_defaults_` section in your config, and you can use them elsewhere.
25
25
 
26
- Here's an example of a templated GitHub Action workflow file:
26
+ Here's an example of a templated GitHub Action workflow file.
27
27
 
28
28
  ```yaml
29
29
  on:
@@ -33,7 +33,7 @@ on:
33
33
  - master
34
34
  - develop
35
35
 
36
- defaults_:
36
+ _defaults_:
37
37
  _container_:
38
38
  image: ghcr.io/wishabi/ci-build-environment:ruby-3.0-buster-node
39
39
  credentials:
@@ -47,11 +47,8 @@ defaults_:
47
47
  key: rails-${{ hashFiles('Gemfile.lock') }}
48
48
  restore-keys: rails-
49
49
  _teardown_:
50
- - name: Slack webhook
51
- env:
52
- SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
53
- uses: voxmedia/github-action-slack-notify-build@v2
54
- if: failure()
50
+ - name: Cleanup
51
+ - run: docker cleanup
55
52
  _setup_:
56
53
  - _cache_
57
54
  - name: Bundle install
@@ -62,10 +59,13 @@ jobs:
62
59
  container: _container_
63
60
  steps:
64
61
  - _setup_
62
+ - name: Print build
63
+ run: ls dist/
65
64
  - _teardown_
66
65
  ```
67
66
 
68
- The output of this file will look like this:
67
+ The output of this file will look like this (you can see that it auto-creates the checkout and "Flipp global" steps):
68
+
69
69
  ```yaml
70
70
  name: CI
71
71
 
@@ -105,6 +105,14 @@ jobs:
105
105
  steps:
106
106
  - name: Checkout code
107
107
  uses: actions/checkout@v2
108
+ - name: Flipp global
109
+ uses: wishabi/github-actions@v0.3
110
+ env:
111
+ SLACK_BOT_TOKEN: "${{ secrets.SLACK_BOT_TOKEN }}"
112
+ timeout-minutes: 10
113
+ with:
114
+ slack_channel: "${{env.SLACK_CHANNEL }}"
115
+ job_status: "${{ job.status }}"
108
116
  - name: Bundle cache
109
117
  uses: actions/cache@v2
110
118
  with:
@@ -113,18 +121,15 @@ jobs:
113
121
  restore-keys: rails-
114
122
  - name: Bundle install
115
123
  run: bundle install --jobs=4
116
- - name: Slack webhook
117
- env:
118
- SLACK_BOT_TOKEN: "${{ secrets.SLACK_BOT_TOKEN }}"
119
- uses: voxmedia/github-action-slack-notify-build@v2
120
- if: failure()
124
+ - name: Print build
125
+ run: ls dist/
126
+ - name: Cleanup
127
+ run: docker cleanup
121
128
  ```
122
129
 
123
- In the future, we will likely auto-add the Flipp "global action" to each job once it's created.
124
-
125
- Templates get expanded into their contents whenever they are used. Templates can also include templates (as you can see that the `setup` template includes the `cache` template). Finally, if a template is used inside a list of steps, the expansion will continue the list rather than nest it.
130
+ Templates get expanded into their contents whenever they are used. Templates can also include templates (as you can see that the `_setup_` template includes the `_cache_` template). Finally, if a template is used inside a list of steps, the expansion will continue the list rather than nest it.
126
131
 
127
- You can add this gem to your app Gemfile and re-run it whenever your "source workflow" changes.
132
+ If you're using Ruby, you can add this gem to your app Gemfile. Otherwise, you can install it locally. Either way, you can re-run it whenever your "source workflow" changes.
128
133
 
129
134
  ## Contributing
130
135
 
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)}.compact.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
+ return hash unless config.defaults.key?(hash)
26
+ val = config.defaults[hash]
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.15'
5
+ end
@@ -0,0 +1,83 @@
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
+ default_env = {
9
+ 'SLACK_CHANNEL' => ''
10
+ }
11
+ output_hash['env'] = default_env.merge(config.env).
12
+ merge({
13
+ 'HOME' => '/home/circleci',
14
+ 'AWS_ACCESS_KEY_ID' => '${{ secrets.AWS_ACCESS_KEY_ID }}',
15
+ 'AWS_ACCOUNT_ID' => '${{ secrets.AWS_ACCOUNT_ID }}',
16
+ 'AWS_REGION' => '${{ secrets.AWS_REGION }}',
17
+ 'AWS_SECRET_ACCESS_KEY' => '${{ secrets.AWS_SECRET_ACCESS_KEY }}',
18
+ 'DEPLOYMENT_TYPE' => '${{ secrets.DEPLOYMENT_TYPE }}',
19
+ 'ECR_REPOSITORY' => '${{ secrets.ECR_REPOSITORY }}',
20
+ 'ECS_CLUSTER_PROD' => '${{ secrets.ECS_CLUSTER_PROD }}',
21
+ 'ECS_CLUSTER_STG' => '${{ secrets.ECS_CLUSTER_STG }}',
22
+ 'ECS_SERVICE_PROD' => '${{ secrets.ECS_SERVICE_PROD }}',
23
+ 'ECS_SERVICE_STG' => '${{ secrets.ECS_SERVICE_STG }}',
24
+ 'SERVICE_NAME' => '${{ secrets.SERVICE_NAME }}',
25
+ 'SERVICE_PROFILE' => '${{ secrets.SERVICE_PROFILE }}',
26
+ 'SERVICE_TOKEN' => '${{ secrets.SERVICE_TOKEN }}',
27
+ 'WISHABI_ENVIRONMENT' => '${{ secrets.WISHABI_ENVIRONMENT }}'
28
+ })
29
+
30
+ output_hash['jobs'] = {}
31
+ config.parsed_config['jobs'].each do |name, job|
32
+ new_job = {
33
+ 'runs-on' => '[ubuntu, runner-fleet]'
34
+ }
35
+ job['runs-on'] = '[ubuntu, runner-fleet]'
36
+ job['steps'].unshift({
37
+ 'name' => 'Flipp global',
38
+ 'uses' => 'wishabi/github-actions@v0.4',
39
+ 'env' => {
40
+ 'SLACK_BOT_TOKEN' => "${{ secrets.SLACK_BOT_TOKEN }}"
41
+ },
42
+ 'timeout-minutes' => 10,
43
+ 'with' => {
44
+ 'slack_channel' => '${{env.SLACK_CHANNEL }}',
45
+ 'job_status' => '${{ job.status }}'
46
+ }})
47
+ job['steps'].unshift({
48
+ 'name' => 'Checkout code',
49
+ 'uses' => 'actions/checkout@v2'
50
+ })
51
+ job['needs'] = "[#{job['needs'].join(', ')}]" if job['needs'].is_a?(Array)
52
+ new_job.merge!(job)
53
+ output_hash['jobs'][name] = new_job
54
+ end
55
+ output = output_hash.to_yaml
56
+ output = cleanup(output)
57
+ header = <<-OUT
58
+ ######## GENERATED FROM ./github/workflow-src/CI.yml
59
+ ######## USING gha_config https://github.com/wishabi/gha-config
60
+
61
+ OUT
62
+ output = header + output
63
+ File.write(output_file, output)
64
+ end
65
+
66
+ def self.cleanup(out)
67
+ out = out.sub("---\n", '')
68
+ out = out.gsub(/'on'/, 'on') # replace 'on' with on
69
+ out = out.gsub(/: ''/, ':') # replace : '' with :
70
+ out = out.gsub(/\n(\S)/) { "\n\n#{$1}" } # add empty line before top level keys
71
+ out = out.gsub(/"\[/, '[')
72
+ out = out.gsub(/\]"/, ']') # change "[...]" to [...]
73
+
74
+ first, last = out.split("\njobs:")
75
+ first = first.gsub(/"/, '') # remove quotes from env block
76
+ last = last.gsub(/\n (\S)/) { "\n\n #{$1}" } # add empty line before job keys
77
+ out = first + "\njobs:" + last
78
+
79
+ out
80
+ end
81
+
82
+ end
83
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
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.15'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Orner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-15 00:00:00.000000000 Z
11
+ date: 2021-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -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: {}