gha_config 0.11 → 0.16

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: 494d88f660f4f7b6aac5ab217afa7afb34e6c88c09ec357c811aca471ca19c8f
4
- data.tar.gz: 1306d388bec13893965e811a8349a34e7b44b8fbc5be2bbe18a064d07a98931f
3
+ metadata.gz: 276069863b70861f12f3d76fc4054920f9a90859b0e48c58f198f87a1156bcbc
4
+ data.tar.gz: 18281dc811434e385db5f95109da89051ec7cca89d1d1eb56a584c01289528ea
5
5
  SHA512:
6
- metadata.gz: 5b572dd14a4804d5ea444955d0b859acb920024d1341bee55d84b634a63d961c9199e31f10fc7416e05ee9c9381d88b77be073b3b6185c902e9038cbbc81da75
7
- data.tar.gz: 7c1621af6526c97f81698d8499a9289e8353901ca52a49c071a8341eaa38a03bc8cea5880488694fab5f6b09cfe94570f8e51586e25f3624e233fb009dd608a8
6
+ metadata.gz: 324bfce26f456d6a5b506339b3ad021dc6ca59aa2a47fbceef054479853a7e955aff8981406ff59df6f9fb6cfa68f3f9befbb0c84c400f56afecbbd36b2eeca1
7
+ data.tar.gz: 1e91fce0673ef84daac35503ff658ef558a26bc9b36b8ea0915e528a483f6a232174c92c7a5de670beb60de38b833364a3edb5dfc3e2c3b02db7f45a9a6e95d5
data/CHANGELOG.md CHANGED
@@ -5,5 +5,18 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.16] - 2021-07-27
9
+ - Remove dependency on activesupport and byebug
10
+ - Auto-create directory if it doesn't exist
11
+
12
+ ## [0.15] - 2021-07-27
13
+ - Fix bug where defaults are not given (uses [] instead of {})
14
+
15
+ ## [0.14] - 2021-07-22
16
+ - Update global action to v0.4
17
+
18
+ ## [0.13] - 2021-07-19
19
+ - Fixes related to global action
20
+
8
21
  ## [0.11] - 2021-07-15
9
22
  - First public version.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gha_config (0.11)
4
+ gha_config (0.15)
5
5
 
6
6
  GEM
7
7
  remote: https://flipplib.jfrog.io/flipplib/api/gems/flipp-gems/
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 CHANGED
@@ -2,7 +2,6 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'yaml'
5
- require 'active_support/all'
6
5
  require 'fileutils'
7
6
 
8
7
  require_relative '../lib/gha_config/parser'
@@ -1,5 +1,3 @@
1
- require 'byebug'
2
-
3
1
  module GhaConfig
4
2
  module Parser
5
3
  def self.parse(input_file)
@@ -7,7 +5,7 @@ module GhaConfig
7
5
  input.gsub!(/(^|\n)on:/, %(\n"on":))
8
6
  hash = YAML.safe_load(input)
9
7
  config = GhaConfig::Config.new
10
- config.defaults = hash.delete('_defaults_') || []
8
+ config.defaults = hash.delete('_defaults_') || {}
11
9
  config.env = hash.delete('env') || {}
12
10
 
13
11
  hash['jobs'] = replace_defaults(config, hash['jobs'])
@@ -17,13 +15,13 @@ module GhaConfig
17
15
 
18
16
  def self.replace_defaults(config, hash)
19
17
  if hash.is_a?(Array)
20
- return hash.map { |v| self.replace_defaults(config, v)}.flatten
18
+ return hash.map { |v| self.replace_defaults(config, v)}.compact.flatten
21
19
  elsif hash.is_a?(Hash)
22
20
  return hash.map { |k, v| [k, self.replace_defaults(config, v)] }.to_h
23
21
  end
24
22
  return hash unless hash.is_a?(String) && hash =~ /_.*_/
23
+ return hash unless config.defaults.key?(hash)
25
24
  val = config.defaults[hash]
26
- return hash if val.nil?
27
25
  if val.is_a?(Array)
28
26
  val.map { |v| self.replace_defaults(config, v) }.flatten
29
27
  else
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GhaConfig
4
- VERSION = '0.11'
4
+ VERSION = '0.16'
5
5
  end
@@ -1,3 +1,5 @@
1
+ require 'fileutils'
2
+
1
3
  module GhaConfig
2
4
  module Writer
3
5
  def self.write(config, output_file)
@@ -5,7 +7,10 @@ module GhaConfig
5
7
  output_hash['name'] = 'CI'
6
8
  output_hash['on'] = config.parsed_config['on']
7
9
 
8
- output_hash['env'] = config.env.
10
+ default_env = {
11
+ 'SLACK_CHANNEL' => ''
12
+ }
13
+ output_hash['env'] = default_env.merge(config.env).
9
14
  merge({
10
15
  'HOME' => '/home/circleci',
11
16
  'AWS_ACCESS_KEY_ID' => '${{ secrets.AWS_ACCESS_KEY_ID }}',
@@ -30,6 +35,17 @@ module GhaConfig
30
35
  'runs-on' => '[ubuntu, runner-fleet]'
31
36
  }
32
37
  job['runs-on'] = '[ubuntu, runner-fleet]'
38
+ job['steps'].unshift({
39
+ 'name' => 'Flipp global',
40
+ 'uses' => 'wishabi/github-actions@v0.4',
41
+ 'env' => {
42
+ 'SLACK_BOT_TOKEN' => "${{ secrets.SLACK_BOT_TOKEN }}"
43
+ },
44
+ 'timeout-minutes' => 10,
45
+ 'with' => {
46
+ 'slack_channel' => '${{env.SLACK_CHANNEL }}',
47
+ 'job_status' => '${{ job.status }}'
48
+ }})
33
49
  job['steps'].unshift({
34
50
  'name' => 'Checkout code',
35
51
  'uses' => 'actions/checkout@v2'
@@ -40,6 +56,13 @@ module GhaConfig
40
56
  end
41
57
  output = output_hash.to_yaml
42
58
  output = cleanup(output)
59
+ header = <<-OUT
60
+ ######## GENERATED FROM ./github/workflow-src/CI.yml
61
+ ######## USING gha_config https://github.com/wishabi/gha-config
62
+
63
+ OUT
64
+ output = header + output
65
+ FileUtils.mkdir_p(File.dirname(output_file))
43
66
  File.write(output_file, output)
44
67
  end
45
68
 
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.11'
4
+ version: '0.16'
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