-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from akerl-unpriv/v2
Golang conversion!
- Loading branch information
Showing
68 changed files
with
537 additions
and
1,701 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
pkg/*.gem | ||
coverage/ | ||
.coveralls.yml | ||
.bundle | ||
Gemfile.lock | ||
/.gopath | ||
/bin | ||
/vendor/ | ||
/pkg/ | ||
/.github | ||
/payload.zip | ||
/.tools/ | ||
/Dockerfile | ||
prospectus |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
my_slug = 'akerl/prospectus' | ||
#!/usr/bin/env ruby | ||
|
||
require 'prospectus' | ||
|
||
Prospectus.extra_dep('file', 'prospectus_travis') | ||
Prospectus.extra_dep('file', 'prospectus_gems') | ||
Prospectus.extra_dep('file', 'prospectus_golang') | ||
|
||
item do | ||
noop | ||
|
||
extend ProspectusGems::Gemspec.new | ||
extend ProspectusTravis::Build.new(my_slug) | ||
extend ProspectusGolang::Deps.new | ||
extend ProspectusTravis::Build.new('akerl/prospectus') | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,286 +1,43 @@ | ||
prospectus | ||
========= | ||
|
||
[![Gem Version](https://img.shields.io/gem/v/prospectus.svg)](https://rubygems.org/gems/prospectus) | ||
[![Build Status](https://img.shields.io/travis/com/akerl/prospectus.svg)](https://travis-ci.com/akerl/prospectus) | ||
[![Coverage Status](https://img.shields.io/codecov/c/github/akerl/prospectus.svg)](https://codecov.io/github/akerl/prospectus) | ||
[![Code Quality](https://img.shields.io/codacy/36b84b3bc7b24cd4991c4753f7788850.svg)](https://www.codacy.com/app/akerl/prospectus) | ||
[![GitHub release](https://img.shields.io/github/release/akerl/prospectus.svg)](https://github.com/akerl/prospectus/releases) | ||
[![MIT Licensed](https://img.shields.io/badge/license-MIT-green.svg)](https://tldrlegal.com/license/mit-license) | ||
|
||
Write short scripts in a simple DSL and use the prospectus tool to check for changes in expected vs. actual state. | ||
|
||
I use this for checking my [homebrew tap](https://github.com/halyard/homebrew-formulae) and [ArchLinux packages](https://github.com/amylum) for outdated package versions: it compares the version I'm packaging now against the upstream latest version. | ||
Tool to check for changes in expected vs. actual state | ||
|
||
## Usage | ||
|
||
This gem reads a "./.prospectus" file to determine expected/actual state. A prospectus file can be pretty lightweight: | ||
|
||
``` | ||
item do | ||
name 'zlib' | ||
expected do | ||
github_release | ||
repo 'madler/zlib' | ||
regex /^v(.*)$/ | ||
end | ||
actual do | ||
git_tag | ||
regex /^(.*)-\d+$/ | ||
end | ||
end | ||
``` | ||
|
||
Prospectus works by letting you define "items", each of which have an "expected" and "actual" block. You can specify a "name", as above, otherwise it will infer the name from the directory containing the prospectus file. | ||
|
||
The expected/actual blocks first define the module to be used, and then define any configuration for that module. | ||
|
||
To run the check, just run `prospectus` in the directory with the .prospectus file, or use `prospectus -d /path/to/directory`. | ||
|
||
### Parsing output | ||
|
||
If you're looking to parse the output with something else, consider using -j to get JSON output. | ||
|
||
## Included Modules | ||
|
||
The following modules are included with Prospectus. | ||
|
||
Most of the examples below will use either an expected or actual block, based on the most common use case, but any module can be used for either state. | ||
|
||
### git_tag | ||
|
||
This checks the git tag of the local repo. Supports the Regex helper | ||
|
||
``` | ||
# This would use the current git tag directly | ||
actual do | ||
git_tag | ||
end | ||
``` | ||
|
||
``` | ||
# This would convert v1.0.0 into 1.0.0 | ||
actual do | ||
git_tag | ||
regex /^v([\d.]+)$/ | ||
end | ||
``` | ||
|
||
``` | ||
# And this would convert v1_0_0 into 1.0.0 | ||
actual do | ||
git_tag | ||
regex /^v(\d+)_(\d+)_(\d+)$/, '\1.\2.\3' | ||
end | ||
``` | ||
|
||
### git_hash | ||
|
||
Checks the git hash of a local repository. Supports the chdir helper. | ||
|
||
Will return the short hash unless the `long` argument is provided. | ||
|
||
Primarily used for checking git submodules. | ||
|
||
``` | ||
# Returns the short hash | ||
actual do | ||
git_hash | ||
dir 'submodules/my-important-other-repo' | ||
end | ||
# Returns the full hash | ||
actual do | ||
git_hash | ||
long | ||
dir 'submodules/other-repo' | ||
end | ||
``` | ||
|
||
### github_release | ||
|
||
This checks the latest GitHub release for a repo (must be a real Release, not just a tag. Use github_tag if there isn't a Release). Supports the Regex and Filter helpers and uses the GitHub API helper for API access. To track `prerelease` Releases, use `allow_prerelease` | ||
|
||
``` | ||
expected do | ||
github_release | ||
repo 'amylum/s6' | ||
end | ||
``` | ||
|
||
### github_tag | ||
|
||
This checks the latest GitHub tag for a repo. Supports the Regex and Filter helpers and uses the GitHub API helper for API access. | ||
|
||
``` | ||
expected do | ||
github_tag | ||
repo 'reubenhwk/radvd' | ||
end | ||
``` | ||
|
||
### github_hash | ||
|
||
This checks the latest commit hash on GitHub. Uses the github_api helper, which requires octoauth. Designed to be used alongside the git_hash module for comparing local submodules with upstream commits. | ||
### Check specification | ||
|
||
Will give the 7 character short hash unless "long" is specified. | ||
Checks must implement responses for the following commands: | ||
|
||
``` | ||
expected do | ||
github_hash | ||
repo 'akerl/keys' | ||
end | ||
### load | ||
|
||
expected do | ||
github_hash | ||
repo 'akerl/keys' | ||
long | ||
end | ||
``` | ||
The `load` command accepts a hash with a single key, the directory being checked, and returns an array of checks with optional metadata. | ||
|
||
### homebrew_formula | ||
Input: `{"dir": "/path/to/main/dir"}` | ||
Output: `[{"name": "check_N", "metadata": {"foo": "bar"}}, ...]` | ||
|
||
Checks a Formula file for the current version. This uses the grep module, and expects the formula to be in ./Formula/$NAME.rb. | ||
### execute | ||
|
||
``` | ||
actual do | ||
homebrew_formula | ||
name 'openssh' | ||
end | ||
``` | ||
The `execute` command accepts a hash representing the check object. Metadata provided during the `load` call is included. The return value must be a Result object for the given check. | ||
|
||
### homebrew_cask | ||
Input: `{"dir": "/path/to/main/dir", "file": "/path/to/main/dir/.prospectus.d/checkfile", "name": "check_N", "metadata": {"foo": "bar"}}` | ||
Output: `{"actual": "unhappy", "expected": {"type": "string", "data": {"expected": "happy"}}}` | ||
|
||
Checks a Cask file for the current version. This uses the grep module, and expects the cask to be in ./Casks/$NAME.rb. | ||
### fix | ||
|
||
``` | ||
actual do | ||
homebrew_cask | ||
name 'alfred' | ||
end | ||
``` | ||
The `fix` command can attempt to fix a failed check automatically. It accepts a hash representing the failed result, which includes the originating check. The return value must be a Result object for the given check. | ||
|
||
### gitlab_tag | ||
**Note:** The check must respond to the `fix` command, but if it does not support automatic fixes, it can respond by emiting the same result object it was given. | ||
|
||
Checks a repo on GitLab.com for its latest tag. Supports the regex helper. | ||
|
||
``` | ||
actual do | ||
gitlab_tag | ||
repo 'procps-ng/procps' | ||
end | ||
``` | ||
|
||
### grep | ||
|
||
This checks a local file's contents. Supports the Regex helper, and uses the provided regex pattern to match which line of the file to use. If no regex is specified, it will use the full first line of the file. | ||
|
||
``` | ||
# Searches file for OPENSSL_VERSION = 1.0.1e and returns 1.0.1e | ||
actual do | ||
grep | ||
file 'Makefile' | ||
regex /^OPENSSL_VERSION = ([\w.-]+)$/ | ||
end | ||
``` | ||
|
||
### url_xpath | ||
|
||
Used to parse an xpath inside a web page. Requires the nokogiri gem, and supports the Regex helper. | ||
|
||
The easiest way to get an xpath is usually to use Chrome's Inspector to find the element you want and right click it -> Copy -> As XPath. There are some quirks, notably that nokogiri doesn't parse the tbody tag (just remove it from the xpath that Chrome provides). | ||
|
||
``` | ||
# Parses the latest tag for procps-ng | ||
expected do | ||
url_xpath | ||
url 'https://gitlab.com/procps-ng/procps/tags' | ||
xpath '/html/body/div[1]/div[2]/div[2]/div/div/div[2]/ul/li[1]/div[1]/a/strong/text()' | ||
regex /v([\d.]+)$/ | ||
end | ||
``` | ||
|
||
### static | ||
|
||
Basic module for staticly defining a value. Useful for testing, and also for comparisons against a known state. | ||
|
||
``` | ||
item do | ||
expected do | ||
static_test | ||
set '0.0.3' | ||
end | ||
actual do | ||
static_test | ||
set '0.0.1' | ||
end | ||
end | ||
``` | ||
|
||
## Included Helpers | ||
|
||
### regex | ||
|
||
Allows modification of result using regex. Supported by most modules, per the above modules list. | ||
|
||
The first argument should be a regex pattern to match against the value. Note that an error will be raised if the value does not match the provided regex. An optional second value specifies the replacement string to use; the default is '\1', which will use the first capture group from your regex. | ||
|
||
``` | ||
# This would convert v1.0.0 into 1.0.0 | ||
actual do | ||
git_tag | ||
regex /^v([\d.]+)$/ | ||
end | ||
``` | ||
|
||
``` | ||
# And this would convert v1_0_0 into 1.0.0 | ||
actual do | ||
git_tag | ||
regex /^v(\d+)_(\d+)_(\d+)$/, '\1.\2.\3' | ||
end | ||
``` | ||
|
||
### filter | ||
|
||
Allows filtering of available items. Useful for modules that must parse a list where you only care about some of the entries (like upstream repos that tag multiple packages in the same repo). | ||
|
||
The provided argument is the regex pattern to filter the list with. | ||
|
||
``` | ||
# This filters out github tags that don't match the format 1.2.3 | ||
expected do | ||
github_tag | ||
repo 'foo/bar' | ||
filter /^[\d.]+$/ | ||
end | ||
``` | ||
|
||
### chdir | ||
|
||
Used to chdir to a different directory before loading the state. | ||
|
||
``` | ||
actual do | ||
git_hash | ||
dir 'submodules/important_repo' | ||
end | ||
``` | ||
|
||
### github_api | ||
|
||
Used by modules to provide authenticated access to the GitHub API. Uses the [octoauth gem](https://github.com/akerl/octoauth) | ||
|
||
### gitlab_api | ||
|
||
Used by modules to provide access to GitLab's API, using [the gitlab gem](https://github.com/NARKOZ/gitlab) | ||
Input: `{"actual": "unhappy", "expected": {"type": "string", "data": {"expected": "happy"}}, "check": {"dir": "/path/to/main/dir", "file": "/path/to/main/dir/.prospectus.d/checkfile", "name": "check_N", "metadata": {"foo": "bar"}}}` | ||
Output: `{"actual": "happy", "expected": {"type": "string", "data": {"expected": "happy"}}}` | ||
|
||
## Installation | ||
|
||
gem install prospectus | ||
|
||
## License | ||
|
||
prospectus is released under the MIT License. See the bundled LICENSE file for details. | ||
|
Oops, something went wrong.