Skip to content

Commit

Permalink
Initial add - now to use it!
Browse files Browse the repository at this point in the history
  • Loading branch information
nicwise committed Sep 21, 2020
0 parents commit 904c073
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
steps:
- label: ":hammer: Test"
plugins:
docker-compose#v1.3.1:
run: tests
- label: ":sparkles: Lint"
plugins:
plugin-linter#v2.0.0:
id: tendnz/git-tag
- label: ":shell: Shellcheck"
plugins:
shellcheck#v1.0.1:
files: hooks/**
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2018 The Dyrt

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
68 changes: 68 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Git Tag Buildkite Plugin

A [Buildkite plugin](https://buildkite.com/docs/agent/v3/plugins) to tag the current head with a version and push it to the repo.

Based heavily on [Git Commit](https://github.com/thedyrt/git-commit-buildkite-plugin).

## Example

With no options, tags the `$BUILDKITE_BRANCH` and pushes the tags, with a commit message like `Build #4`:

```yml
steps:
- command: make
plugins:
- tendnz/git-tag#v1.0.0:
version: "v1.0.0-prod"
```
With all options customized:
```yml
steps:
- command: make
plugins:
- tendnz/git-tag#v1.0.0:
version: "v1.0.0-prod"
message: "Release to $ENV [$BUILDKITE_BUILD_NUMBER]"
user:
name: Bob Monkey
email: [email protected]
```
## Configuration
- **version** (required))
A tag to use in `git tag $VERSION`

- **message** (optional, defaults to `Build #${BUILDKITE_BUILD_NUMBER}`)

The commit message

- **user.email** (optional)

If given, will configure the git user email for the repo.

- **user.name** (optional)

If given, will configure the git user name for the repo.


## Tests / Linting

To run the tests of this plugin, run

```sh
docker-compose run --rm tests
```

To run the [Buildkite Plugin Linter](https://github.com/buildkite-plugins/buildkite-plugin-linter), run

```sh
docker-compose run --rm lint
```

## License

MIT (see [LICENSE](LICENSE))
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '2'
services:
tests:
image: buildkite/plugin-tester
volumes:
- ".:/plugin:ro"
lint:
image: buildkite/plugin-linter
command: ['--id', 'tendnz/git-tag']
volumes:
- ".:/plugin:ro"
27 changes: 27 additions & 0 deletions hooks/post-command
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

set -euo pipefail

if [[ ${BUILDKITE_COMMAND_EXIT_STATUS:-0} != "0" ]]
then
echo "--- Skipping git-tag because the command failed"
exit 0
fi

branch=${BUILDKITE_PLUGIN_GIT_TAG_BRANCH:-${BUILDKITE_BRANCH}}
message=${BUILDKITE_PLUGIN_GIT_TAG_MESSAGE:-"Build #${BUILDKITE_BUILD_NUMBER}"}

if [[ -n ${BUILDKITE_PLUGIN_GIT_TAG_USER_NAME+x} ]]
then
git config user.name "$BUILDKITE_PLUGIN_GIT_TAG_USER_NAME"
fi

if [[ -n ${BUILDKITE_PLUGIN_GIT_TAG_USER_EMAIL+x} ]]
then
git config user.email "$BUILDKITE_PLUGIN_GIT_TAG_USER_EMAIL"
fi

echo "--- Tagging with ${BUILDKITE_PLUGIN_GIT_TAG_VERSION}"
git tag "${BUILDKITE_PLUGIN_GIT_TAG_VERSION}" -m "${BUILDKITE_PLUGIN_GIT_TAG_MESSAGE}"
git push --tags
echo "--- Tags pushed"
17 changes: 17 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Git Tag
description: A Buildkite plugin to tag the current git repository with a specific value
author: https://github.com/nicwise
requirements: []
configuration:
properties:
version:
type: string
message:
type: string
user:
type: object
properties:
email:
type: string
name:
type: string
8 changes: 8 additions & 0 deletions tests/post-command.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bats

load '/usr/local/lib/bats/load.bash'

post_command_hook="$PWD/hooks/post-command"


echo "needs ot have some tests"

0 comments on commit 904c073

Please sign in to comment.