fa-harness-tools 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/ruby.yml +20 -0
- data/.gitignore +8 -0
- data/.rspec +1 -0
- data/.ruby-version +1 -0
- data/CODE_OF_CONDUCT.md +77 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +56 -0
- data/LICENSE +202 -0
- data/README.md +105 -0
- data/Rakefile +9 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/check-branch-protection +57 -0
- data/exe/check-forward-deploy +57 -0
- data/exe/check-recent-deploy +63 -0
- data/exe/check-schedule +19 -0
- data/exe/create-deployment-tag +69 -0
- data/fa-harness-tools.gemspec +37 -0
- data/lib/fa-harness-tools.rb +11 -0
- data/lib/fa-harness-tools/check_branch_protection.rb +19 -0
- data/lib/fa-harness-tools/check_forward_deploy.rb +38 -0
- data/lib/fa-harness-tools/check_recent_deploy.rb +55 -0
- data/lib/fa-harness-tools/check_schedule.rb +31 -0
- data/lib/fa-harness-tools/github_client.rb +94 -0
- data/lib/fa-harness-tools/harness_context.rb +15 -0
- data/lib/fa-harness-tools/version.rb +3 -0
- metadata +177 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a3cee0250f6a943fb938d11c0e118f53d26ea03be5edb7e8f8fc7fb0f73e154e
|
4
|
+
data.tar.gz: 030ab9dac48945eac8366a8cfcbafecc4bbbeebc5dc16254f97bfa3cfdb26368
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3f00171760572605f0282595bc852bf20181768464dd9811051cb71a6658daa9692bdb77c46dbb180eca6c982b17736cf0f4c24e89cf6fba60fcddd379d81a08
|
7
|
+
data.tar.gz: 863db5b6b4230a1d2fedd00ab20f05d830fb682bc9b4947f1e4bdd69429dfa90ba637fac2afabd6cd7c8c7b71271e6a53346593325e46a0c7c6377453c86e7bd
|
@@ -0,0 +1,20 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
|
10
|
+
steps:
|
11
|
+
- uses: actions/checkout@v1
|
12
|
+
- name: Set up Ruby 2.5
|
13
|
+
uses: actions/setup-ruby@v1
|
14
|
+
with:
|
15
|
+
ruby-version: 2.5.x
|
16
|
+
- name: Build and test with Rake
|
17
|
+
run: |
|
18
|
+
gem install bundler -v 1.16.4
|
19
|
+
bundle install --jobs 4 --retry 3
|
20
|
+
bundle exec rake
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.1
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to make participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, sex characteristics, gender identity and expression,
|
9
|
+
level of experience, education, socio-economic status, nationality, personal
|
10
|
+
appearance, race, religion, or sexual identity and orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies within all project spaces, and it also applies when
|
49
|
+
an individual is representing the project or its community in public spaces.
|
50
|
+
Examples of representing a project or community include using an official
|
51
|
+
project e-mail address, posting via an official social media account, or acting
|
52
|
+
as an appointed representative at an online or offline event. Representation of
|
53
|
+
a project may be further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at [INSERT EMAIL ADDRESS]. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
72
|
+
|
73
|
+
[homepage]: https://www.contributor-covenant.org
|
74
|
+
|
75
|
+
For answers to common questions about this code of conduct, see
|
76
|
+
https://www.contributor-covenant.org/faq
|
77
|
+
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
fa-harness-tools (1.0.4)
|
5
|
+
octokit (~> 4.0)
|
6
|
+
tzinfo (~> 2.0)
|
7
|
+
tzinfo-data (~> 1.0)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
addressable (2.7.0)
|
13
|
+
public_suffix (>= 2.0.2, < 5.0)
|
14
|
+
concurrent-ruby (1.1.5)
|
15
|
+
diff-lcs (1.3)
|
16
|
+
faraday (0.17.0)
|
17
|
+
multipart-post (>= 1.2, < 3)
|
18
|
+
multipart-post (2.1.1)
|
19
|
+
octokit (4.14.0)
|
20
|
+
sawyer (~> 0.8.0, >= 0.5.3)
|
21
|
+
public_suffix (4.0.1)
|
22
|
+
rake (10.5.0)
|
23
|
+
rspec (3.9.0)
|
24
|
+
rspec-core (~> 3.9.0)
|
25
|
+
rspec-expectations (~> 3.9.0)
|
26
|
+
rspec-mocks (~> 3.9.0)
|
27
|
+
rspec-core (3.9.0)
|
28
|
+
rspec-support (~> 3.9.0)
|
29
|
+
rspec-expectations (3.9.0)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.9.0)
|
32
|
+
rspec-mocks (3.9.0)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.9.0)
|
35
|
+
rspec-support (3.9.0)
|
36
|
+
sawyer (0.8.2)
|
37
|
+
addressable (>= 2.3.5)
|
38
|
+
faraday (> 0.8, < 2.0)
|
39
|
+
timecop (0.9.1)
|
40
|
+
tzinfo (2.0.0)
|
41
|
+
concurrent-ruby (~> 1.0)
|
42
|
+
tzinfo-data (1.2019.3)
|
43
|
+
tzinfo (>= 1.0.0)
|
44
|
+
|
45
|
+
PLATFORMS
|
46
|
+
ruby
|
47
|
+
|
48
|
+
DEPENDENCIES
|
49
|
+
bundler (~> 1.0)
|
50
|
+
fa-harness-tools!
|
51
|
+
rake (~> 10.0)
|
52
|
+
rspec (~> 3.8)
|
53
|
+
timecop (~> 0.9)
|
54
|
+
|
55
|
+
BUNDLED WITH
|
56
|
+
1.16.4
|
data/LICENSE
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
# fa-harness-tools
|
2
|
+
|
3
|
+
FreeAgent-specific pre-flight checks and tools that are designed to work in [Harness](https://harness.io).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'fa-harness-tools'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install fa-harness-tools
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Examples below use [variables defined by Harness](https://docs.harness.io/article/9dvxcegm90-variables) so should be suitable to use directly in Harness scripts.
|
24
|
+
|
25
|
+
### Required environment variables
|
26
|
+
|
27
|
+
* `GITHUB_OAUTH_TOKEN` must be exported, containing a valid [personal access token](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line) for GitHub
|
28
|
+
|
29
|
+
### check-branch-brotection
|
30
|
+
|
31
|
+
Check the new build/commit being deployed is on the master branch:
|
32
|
+
|
33
|
+
```
|
34
|
+
bundle exec exe/check-branch-protection -r ${artifact.source.repositoryName} -e ${env.name} -b ${artifact.buildNo}
|
35
|
+
```
|
36
|
+
|
37
|
+
(Branch name etc can be changed, see `--help` for more options.)
|
38
|
+
|
39
|
+
### check-forward-deploy
|
40
|
+
|
41
|
+
Using a Git tag indicating the last deployment, check that the new commit being deployed is a descendant of the current commit:
|
42
|
+
|
43
|
+
```
|
44
|
+
bundle exec exe/check-forward-deploy -r ${artifact.source.repositoryName} -e ${env.name} -b ${artifact.buildNo}
|
45
|
+
```
|
46
|
+
|
47
|
+
(Tag prefix etc can be changed, see `--help` for more options.)
|
48
|
+
|
49
|
+
### check-recent-deploy
|
50
|
+
|
51
|
+
Using Git tags indicating recent deployments, check the commit being deployed is one of the last X commits or newer. Allows a user to rollback by X deployments.
|
52
|
+
|
53
|
+
```
|
54
|
+
bundle exec exe/check-recent-deploy -r ${artifact.source.repositoryName} -e ${env.name} -b ${artifact.buildNo}
|
55
|
+
```
|
56
|
+
|
57
|
+
(Allowed rollback count and tag prefix etc can be changed, see `--help` for more options.)
|
58
|
+
|
59
|
+
### check-schedule
|
60
|
+
|
61
|
+
Check the current time is within the deployment window of Mon-Thu 9am to 4pm, or Fri 9am to 12pm, using local London time.
|
62
|
+
|
63
|
+
```
|
64
|
+
bundle exec exe/check-schedule
|
65
|
+
```
|
66
|
+
|
67
|
+
### create-deployment-tag
|
68
|
+
|
69
|
+
Creates a Git tag in the project repository to indicate the deployment has happened:
|
70
|
+
|
71
|
+
```
|
72
|
+
bundle exec exe/create-deployment-tag -r ${artifact.source.repositoryName} -e ${env.name} -b ${artifact.buildNo}
|
73
|
+
```
|
74
|
+
|
75
|
+
(Tagger's name and email address etc can be changed, see `--help` for more options.)
|
76
|
+
|
77
|
+
## Development
|
78
|
+
|
79
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
80
|
+
|
81
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
82
|
+
|
83
|
+
To release a new version, update the version number in `version.rb`, run `bundle` and commit the version bump. Then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
84
|
+
|
85
|
+
The Ruby version used matches the one from the `harness/delegate` Docker image.
|
86
|
+
|
87
|
+
## Contributing
|
88
|
+
|
89
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/fac/fa-harness-tools
|
90
|
+
|
91
|
+
## Licence
|
92
|
+
|
93
|
+
Copyright 2019 FreeAgent Central Ltd.
|
94
|
+
|
95
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
96
|
+
you may not use this file except in compliance with the License.
|
97
|
+
You may obtain a copy of the License at
|
98
|
+
|
99
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
100
|
+
|
101
|
+
Unless required by applicable law or agreed to in writing, software
|
102
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
103
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
104
|
+
See the License for the specific language governing permissions and
|
105
|
+
limitations under the License.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "fa-harness-tools"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "fa-harness-tools"
|
4
|
+
require "optparse"
|
5
|
+
|
6
|
+
options = {
|
7
|
+
github_owner: "fac",
|
8
|
+
branch: "master",
|
9
|
+
}
|
10
|
+
OptionParser.new do |opts|
|
11
|
+
opts.banner = "Usage: check-branch-protection [options]"
|
12
|
+
|
13
|
+
opts.on("--branch NAME", "Git branch to verify this deployed commit is on, defaults to 'master'") do |v|
|
14
|
+
options[:branch] = v
|
15
|
+
end
|
16
|
+
|
17
|
+
opts.on("-b", "--build-no REVISION", "Build number/deployment revision") do |v|
|
18
|
+
options[:build_no] = v
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on("-e", "--environment NAME", "Environment name") do |v|
|
22
|
+
options[:environment] = v
|
23
|
+
end
|
24
|
+
|
25
|
+
opts.on("--github-owner NAME", "GitHub organisation/owner name, defaults to 'fac'") do |v|
|
26
|
+
options[:github_owner] = v
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on("-r", "--repository NAME", "GitHub repository name") do |v|
|
30
|
+
options[:repo] = v
|
31
|
+
end
|
32
|
+
end.parse!
|
33
|
+
|
34
|
+
client = FaHarnessTools::GithubClient.new(
|
35
|
+
oauth_token: ENV.fetch("GITHUB_OAUTH_TOKEN"),
|
36
|
+
owner: options.fetch(:github_owner),
|
37
|
+
repo: options.fetch(:repo),
|
38
|
+
)
|
39
|
+
context = FaHarnessTools::HarnessContext.new(
|
40
|
+
client: client,
|
41
|
+
environment: options.fetch(:environment),
|
42
|
+
build_no: options.fetch(:build_no),
|
43
|
+
)
|
44
|
+
|
45
|
+
result = FaHarnessTools::CheckBranchProtection.new(
|
46
|
+
client: client,
|
47
|
+
context: context,
|
48
|
+
branch: options.fetch(:branch),
|
49
|
+
).verify?
|
50
|
+
|
51
|
+
if result.first
|
52
|
+
puts result.last
|
53
|
+
exit 0
|
54
|
+
else
|
55
|
+
$stderr.puts result.last
|
56
|
+
exit 1
|
57
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "fa-harness-tools"
|
4
|
+
require "optparse"
|
5
|
+
|
6
|
+
options = {
|
7
|
+
github_owner: "fac",
|
8
|
+
tag_prefix: "harness-deploy",
|
9
|
+
}
|
10
|
+
OptionParser.new do |opts|
|
11
|
+
opts.banner = "Usage: check-forward-deploy [options]"
|
12
|
+
|
13
|
+
opts.on("-b", "--build-no REVISION", "Build number/deployment revision") do |v|
|
14
|
+
options[:build_no] = v
|
15
|
+
end
|
16
|
+
|
17
|
+
opts.on("-e", "--environment NAME", "Environment name") do |v|
|
18
|
+
options[:environment] = v
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on("--github-owner NAME", "GitHub organisation/owner name, defaults to 'fac'") do |v|
|
22
|
+
options[:github_owner] = v
|
23
|
+
end
|
24
|
+
|
25
|
+
opts.on("-r", "--repository NAME", "GitHub repository name") do |v|
|
26
|
+
options[:repo] = v
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on("--tag-prefix PREFIX", "Git tag prefix, defaults to 'harness-deploy'") do |v|
|
30
|
+
options[:tag_prefix] = v
|
31
|
+
end
|
32
|
+
end.parse!
|
33
|
+
|
34
|
+
client = FaHarnessTools::GithubClient.new(
|
35
|
+
oauth_token: ENV.fetch("GITHUB_OAUTH_TOKEN"),
|
36
|
+
owner: options.fetch(:github_owner),
|
37
|
+
repo: options.fetch(:repo),
|
38
|
+
)
|
39
|
+
context = FaHarnessTools::HarnessContext.new(
|
40
|
+
client: client,
|
41
|
+
environment: options.fetch(:environment),
|
42
|
+
build_no: options.fetch(:build_no),
|
43
|
+
)
|
44
|
+
|
45
|
+
result = FaHarnessTools::CheckForwardDeploy.new(
|
46
|
+
client: client,
|
47
|
+
context: context,
|
48
|
+
tag_prefix: options.fetch(:tag_prefix),
|
49
|
+
).verify?
|
50
|
+
|
51
|
+
if result.first
|
52
|
+
puts result.last
|
53
|
+
exit 0
|
54
|
+
else
|
55
|
+
$stderr.puts result.last
|
56
|
+
exit 1
|
57
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "fa-harness-tools"
|
4
|
+
require "optparse"
|
5
|
+
|
6
|
+
options = {
|
7
|
+
allowed_rollback_count: 3,
|
8
|
+
github_owner: "fac",
|
9
|
+
tag_prefix: "harness-deploy",
|
10
|
+
}
|
11
|
+
OptionParser.new do |opts|
|
12
|
+
opts.banner = "Usage: check-recent-deploy [options]"
|
13
|
+
|
14
|
+
opts.on("--allowed-rollback-count NUMBER", "Number of deployments that can be rolled back, defaults to 3") do |v|
|
15
|
+
options[:allowed_rollback_count] = v.to_i
|
16
|
+
end
|
17
|
+
|
18
|
+
opts.on("-b", "--build-no REVISION", "Build number/deployment revision") do |v|
|
19
|
+
options[:build_no] = v
|
20
|
+
end
|
21
|
+
|
22
|
+
opts.on("-e", "--environment NAME", "Environment name") do |v|
|
23
|
+
options[:environment] = v
|
24
|
+
end
|
25
|
+
|
26
|
+
opts.on("--github-owner NAME", "GitHub organisation/owner name, defaults to 'fac'") do |v|
|
27
|
+
options[:github_owner] = v
|
28
|
+
end
|
29
|
+
|
30
|
+
opts.on("-r", "--repository NAME", "GitHub repository name") do |v|
|
31
|
+
options[:repo] = v
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.on("--tag-prefix PREFIX", "Git tag prefix, defaults to 'harness-deploy'") do |v|
|
35
|
+
options[:tag_prefix] = v
|
36
|
+
end
|
37
|
+
end.parse!
|
38
|
+
|
39
|
+
client = FaHarnessTools::GithubClient.new(
|
40
|
+
oauth_token: ENV.fetch("GITHUB_OAUTH_TOKEN"),
|
41
|
+
owner: options.fetch(:github_owner),
|
42
|
+
repo: options.fetch(:repo),
|
43
|
+
)
|
44
|
+
context = FaHarnessTools::HarnessContext.new(
|
45
|
+
client: client,
|
46
|
+
environment: options.fetch(:environment),
|
47
|
+
build_no: options.fetch(:build_no),
|
48
|
+
)
|
49
|
+
|
50
|
+
result = FaHarnessTools::CheckRecentDeploy.new(
|
51
|
+
client: client,
|
52
|
+
context: context,
|
53
|
+
tag_prefix: options.fetch(:tag_prefix),
|
54
|
+
allowed_rollback_count: options.fetch(:allowed_rollback_count),
|
55
|
+
).verify?
|
56
|
+
|
57
|
+
if result.first
|
58
|
+
puts result.last
|
59
|
+
exit 0
|
60
|
+
else
|
61
|
+
$stderr.puts result.last
|
62
|
+
exit 1
|
63
|
+
end
|
data/exe/check-schedule
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "fa-harness-tools"
|
4
|
+
require "optparse"
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
OptionParser.new do |opts|
|
8
|
+
opts.banner = "Usage: check-schedule [options]"
|
9
|
+
end.parse!
|
10
|
+
|
11
|
+
result = FaHarnessTools::CheckSchedule.new.verify?
|
12
|
+
|
13
|
+
if result.first
|
14
|
+
puts result.last
|
15
|
+
exit 0
|
16
|
+
else
|
17
|
+
$stderr.puts result.last
|
18
|
+
exit 1
|
19
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "fa-harness-tools"
|
4
|
+
require "optparse"
|
5
|
+
require "time"
|
6
|
+
|
7
|
+
options = {
|
8
|
+
github_owner: "fac",
|
9
|
+
tag_prefix: "harness-deploy",
|
10
|
+
tagger_email: "harness@example.com",
|
11
|
+
tagger_name: "Harness",
|
12
|
+
}
|
13
|
+
OptionParser.new do |opts|
|
14
|
+
opts.banner = "Usage: create-deployment-tag [options]"
|
15
|
+
|
16
|
+
opts.on("-b", "--build-no REVISION", "Build number/deployment revision") do |v|
|
17
|
+
options[:build_no] = v
|
18
|
+
end
|
19
|
+
|
20
|
+
opts.on("-e", "--environment NAME", "Environment name") do |v|
|
21
|
+
options[:environment] = v
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.on("--github-owner NAME", "GitHub organisation/owner name, defaults to 'fac'") do |v|
|
25
|
+
options[:github_owner] = v
|
26
|
+
end
|
27
|
+
|
28
|
+
opts.on("-r", "--repository NAME", "GitHub repository name") do |v|
|
29
|
+
options[:repo] = v
|
30
|
+
end
|
31
|
+
|
32
|
+
opts.on("--tag-prefix PREFIX", "Git tag prefix, defaults to 'harness-deploy'") do |v|
|
33
|
+
options[:tag_prefix] = v
|
34
|
+
end
|
35
|
+
|
36
|
+
opts.on("--tagger-email EMAIL", "Author email address for the Git tag, defaults to 'harness@example.com'") do |v|
|
37
|
+
options[:tagger_email] = v
|
38
|
+
end
|
39
|
+
|
40
|
+
opts.on("--tagger-name NAME", "Author name for the Git tag, defaults to 'Harness'") do |v|
|
41
|
+
options[:tagger_name] = v
|
42
|
+
end
|
43
|
+
end.parse!
|
44
|
+
|
45
|
+
client = FaHarnessTools::GithubClient.new(
|
46
|
+
oauth_token: ENV.fetch("GITHUB_OAUTH_TOKEN"),
|
47
|
+
owner: options.fetch(:github_owner),
|
48
|
+
repo: options.fetch(:repo),
|
49
|
+
)
|
50
|
+
context = FaHarnessTools::HarnessContext.new(
|
51
|
+
client: client,
|
52
|
+
environment: options.fetch(:environment),
|
53
|
+
build_no: options.fetch(:build_no),
|
54
|
+
)
|
55
|
+
|
56
|
+
tag_time = Time.now.utc
|
57
|
+
timestamp = tag_time.strftime("%Y-%m-%dT%H-%M-%SZ")
|
58
|
+
|
59
|
+
tag = client.create_tag(
|
60
|
+
"#{options.fetch(:tag_prefix)}-#{context.environment}-#{timestamp}",
|
61
|
+
"Harness deployment at #{timestamp}",
|
62
|
+
context.new_commit_sha,
|
63
|
+
"commit",
|
64
|
+
options.fetch(:tagger_name),
|
65
|
+
options.fetch(:tagger_email),
|
66
|
+
tag_time.strftime("%Y-%m-%dT%H:%M:%SZ"),
|
67
|
+
)
|
68
|
+
|
69
|
+
puts "Created tag #{tag[:tag]}"
|
@@ -0,0 +1,37 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "fa-harness-tools/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "fa-harness-tools"
|
7
|
+
spec.version = FaHarnessTools::VERSION
|
8
|
+
spec.authors = ["FreeAgent"]
|
9
|
+
spec.email = ["opensource@freeagent.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{Tools including preflight checks for Harness.io}
|
12
|
+
spec.description = %q{FreeAgent-specific pre-flight checks and tools that are designed to work in Harness.io}
|
13
|
+
spec.homepage = "https://github.com/fac/fa-harness-tools"
|
14
|
+
spec.license = "Apache-2.0"
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
18
|
+
spec.metadata["changelog_uri"] = "https://github.com/fac/fa-harness-tools/releases"
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_runtime_dependency "octokit", "~> 4.0"
|
30
|
+
spec.add_runtime_dependency "tzinfo", "~> 2.0"
|
31
|
+
spec.add_runtime_dependency "tzinfo-data", "~> 1.0"
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.0"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.8"
|
36
|
+
spec.add_development_dependency "timecop", "~> 0.9"
|
37
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "fa-harness-tools/check_branch_protection"
|
2
|
+
require "fa-harness-tools/check_forward_deploy"
|
3
|
+
require "fa-harness-tools/check_recent_deploy"
|
4
|
+
require "fa-harness-tools/check_schedule"
|
5
|
+
require "fa-harness-tools/github_client"
|
6
|
+
require "fa-harness-tools/harness_context"
|
7
|
+
require "fa-harness-tools/version"
|
8
|
+
|
9
|
+
module FaHarnessTools
|
10
|
+
LookupError = Class.new(StandardError)
|
11
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module FaHarnessTools
|
2
|
+
# Check if the sha being deployed belongs to the given branch.
|
3
|
+
class CheckBranchProtection
|
4
|
+
def initialize(client:, context:, branch:)
|
5
|
+
@client = client
|
6
|
+
@context = context
|
7
|
+
@branch = branch
|
8
|
+
end
|
9
|
+
|
10
|
+
def verify?
|
11
|
+
new_sha = @context.new_commit_sha
|
12
|
+
if @client.branch_contains?(@branch, new_sha)
|
13
|
+
[true, "#{@branch} contains #{new_sha}"]
|
14
|
+
else
|
15
|
+
[false, "#{@branch} does not contain #{new_sha}"]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module FaHarnessTools
|
2
|
+
# Checks if the revision to deploy is ahead of the deployed revision, a
|
3
|
+
# forward deploy. The currently deployed revision is an ancestor of the
|
4
|
+
# revision to deploy.
|
5
|
+
#
|
6
|
+
# In order to work out what is currently deployed it checks for tags with
|
7
|
+
# the configured tag_prefix, the newest of those is considered the current
|
8
|
+
# version.
|
9
|
+
# If there are none of those tags at all it will allow, to avoid creating an
|
10
|
+
# un-passable check!
|
11
|
+
class CheckForwardDeploy
|
12
|
+
def initialize(client:, context:, tag_prefix:)
|
13
|
+
@client = client
|
14
|
+
@context = context
|
15
|
+
@tag_prefix = tag_prefix
|
16
|
+
end
|
17
|
+
|
18
|
+
def verify?
|
19
|
+
current_tag = @client.last_deploy_tag(
|
20
|
+
prefix: @tag_prefix, environment: @context.environment)
|
21
|
+
|
22
|
+
if current_tag.nil?
|
23
|
+
# If no previous deploys we need to let it deploy otherwise it will
|
24
|
+
# never get past this check!
|
25
|
+
return true, "first deploy"
|
26
|
+
end
|
27
|
+
|
28
|
+
current_deployed_rev = current_tag[:commit][:sha]
|
29
|
+
rev = @context.new_commit_sha
|
30
|
+
|
31
|
+
if @client.is_ancestor_of?(current_deployed_rev, rev)
|
32
|
+
[true, "forward deploy, #{rev} is ahead of #{current_deployed_rev}"]
|
33
|
+
else
|
34
|
+
[false, "not a forward deploy, #{rev} is behind #{current_deployed_rev}"]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module FaHarnessTools
|
2
|
+
# CheckRecentDeploy only allows deployer to deploy commits with `deploy_tag_prefix` ahead of (and include) Nth most recent commit
|
3
|
+
# with the give tag.
|
4
|
+
#
|
5
|
+
# For example if the commit history is like
|
6
|
+
#
|
7
|
+
# SHA 1
|
8
|
+
# SHA 2 - tag: production-deploy-1
|
9
|
+
# SHA 3
|
10
|
+
# SHA 4 - tag: production-deploy-2
|
11
|
+
# SHA 5
|
12
|
+
# SHA 6 - tag: production-deploy-3
|
13
|
+
# SHA 7
|
14
|
+
# SHA 8 - tag: production-deploy-4
|
15
|
+
#
|
16
|
+
# If the age deploy check is set to
|
17
|
+
# tag_prefix: "production-deploy"
|
18
|
+
# allowed_rollback_count: 2
|
19
|
+
#
|
20
|
+
# Then SHA 1 - 4 would be allowed, however SHA 5 - 8 would get denied
|
21
|
+
#
|
22
|
+
# Notes if the tag `production-deploy-` doesn't exist in Git history, the check returns allow
|
23
|
+
#
|
24
|
+
class CheckRecentDeploy
|
25
|
+
def initialize(client:, context:, tag_prefix:, allowed_rollback_count:)
|
26
|
+
@client = client
|
27
|
+
@context = context
|
28
|
+
@tag_prefix = tag_prefix
|
29
|
+
@allowed_rollback_count = allowed_rollback_count
|
30
|
+
end
|
31
|
+
|
32
|
+
def verify?
|
33
|
+
tags = @client.
|
34
|
+
all_deploy_tags(prefix: @tag_prefix, environment: @context.environment).
|
35
|
+
sort_by { |tag| tag[:name] }
|
36
|
+
|
37
|
+
latest_allowed_tag = tags.last(@allowed_rollback_count).first
|
38
|
+
|
39
|
+
if latest_allowed_tag.nil?
|
40
|
+
# If no previous deploys we need to let it deploy otherwise it will
|
41
|
+
# never get past this check!
|
42
|
+
return true, "first deploy"
|
43
|
+
end
|
44
|
+
|
45
|
+
latest_allowed_rev = latest_allowed_tag[:commit][:sha]
|
46
|
+
rev = @context.new_commit_sha
|
47
|
+
|
48
|
+
if @client.is_ancestor_of?(latest_allowed_rev, rev)
|
49
|
+
[true, "#{rev} is ahead of no.#{@allowed_rollback_count} most recent commit with #{@tag_prefix.inspect} tag"]
|
50
|
+
else
|
51
|
+
[false, "#{rev} is prior to no.#{@allowed_rollback_count} most recent commit with #{@tag_prefix.inspect} tag"]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "time"
|
2
|
+
require "tzinfo"
|
3
|
+
|
4
|
+
module FaHarnessTools
|
5
|
+
# Check against the time of day so you can restrict deploying to sensible
|
6
|
+
# hours. Uses local London time by default.
|
7
|
+
#
|
8
|
+
# Restricts to Mon-Thu from 9am to 4pm, Fri from 9am to 12pm.
|
9
|
+
class CheckSchedule
|
10
|
+
def initialize(timezone: "Europe/London")
|
11
|
+
tz = TZInfo::Timezone.get(timezone)
|
12
|
+
@now = tz.to_local(Time.now.utc)
|
13
|
+
end
|
14
|
+
|
15
|
+
def verify?
|
16
|
+
permitted = false
|
17
|
+
case @now.wday
|
18
|
+
when 1..4
|
19
|
+
permitted = true if @now.hour >= 9 && @now.hour < 16
|
20
|
+
when 5
|
21
|
+
permitted = true if @now.hour >= 9 && @now.hour < 12
|
22
|
+
end
|
23
|
+
|
24
|
+
if permitted
|
25
|
+
[true, "scheduled deploy time"]
|
26
|
+
else
|
27
|
+
[false, "outside deployment schedule"]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require "octokit"
|
2
|
+
|
3
|
+
# Wraps the GitHub operations we're using
|
4
|
+
module FaHarnessTools
|
5
|
+
class GithubClient
|
6
|
+
attr_reader :owner, :repo
|
7
|
+
|
8
|
+
def initialize(oauth_token:, owner:, repo:)
|
9
|
+
@octokit = Octokit::Client.new(access_token: oauth_token)
|
10
|
+
@owner = owner
|
11
|
+
@repo = repo
|
12
|
+
end
|
13
|
+
|
14
|
+
def owner_repo
|
15
|
+
"#{owner}/#{repo}"
|
16
|
+
end
|
17
|
+
|
18
|
+
# Return all tags starting "harness-deploy-ENV-"
|
19
|
+
#
|
20
|
+
# Used to find deployments in an environment. The commit SHA of the tag is
|
21
|
+
# in [:commit][:sha] in the returned hash.
|
22
|
+
#
|
23
|
+
# @return [Array[Hash]] Array of tag data hash, or [] if none
|
24
|
+
def all_deploy_tags(prefix:, environment:)
|
25
|
+
@octokit.auto_paginate = true
|
26
|
+
@octokit.tags(owner_repo).find_all do |tag|
|
27
|
+
tag[:name].start_with?("#{prefix}-#{environment}-")
|
28
|
+
end
|
29
|
+
ensure
|
30
|
+
@octokit.auto_paginate = false
|
31
|
+
end
|
32
|
+
|
33
|
+
# Return the last (when sorted) tag starting "harness-deploy-ENV-"
|
34
|
+
#
|
35
|
+
# Used to find the most recent deployment in an environment. The commit SHA
|
36
|
+
# of the tag is in [:commit][:sha] in the returned hash.
|
37
|
+
#
|
38
|
+
# @return [Hash] Tag data hash, or nil if none
|
39
|
+
def last_deploy_tag(prefix:, environment:)
|
40
|
+
last_tag = all_deploy_tags(prefix: prefix, environment: environment).
|
41
|
+
sort_by { |tag| tag[:name] }.last
|
42
|
+
last_tag ? last_tag : nil
|
43
|
+
end
|
44
|
+
|
45
|
+
# Return a full commit SHA from a short SHA
|
46
|
+
#
|
47
|
+
# @return [String] Full commit SHA
|
48
|
+
# @raise [LookupError] If short SHA cannot be found
|
49
|
+
def get_commit_sha(short_sha)
|
50
|
+
commit = @octokit.commit(owner_repo, short_sha)
|
51
|
+
raise LookupError, "Unable to find commit #{short_sha} in Git repo" unless commit
|
52
|
+
commit[:sha]
|
53
|
+
end
|
54
|
+
|
55
|
+
# Checks if <ancestor> is an ancestor of <commit>
|
56
|
+
#
|
57
|
+
# i.e. commit and ancestor are directly related
|
58
|
+
#
|
59
|
+
# @return [Bool] True is <ancestor> is ancestor of <commit>
|
60
|
+
def is_ancestor_of?(ancestor, commit)
|
61
|
+
!!find_commit(commit) { |c| c[:sha] == ancestor }
|
62
|
+
end
|
63
|
+
|
64
|
+
# Checks if <commit> is on branch <branch>
|
65
|
+
#
|
66
|
+
# @return [Bool] True is <commit> is on <branch>
|
67
|
+
def branch_contains?(branch, commit)
|
68
|
+
!!find_commit(branch) { |c| c[:sha] == commit }
|
69
|
+
end
|
70
|
+
|
71
|
+
# Creates a Git tag
|
72
|
+
#
|
73
|
+
# Arguments match Octokit::Client::Objects#create_tag, minus first repo argument
|
74
|
+
# (http://octokit.github.io/octokit.rb/Octokit/Client/Objects.html#create_tag-instance_method)
|
75
|
+
def create_tag(tag, message, commit_sha, *args)
|
76
|
+
@octokit.create_ref(owner_repo, "tags/#{tag}", commit_sha)
|
77
|
+
@octokit.create_tag(owner_repo, tag, message, commit_sha, *args)
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
# Paginate over commits from a given sha/branch, and exit early if the
|
83
|
+
# supplied block matches
|
84
|
+
def find_commit(sha_or_branch, &block)
|
85
|
+
result = @octokit.commits(owner_repo, sha_or_branch).find(&block)
|
86
|
+
response = @octokit.last_response
|
87
|
+
until result || !response.rels[:next]
|
88
|
+
response = response.rels[:next].get
|
89
|
+
result = response.data.find(&block)
|
90
|
+
end
|
91
|
+
result
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module FaHarnessTools
|
2
|
+
class HarnessContext
|
3
|
+
attr_reader :environment
|
4
|
+
|
5
|
+
def initialize(client:, environment:, build_no:)
|
6
|
+
@client = client
|
7
|
+
@environment = environment
|
8
|
+
@build_no = build_no
|
9
|
+
end
|
10
|
+
|
11
|
+
def new_commit_sha
|
12
|
+
@client.get_commit_sha(@build_no)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fa-harness-tools
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- FreeAgent
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-11-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: octokit
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: tzinfo
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: tzinfo-data
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.8'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.8'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: timecop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.9'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.9'
|
111
|
+
description: FreeAgent-specific pre-flight checks and tools that are designed to work
|
112
|
+
in Harness.io
|
113
|
+
email:
|
114
|
+
- opensource@freeagent.com
|
115
|
+
executables:
|
116
|
+
- check-branch-protection
|
117
|
+
- check-forward-deploy
|
118
|
+
- check-recent-deploy
|
119
|
+
- check-schedule
|
120
|
+
- create-deployment-tag
|
121
|
+
extensions: []
|
122
|
+
extra_rdoc_files: []
|
123
|
+
files:
|
124
|
+
- ".github/workflows/ruby.yml"
|
125
|
+
- ".gitignore"
|
126
|
+
- ".rspec"
|
127
|
+
- ".ruby-version"
|
128
|
+
- CODE_OF_CONDUCT.md
|
129
|
+
- Gemfile
|
130
|
+
- Gemfile.lock
|
131
|
+
- LICENSE
|
132
|
+
- README.md
|
133
|
+
- Rakefile
|
134
|
+
- bin/console
|
135
|
+
- bin/setup
|
136
|
+
- exe/check-branch-protection
|
137
|
+
- exe/check-forward-deploy
|
138
|
+
- exe/check-recent-deploy
|
139
|
+
- exe/check-schedule
|
140
|
+
- exe/create-deployment-tag
|
141
|
+
- fa-harness-tools.gemspec
|
142
|
+
- lib/fa-harness-tools.rb
|
143
|
+
- lib/fa-harness-tools/check_branch_protection.rb
|
144
|
+
- lib/fa-harness-tools/check_forward_deploy.rb
|
145
|
+
- lib/fa-harness-tools/check_recent_deploy.rb
|
146
|
+
- lib/fa-harness-tools/check_schedule.rb
|
147
|
+
- lib/fa-harness-tools/github_client.rb
|
148
|
+
- lib/fa-harness-tools/harness_context.rb
|
149
|
+
- lib/fa-harness-tools/version.rb
|
150
|
+
homepage: https://github.com/fac/fa-harness-tools
|
151
|
+
licenses:
|
152
|
+
- Apache-2.0
|
153
|
+
metadata:
|
154
|
+
homepage_uri: https://github.com/fac/fa-harness-tools
|
155
|
+
source_code_uri: https://github.com/fac/fa-harness-tools
|
156
|
+
changelog_uri: https://github.com/fac/fa-harness-tools/releases
|
157
|
+
post_install_message:
|
158
|
+
rdoc_options: []
|
159
|
+
require_paths:
|
160
|
+
- lib
|
161
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - ">="
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
requirements: []
|
172
|
+
rubyforge_project:
|
173
|
+
rubygems_version: 2.7.6
|
174
|
+
signing_key:
|
175
|
+
specification_version: 4
|
176
|
+
summary: Tools including preflight checks for Harness.io
|
177
|
+
test_files: []
|