gha_config 0.19 → 0.20

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: 16a002da5b1417fffef6cf22c9ec166e258c4000377072a952fa8998f9c33146
4
- data.tar.gz: f822acdf86ae16bc7b94275777ce0f693a154b8d417d16845e3ac993889b49e7
3
+ metadata.gz: f38b004057c7f52c5d24ccd7d75d65e323dbc64f57256f472b32e7b5d03a63cf
4
+ data.tar.gz: c0405f8dcc6adb2457267eaccc6fee2e30d2247f0d4dc0db744f5d82903017ee
5
5
  SHA512:
6
- metadata.gz: 730cf61647df7abffa62cf6ed4fc35bff2bee33dd0365e5e8a13b0c42f49f7cbf7286ac93d0d5bf859026d8bdd0fe1a617cb90dd8eab2a2d0c44f0684664b433
7
- data.tar.gz: b73d3b11704a7ed1dddffeaffa8a2219fbb3486fc3df996386008d9deaf3ea0f081b1e2317c5d776ec3f661fda3566bb3db3a30fce05d44faf256aea30508af3
6
+ metadata.gz: 37a0c649ee04795bc424852b31fef982eac4cadb765e6e87857f3ab546d9a58e746653f068a8211f16345f823f756fb13b05c4c0e5a273207fc4b9ed594d31f9
7
+ data.tar.gz: 01c6da0bcee2d280badb5deca83cbb51b18f9c402064c3b58ddc0feadce438bf53eed6c2663dc202531e14a61d1be2fa76936e899022cbacc6cd13249873a0eb
data/CHANGELOG.md CHANGED
@@ -5,6 +5,9 @@ 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.20] - 2021-08-09
9
+ - Added `_variables_` for substitution.
10
+
8
11
  ## [0.19] - 2021-08-06
9
12
  - Add `_options_` for submodules and SSH.
10
13
 
data/README.md CHANGED
@@ -131,6 +131,30 @@ Templates get expanded into their contents whenever they are used. Templates can
131
131
 
132
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.
133
133
 
134
+ ### Variables
135
+
136
+ You can define simple variables in a separate section. These variables will be replaced with their values when they appear anywhere in the input workflow file surrounded by *double underscores*. For example:
137
+
138
+ ```yaml
139
+ _variables_:
140
+ PROD_BRANCH: master
141
+ STAGING_BRANCH: develop
142
+
143
+ on:
144
+ push:
145
+ - __PROD_BRANCH__
146
+ - __STAGING_BRANCH__
147
+ ```
148
+
149
+ will output:
150
+
151
+ ```yaml
152
+ on:
153
+ push:
154
+ - master
155
+ - develop
156
+ ```
157
+
134
158
  ### Special options
135
159
 
136
160
  In addition to `_defaults_`, there are other options that will affect how the output of certain steps is emitted. These options are parsed from the `_options_` key:
@@ -4,12 +4,14 @@ module GhaConfig
4
4
  attr_accessor :env
5
5
  attr_accessor :parsed_config
6
6
  attr_accessor :options
7
+ attr_accessor :variables
7
8
 
8
9
  def initialize
9
10
  @env = {}
10
11
  @defaults = []
11
12
  @parsed_config = {}
12
13
  @options = {}
14
+ @variables = {}
13
15
  end
14
16
  end
15
17
  end
@@ -7,6 +7,7 @@ module GhaConfig
7
7
  config = GhaConfig::Config.new
8
8
  config.defaults = hash.delete('_defaults_') || {}
9
9
  config.options = hash.delete('_options_') || {}
10
+ config.variables = hash.delete('_variables_') || {}
10
11
  config.env = hash.delete('env') || {}
11
12
 
12
13
  hash['jobs'] = replace_defaults(config, hash['jobs'])
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GhaConfig
4
- VERSION = '0.19'
4
+ VERSION = '0.20'
5
5
  end
@@ -66,7 +66,7 @@ module GhaConfig
66
66
  output_hash['jobs'][name] = new_job
67
67
  end
68
68
  output = output_hash.to_yaml
69
- output = cleanup(output)
69
+ output = cleanup(output, config)
70
70
  header = <<-OUT
71
71
  ######## GENERATED FROM ./github/workflow-src/CI.yml
72
72
  ######## USING gha_config https://github.com/wishabi/gha-config
@@ -77,7 +77,7 @@ module GhaConfig
77
77
  File.write(output_file, output)
78
78
  end
79
79
 
80
- def self.cleanup(out)
80
+ def self.cleanup(out, config)
81
81
  out = out.sub("---\n", '')
82
82
  out = out.gsub(/'on'/, 'on') # replace 'on' with on
83
83
  out = out.gsub(/: ''/, ':') # replace : '' with :
@@ -85,6 +85,10 @@ module GhaConfig
85
85
  out = out.gsub(/"\[/, '[')
86
86
  out = out.gsub(/\]"/, ']') # change "[...]" to [...]
87
87
 
88
+ config.variables.each do |name, val|
89
+ out = out.gsub("__#{name}__", val)
90
+ end
91
+
88
92
  first, last = out.split("\njobs:")
89
93
  first = first.gsub(/"/, '') # remove quotes from env block
90
94
  last = last.gsub(/\n (\S)/) { "\n\n #{$1}" } # add empty line before job keys
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.19'
4
+ version: '0.20'
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-08-06 00:00:00.000000000 Z
11
+ date: 2021-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop