terraspace_ci_github 0.1.1 → 0.2.0

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: d4e578a83cdc12bfa854c076f336e8c81e0d716bd479a30006b24a1925ab6033
4
- data.tar.gz: f846068d455b7a0bf859ce5d3cc14bb81fa9792dbb865f0c72b2670fdc4207a6
3
+ metadata.gz: ed3862589c53aacc52e4ef608a40dfc2c497e975972dd4873d14a2187308812a
4
+ data.tar.gz: f141392dd32495f4ba7297848713a44bb845de03f22881f85afdcd293f06c5f1
5
5
  SHA512:
6
- metadata.gz: 996cabd891da675d935b7500c1c6d2f5264fea85eaa14150af1ff20b14269a6cfb99a4713f7bb1dda8ad035ec63bf2edc4fa52d22be044be04e4e70083e52456
7
- data.tar.gz: 4db815eb1239ec5449db267786adc339694ff8bcc7243cd2202bca8664a309162a49fcdc0488dced8a8d18474bb0b2edeed16fb29ad1b56f1d9ef10c340eb58e
6
+ metadata.gz: 0a7fe5e22a954b75c84d6a8f0f7d0f4b87dc90a79c0b00dafd85dffc868f7e01bd5467091e78822ac62be3728d9af7c1ffb3dffeeba34a45a79eec5f5dd01cce
7
+ data.tar.gz: 55f8b17d8cfe9492202792b475ee77ba31dc319310bb29c10c522d6f25ddac0d7d6feb2902018b11f0fcd397b283c4cc350231c5cff62abedac952fd4d36ada6
data/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *tries* to adhere to [Semantic Versioning](http://semver.org/).
5
5
 
6
+ ## [0.2.0] - 2022-07-11
7
+ - [#3](https://github.com/boltops-tools/terraspace_ci_github/pull/3) Cost support: install infracost
8
+ - [#4](https://github.com/boltops-tools/terraspace_ci_github/pull/4) Deprecate comment interface method
9
+ - update template: use github.token from github actions ci env instead
10
+
11
+ ## [0.1.3] - 2022-06-15
12
+ - [#2](https://github.com/boltops-tools/terraspace_ci_github/pull/2) get pr url from push commit message
13
+
14
+ ## [0.1.2] - 2022-06-15
15
+ - [#1](https://github.com/boltops-tools/terraspace_ci_github/pull/1) add faraday-retry gem to get rid of warning
16
+
6
17
  ## [0.1.1] - 2022-06-09
7
18
 
8
19
  - Fix branch name
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # terraspace_ci_github
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/terraspace.png)](http://badge.fury.io/rb/terraspace)
3
+ [![Gem Version](https://badge.fury.io/rb/terraspace_ci_github.png)](http://badge.fury.io/rb/terraspace_ci_github)
4
4
 
5
5
  [![BoltOps Badge](https://img.boltops.com/boltops/badges/boltops-badge.png)](https://www.boltops.com)
6
6
 
@@ -1,8 +1,15 @@
1
1
  #!/bin/bash
2
+
3
+ # install terraform
2
4
  brew install tfenv
3
5
  tfenv install latest
4
6
  tfenv use latest
5
7
  terraform --version
8
+
9
+ # install terraspace
6
10
  bundle install
7
11
  bundle exec terraspace new shim
8
12
  terraspace --version
13
+
14
+ # install infracost
15
+ curl -fsSL https://raw.githubusercontent.com/infracost/infracost/master/scripts/install.sh | sh
@@ -9,13 +9,13 @@ jobs:
9
9
 
10
10
  env:
11
11
  <%= plugin_env_vars(indent: 6) -%>
12
- GH_TOKEN: ${{ secrets.GH_TOKEN }}
12
+ GH_TOKEN: ${{ github.token }}
13
13
  TS_ENV: dev
14
14
  TS_TOKEN: ${{ secrets.TS_TOKEN }}
15
15
 
16
16
  steps:
17
17
  <%= partial "init_steps.yml" -%>
18
18
 
19
- - name: Terraspace Command
19
+ - name: Run Terraspace
20
20
  run: |
21
21
  terraspace plan demo
@@ -11,13 +11,13 @@ jobs:
11
11
 
12
12
  env:
13
13
  <%= plugin_env_vars(indent: 6) -%>
14
- GH_TOKEN: ${{ secrets.GH_TOKEN }}
14
+ GH_TOKEN: ${{ github.token }}
15
15
  TS_ENV: dev
16
16
  TS_TOKEN: ${{ secrets.TS_TOKEN }}
17
17
 
18
18
  steps:
19
19
  <%= partial "init_steps.yml" -%>
20
20
 
21
- - name: Terraspace Command
21
+ - name: Run Terraspace
22
22
  run: |
23
23
  terraspace up demo -y
@@ -18,13 +18,13 @@ jobs:
18
18
 
19
19
  env:
20
20
  <%= plugin_env_vars(indent: 6) -%>
21
- GH_TOKEN: ${{ secrets.GH_TOKEN }}
21
+ GH_TOKEN: ${{ github.token }}
22
22
  TS_ENV: ${{ github.event.inputs.env }}
23
23
  TS_TOKEN: ${{ secrets.TS_TOKEN }}
24
24
 
25
25
  steps:
26
26
  <%= partial "init_steps.yml" -%>
27
27
 
28
- - name: Terraspace Command
28
+ - name: Run Terraspace
29
29
  run: |
30
30
  terraspace ${{ github.event.inputs.command }} -y
@@ -7,6 +7,6 @@
7
7
  ruby-version: 3.1
8
8
  bundler-cache: true # runs 'bundle install' and caches installed gems automatically
9
9
 
10
- - name: Install
10
+ - name: Install Terraspace
11
11
  run:
12
12
  .github/bin/install
@@ -1,3 +1,5 @@
1
+ require "faraday"
2
+ require "faraday/retry"
1
3
  require "octokit"
2
4
 
3
5
  module TerraspaceCiGithub
@@ -7,6 +7,9 @@ module TerraspaceCiGithub
7
7
 
8
8
  # optional interface
9
9
  def comment(url)
10
+ puts "DEPRECATED: The comment interface has been replaced by the terraspace_vcs_github gem."
11
+ puts "Please upgrade your terraspace install and add terraspace_vcs_github to your Terraspace project Gemfile."
12
+ puts "The comment interface method will be removed from terraspace."
10
13
  Pr.new.comment(url)
11
14
  end
12
15
  end
@@ -1,11 +1,11 @@
1
1
  module TerraspaceCiGithub
2
2
  class Pr < Base
3
3
  def comment(url)
4
- return unless ENV['GITHUB_EVENT_NAME'] == 'pull_request'
4
+ return unless pull_request_available?
5
5
  return unless github_token?
6
6
 
7
7
  repo = ENV['GITHUB_REPOSITORY'] # org/repo
8
- number = ENV['GITHUB_REF_NAME'].split('/').first # IE: 2/merge
8
+ number = pr_number
9
9
  marker = "<!-- terraspace marker -->"
10
10
  body = marker + "\n"
11
11
  body << "Terraspace Cloud Url #{url}"
@@ -25,5 +25,17 @@ module TerraspaceCiGithub
25
25
  rescue Octokit::Unauthorized => e
26
26
  puts "WARN: #{e.message}. Unable to create pull request comment. Please double check your github token"
27
27
  end
28
+
29
+ def pull_request_available?
30
+ !!pr_number
31
+ end
32
+
33
+ def pr_number
34
+ if ENV['GITHUB_EVENT_NAME'] == 'pull_request'
35
+ ENV['GITHUB_REF_NAME'].split('/').first # IE: 2/merge
36
+ else
37
+ Vars.new.pr_number
38
+ end
39
+ end
28
40
  end
29
41
  end
@@ -10,9 +10,10 @@ module TerraspaceCiGithub
10
10
  # urls
11
11
  pr_url: pr_url,
12
12
  build_url: build_url,
13
+ branch_url: branch_url,
13
14
  # additional properties
14
15
  build_type: build_type, # required IE: pull_request or push
15
- pr_number: pr['number'], # set when build_type=pull_request
16
+ pr_number: pr_number, # set when build_type=pull_request
16
17
  sha: sha,
17
18
  # additional properties
18
19
  commit_message: commit_message,
@@ -25,8 +26,31 @@ module TerraspaceCiGithub
25
26
  ENV['GITHUB_SERVER_URL'] || 'https://github.com'
26
27
  end
27
28
 
29
+ def branch_url
30
+ "#{host}/#{full_repo}/tree/#{branch_name}" if branch_name
31
+ end
32
+
33
+ COMMIT_PATTERN = %r{Merge pull request #(\d) from (.*)}
28
34
  def pr_url
29
- "#{host}/#{full_repo}/pull/#{pr['number']}" if pr['number']
35
+ if pr['number']
36
+ "#{host}/#{full_repo}/pull/#{pr['number']}"
37
+ elsif md = commit_message.match(COMMIT_PATTERN)
38
+ # git push commit has commit with PR info
39
+ # IE: Merge pull request #4 from tongueroo/feature
40
+ number = md[1]
41
+ org_branch = md[2]
42
+ org = org_branch.split('/').first
43
+ repo = ENV['GITHUB_REPOSITORY'].split('/').last # IE: tongueroo/infra-ci
44
+ "#{host}/#{org}/#{repo}/pull/#{number}"
45
+ end
46
+ end
47
+
48
+ def pr_number
49
+ if pr['number']
50
+ pr['number']
51
+ elsif md = commit_message.match(COMMIT_PATTERN)
52
+ md[1] # number
53
+ end
30
54
  end
31
55
 
32
56
  def build_url
@@ -46,6 +70,7 @@ module TerraspaceCiGithub
46
70
  rescue Octokit::Unauthorized => e
47
71
  puts "WARN: #{e.message}. Error getting commit message. Please double check your github token"
48
72
  end
73
+ memoize :commit_message
49
74
 
50
75
  def full_repo
51
76
  ENV['GITHUB_REPOSITORY']
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TerraspaceCiGithub
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
29
  spec.require_paths = ["lib"]
30
30
 
31
+ spec.add_dependency "faraday-retry"
31
32
  spec.add_dependency "memoist"
32
33
  spec.add_dependency "octokit"
33
34
  spec.add_dependency "zeitwerk"
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terraspace_ci_github
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-10 00:00:00.000000000 Z
11
+ date: 2022-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday-retry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: memoist
15
29
  requirement: !ruby/object:Gem::Requirement