samus 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +22 -0
  3. data/README.md +255 -0
  4. data/bin/samus +87 -0
  5. data/commands/build/archive-git-full +3 -0
  6. data/commands/build/archive-git-full.help.md +7 -0
  7. data/commands/build/archive-tgz +3 -0
  8. data/commands/build/archive-tgz.help.md +7 -0
  9. data/commands/build/archive-zip +3 -0
  10. data/commands/build/archive-zip.help.md +7 -0
  11. data/commands/build/fs-copy +3 -0
  12. data/commands/build/fs-copy.help.md +8 -0
  13. data/commands/build/fs-mkdir +3 -0
  14. data/commands/build/fs-mkdir.help.md +7 -0
  15. data/commands/build/fs-rmrf +3 -0
  16. data/commands/build/fs-rmrf.help.md +7 -0
  17. data/commands/build/fs-sedfiles +7 -0
  18. data/commands/build/fs-sedfiles.help.md +8 -0
  19. data/commands/build/gem-build +5 -0
  20. data/commands/build/gem-build.help.md +7 -0
  21. data/commands/build/git-archive +3 -0
  22. data/commands/build/git-archive.help.md +8 -0
  23. data/commands/build/git-commit +7 -0
  24. data/commands/build/git-commit.help.md +8 -0
  25. data/commands/build/git-merge +9 -0
  26. data/commands/build/git-merge.help.md +8 -0
  27. data/commands/build/npm-test +3 -0
  28. data/commands/build/npm-test.help.md +7 -0
  29. data/commands/build/rake-task +3 -0
  30. data/commands/build/rake-task.help.md +7 -0
  31. data/commands/publish/cf-invalidate +16 -0
  32. data/commands/publish/cf-invalidate.help.md +8 -0
  33. data/commands/publish/gem-push +6 -0
  34. data/commands/publish/gem-push.help.md +7 -0
  35. data/commands/publish/git-push +15 -0
  36. data/commands/publish/git-push.help.md +8 -0
  37. data/commands/publish/npm-publish +3 -0
  38. data/commands/publish/npm-publish.help.md +7 -0
  39. data/commands/publish/s3-put +13 -0
  40. data/commands/publish/s3-put.help.md +10 -0
  41. data/lib/samus.rb +37 -0
  42. data/lib/samus/action.rb +60 -0
  43. data/lib/samus/build_action.rb +46 -0
  44. data/lib/samus/builder.rb +101 -0
  45. data/lib/samus/command.rb +99 -0
  46. data/lib/samus/credentials.rb +48 -0
  47. data/lib/samus/publish_action.rb +7 -0
  48. data/lib/samus/publisher.rb +38 -0
  49. data/lib/samus/version.rb +3 -0
  50. data/samus.gemspec +13 -0
  51. data/samus.json +44 -0
  52. metadata +95 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 500fa4456778f282bf501ea9d1731a5199f0a2bd
4
+ data.tar.gz: 1bfac1ac68d3be949d286dacdec5ef710609c2a8
5
+ SHA512:
6
+ metadata.gz: bb354e91c9058f483c8a339ffc9b0f331b152e92a548dd6516c86bd2a56e3caa308dcbad3d287f5cd4ffa2ebb423c438ee48929e8660ab60afb2174810532be2
7
+ data.tar.gz: 21d5e9b38e12c614416c75eff044a8c94b49900f913a3e1e2635d6f86c6dcf6f50dd34ca6a3602700e2897a0c8373d967857e78f09048720dccc2118570d4617
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Loren Segal
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,255 @@
1
+ # Samus
2
+
3
+ Samus helps you automate the release of Open Source Software. Samus works
4
+ through a manifest file to describe discrete steps that you typically perform
5
+ when packaging and publishing code.
6
+
7
+ Samus comes with a set of built-in commands that let you prepare your
8
+ repository, push your changes, package your library, and upload it to various
9
+ locations / package managers. Samus is also open-source, so you can contribute
10
+ new commands if you think they are useful to others. Finally, Samus allows you
11
+ to install and share custom commands and credentials for building and publishing
12
+ your code. That's right, Samus has a mechanism to share publishing credentials
13
+ in a fairly secure way, so you can reliably publish releases from almost any
14
+ machine.
15
+
16
+ ## Usage
17
+
18
+ Samus is driven by a manifest file that describes the steps to perform when
19
+ building or publishing a release. You can just use Samus to publish, or you
20
+ can use it for both, it's your choice.
21
+
22
+ ### Publishing
23
+
24
+ If you can handle building all of your assets on your own, you can use Samus
25
+ just to publish your code. Create a manifest file called manifest.json and
26
+ put it in a directory with all of your assets. The manifest file is just a
27
+ list of discrete actions like so (minus comments):
28
+
29
+ ```js
30
+ {
31
+ "actions": [
32
+ {
33
+ "files": "git.tgz", // this is an archive of your git repository
34
+ "action": "git-push",
35
+ "arguments": {
36
+ "remotes": "origin",
37
+ "refs": "master v1.5.0" // the v1.5.0 is a tag for your release
38
+ }
39
+ },
40
+ {
41
+ "action": "gem-push",
42
+ "files": ["my-built-gemfile.gem"],
43
+ "credentials": "my-credentials-key"
44
+ }
45
+ ]
46
+ }
47
+ ```
48
+
49
+ Note: The credentials section defines a flat file or executable Samus looks
50
+ at to get your key for authentication. See the "Custom Commands & Credentials"
51
+ section below for how to point to this file.
52
+
53
+ Now just run `samus publish .`, and Samus will run these commands in order,
54
+ pushing your Git repository and your RubyGem to the world.
55
+
56
+ ### Building
57
+
58
+ In most cases you will want some help staging a release; Samus can help with
59
+ that too. Just in the same way you created a manifest for publishing, you
60
+ create a manifest file for building your release. The only difference is now
61
+ you include build-time actions, in addition to your publish actions.
62
+
63
+ Here is an example that updates your version.rb file, commits and tags the
64
+ release, and zips up your repository and RubyGem for publishing. Call
65
+ it "samus.json" for easier integration:
66
+
67
+ ```js
68
+ // samus.json:
69
+ {
70
+ "actions": [
71
+ {
72
+ "action": "fs-sedfiles",
73
+ "files": ["lib/my-gem/version.rb"],
74
+ "arguments": {
75
+ "search": "VERSION = ['\"](.+?)['\"]",
76
+ "replace": "VERSION = '$version'"
77
+ }
78
+ },
79
+ {
80
+ "action": "git-commit",
81
+ "files": ["lib/my-gem/version.rb"]
82
+ },
83
+ {
84
+ "action": "git-merge", // merge new commit into master branch
85
+ "arguments": {
86
+ "branch": "master"
87
+ }
88
+ },
89
+ {
90
+ "action": "archive-git-full",
91
+ "files": ["git.tgz"],
92
+ "publish": [{
93
+ "action": "git-push",
94
+ "arguments": {
95
+ "remotes": "origin",
96
+ "refs": "master v$version"
97
+ }
98
+ }]
99
+ },
100
+ {
101
+ "action": "gem-build",
102
+ "files": ["my-gem.gemspec"],
103
+ "publish": [
104
+ {
105
+ "action": "gem-push",
106
+ "files": ["my-gem-$version.gem"],
107
+ "credentials": "my-credentials-key"
108
+ }
109
+ ]
110
+ }
111
+ ]
112
+ }
113
+ ```
114
+
115
+ It looks a little longer, but it contains all of the steps to automate when
116
+ bumping the VERSION constant, tagging a version, merging into the master
117
+ branch, and building the gem. To build a release with this manifest, simply
118
+ type:
119
+
120
+ ```sh
121
+ $ samus build 1.5.0
122
+ ```
123
+
124
+ Samus will look for `samus.json` and build a release for version 1.5.0 of your
125
+ code. It will produce an archive called `release-v1.5.0.tar.gz` that you
126
+ can then publish with:
127
+
128
+ ```sh
129
+ $ samus publish release-v1.5.0.tar.gz
130
+ ```
131
+
132
+ You may have noticed some funny looking "$version" strings in the above
133
+ manifest. Those strings will be replaced with the version provided in the
134
+ build command, so all the correct tagging and building will be handled for you.
135
+
136
+ You will also notice that the publish commands are part of this manifest.
137
+ In build mode, Samus handles building of the manifest.json document, grabbing
138
+ any of the "publish" sections of an action and throwing them in the final
139
+ manifest.json. As illustrated above, not all actions require a publish section.
140
+ If you want to inspect the manifest file that Samus created, you can build
141
+ your release as a directory instead of a zip with `--no-zip`.
142
+
143
+ Note: If you didn't name your manifest samus.json you can simply enter the
144
+ filename in the build command as `samus build VERSION manifest.json`.
145
+
146
+ ## Built-in Commands
147
+
148
+ Samus comes with a number of built-in commands optimized for dealing with
149
+ the Git workflow. You can use `samus show-cmd` to list all available commands,
150
+ both for building and publishing a release. Each command has documentation
151
+ for which files and arguments it accepts.
152
+
153
+ ```sh
154
+ $ samus show-cmd
155
+ ... a list of commands ...
156
+ ```
157
+
158
+ To view a specific command, make sure to include the stage (`build` or
159
+ `publish`):
160
+
161
+ ```sh
162
+ $ samus show-cmd publish git-push
163
+ Publish Command: git-push
164
+
165
+ Pushes Git repository refs to a set of remotes.
166
+
167
+ Files:
168
+ * The repository archive filename.
169
+
170
+ Arguments:
171
+ * refs: a space delimited set of commits, branches, or tags to push.
172
+ * remotes: a space delimited set of remotes to push refs to.
173
+ ```
174
+
175
+ ## Custom Commands & Credentials
176
+
177
+ Sometimes you will need to create custom commands that do specific things
178
+ for your project. If they are generic, you should submit them to this project,
179
+ but if not, you can install custom commands that only you have access to.
180
+ This goes for credentials too, which you can install privately on your
181
+ machine.
182
+
183
+ Samus works best when custom packages are Git-backed (preferably private)
184
+ repositories. In this case, you can simply type `samus install REPO` to
185
+ download the repository to your machine:
186
+
187
+ ```sh
188
+ $ samus install git@github.com:my_org/samus_config
189
+ ```
190
+
191
+ Of course, Samus doesn't need these custom packages to be Git-backed. All
192
+ the above command does is clone a repository into the ~/.samus directory.
193
+ The above command creates:
194
+
195
+ ```
196
+ .samus/
197
+ `- samus_config/
198
+ `- commands/
199
+ `- build/
200
+ `- my-command
201
+ `- credentials/
202
+ `- my-credentials-key
203
+ ```
204
+
205
+ ### Commands
206
+
207
+ Commands in Samus are just shell scripts. Samus passes all argument values
208
+ (the keys from the "arguments" section of the manifest) in as environment
209
+ variables with a prefixed underscore. For example, the `rake-task` command
210
+ is just:
211
+
212
+ ```sh
213
+ #!/bin/sh
214
+
215
+ rake $_task
216
+ ```
217
+
218
+ The `$_task` variable is the "task" argument from the manifest.
219
+
220
+ ### Credentials
221
+
222
+ Custom credentials are just flat files or executables in the `credentials/`
223
+ directory of your custom package. When you use the "credentials" section in
224
+ a publish action of the manifest, the value should match the filename of
225
+ a file in one of your credentials directories. For instance, for the
226
+ `my-credentials-key` value in our manifest examples, you should have:
227
+
228
+ ```
229
+ .samus/samus_config/credentials/my-credentials-key
230
+ ```
231
+
232
+ This file is either a flat file with the format:
233
+
234
+ ```
235
+ Key: THE_API_KEY
236
+ Secret: THE_SECRET
237
+ ```
238
+
239
+ Or, alternatively, an *executable* which prints the above format to standard
240
+ out.
241
+
242
+ These values are read in by Samus and get exposed as `$__creds_key` and
243
+ `$__creds_secret` respectively in Samus commands. You can provide other
244
+ metadata as well, which would be included as `$__creds_name` (for the
245
+ line "NAME: value").
246
+
247
+ ## Contributing & TODO
248
+
249
+ Please help by contributing commands that Samus can use to build or publish
250
+ code. Integration with different package managers would be helpful, as well
251
+ as improving the kinds of build-time tasks that are exposed.
252
+
253
+ ## Copyright
254
+
255
+ Samus was created by Loren Segal in 2014 and is available under MIT license.
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/samus'
4
+ require 'optparse'
5
+ require 'tmpdir'
6
+
7
+ command = case ARGV.shift
8
+ when 'install'
9
+ Dir.mkdir(Samus::CONFIG_PATH) unless File.directory?(Samus::CONFIG_PATH)
10
+ Dir.chdir(Samus::CONFIG_PATH) { system "git clone #{ARGV.shift}" }
11
+ exit
12
+ when 'update'
13
+ Samus.config_paths.each do |path|
14
+ Dir.chdir(path) do
15
+ if File.directory?('.git')
16
+ puts "[I] Updating #{path}"
17
+ system "git pull"
18
+ else
19
+ puts "[S] Skipping non-Git directory #{path}"
20
+ end
21
+ end
22
+ end
23
+ exit
24
+ when 'show-cmd'
25
+ stage = ARGV.shift
26
+ if stage
27
+ name = ARGV.shift
28
+ if name
29
+ Samus::Command.new(stage, name).show_help
30
+ else
31
+ Samus::Command.list_commands(stage)
32
+ end
33
+ else
34
+ Samus::Command.list_commands
35
+ end
36
+ exit
37
+ when 'publish', 'push'; Samus::Publisher
38
+ when 'build'; Samus::Builder
39
+ end
40
+
41
+ dry_run = false
42
+ zip_release = true
43
+ opts = OptionParser.new do |opts|
44
+ opts.banner = "Usage: samus publish [options] <directory> [directory ...]\n"
45
+ opts.banner += " samus build [options] <version> [build.json]\n"
46
+ opts.banner += " samus show-cmd [stage] [name]\n"
47
+
48
+ opts.separator ""
49
+ opts.separator "Options:"
50
+ opts.on("--dry-run", "Print commands, don't run them") do |v|
51
+ dry_run = true
52
+ end
53
+ if command == Samus::Builder
54
+ opts.on("--[no-]zip", "Zip release directory") do |zip|
55
+ zip_release = zip
56
+ end
57
+ end
58
+ end
59
+ opts.parse!
60
+
61
+ if command == Samus::Publisher
62
+ ARGV.each do |dir|
63
+ fail "Aborting due to missing path #{dir}" unless File.exist?(dir)
64
+ end
65
+
66
+ ARGV.each do |dir|
67
+ if File.directory?(dir)
68
+ command.new(dir).publish(dry_run)
69
+ elsif File.file?(dir) # it has to be an archive
70
+ Dir.mktmpdir do |tmpdir|
71
+ system "tar -xzf #{dir} -C #{tmpdir}"
72
+ command.new(tmpdir).publish(dry_run)
73
+ end
74
+ end
75
+ end
76
+ elsif command == Samus::Builder
77
+ $VERSION = ARGV.shift
78
+ fail "Missing version" if $VERSION.nil?
79
+ $VERSION = $VERSION.sub(/^v/, '')
80
+
81
+ (ARGV.empty? ? ['samus.json'] : ARGV).each do |file|
82
+ command.new(file).build(dry_run, zip_release)
83
+ end
84
+ else
85
+ puts opts
86
+ exit 1
87
+ end
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+
3
+ tar cfz $__build_dir/$1 .git $(git ls-files)
@@ -0,0 +1,7 @@
1
+ Archives a complete Git repository (including .git directory).
2
+
3
+ Files:
4
+ * The name of the archived repository.
5
+
6
+ Arguments:
7
+ * (none)
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+
3
+ tar cfz $__build_dir/$1 $_paths
@@ -0,0 +1,7 @@
1
+ Archives a set of paths into a gzipped tar file.
2
+
3
+ Files:
4
+ * The name of the archive to build.
5
+
6
+ Arguments:
7
+ * paths: a space delimited set of paths to add to the archive.
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+
3
+ zip -qr $__build_dir/$1 $_paths
@@ -0,0 +1,7 @@
1
+ Archives a set of paths into a zip file.
2
+
3
+ Files:
4
+ * The name of the archive to build.
5
+
6
+ Arguments:
7
+ * paths: a space delimited set of paths to add to the archive.
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+
3
+ cp -r $* $__build_dir/$_destination
@@ -0,0 +1,8 @@
1
+ Copies a set of files into the build directory.
2
+
3
+ Files:
4
+ * A list of files to copy into the build directory.
5
+
6
+ Arguments:
7
+ * destination: (optional) a subdirectory within the build directory to copy
8
+ files to.
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+
3
+ mkdir -p $__build_dir/$*
@@ -0,0 +1,7 @@
1
+ Creates a sub-directory in the build directory.
2
+
3
+ Files:
4
+ * The subdirectory to create. Can be a complex directory.
5
+
6
+ Arguments:
7
+ * (none)
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+
3
+ rm -rf $*