Skip to content

Commit

Permalink
init plugin (#2)
Browse files Browse the repository at this point in the history
* init plugin

* pipeline
  • Loading branch information
matoszz committed Mar 23, 2024
1 parent fcb78ff commit 6ef7493
Show file tree
Hide file tree
Showing 8 changed files with 324 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ steps:
- label: ":sparkles: Lint"
plugins:
plugin-linter#v3.3.0:
id: a-github-user/template
id: datumforge/git-commit
71 changes: 52 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,69 @@
[![Build status](https://badge.buildkite.com/df549c652f77fa3660f4d7f975fd3bb5744e12fb4066719553.svg?branch=main)](https://buildkite.com/datum/template-buildkite-plugin)
[![Build status](https://badge.buildkite.com/7eca2ecc8cd4f571e1c2e26000c51030c808e7bca6b9b25e42.svg)](https://buildkite.com/datum/git-commit-buildkite-plugin)

# Template Buildkite Plugin
# git-commit

Check the [buildkite organization](https://github.com/buildkite-plugins) or [website](https://buildkite.com/plugins) to see if your plugin already exists or we can contribute to it !

Be sure to update this readme with your plugin information after using the template repository - for more info checkout Buildkite's documentation [here](https://buildkite.com/docs/plugins)
A buildkite plugin to commit and push results of command(s) to a remote git repository

## Example

Provide an example of using this plugin, like so:

Add the following to your `pipeline.yml`:

```yml
steps:
- command: ls
- command: task generate
plugins:
- a-github-user/template#v1.0.0:
pattern: '*.md'
- datumforge/git-commit#v1.0.0: ~
```

## Developing
The default options commit all changed/added files to `$BUILDKITE_BRANCH` and pushes to `origin`.

Provide examples on how to modify and test, e.g.:
An example with fully customized options:

To run the linter:
```shell
task lint
```yml
steps:
- command: task generate
plugins:
- datumforge/git-commit#v1.0.0:
add: app/
branch: mitb
create-branch: true
message: "Task generate output"
remote: upstream
user:
name: bender-rodriguez
email: brodriguez@datum.net
```

To run the tests:
## Configuration

### add (optional, defaults to `.`)

A pathspec that will be passed to `git add -A` to add changed files.

### branch (optional, defaults to `$BUILDKITE_BRANCH`)

The branch where changes will be committed. Since Buildkite runs builds in a detached HEAD state, this plugin will fetch and checkout the given branch prior to committing. Unless we're creating a new branch. See `create-branch`

### create-branch (optional, defaults to `false`)

When set to true the branch will be created, rather than fetched from the remote

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

The commit message

### remote (optional, defaults to `origin`)

The git remote where changes will be pushed

### 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

## Developing

```shell
task test
```
Requires [taskfile](https://taskfile.dev/installation/) - `task lint` and `task test` to validate updates to the plugin
3 changes: 1 addition & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
services:
# You need to update this for your plugin name / location
lint:
image: buildkite/plugin-linter
command: [ '--id', 'a-github-user/template' ]
command: [ '--id', 'datumforge/git-commit' ]
volumes:
- ".:/plugin:ro"
tests:
Expand Down
6 changes: 0 additions & 6 deletions hooks/post-checkout

This file was deleted.

41 changes: 40 additions & 1 deletion hooks/post-command
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
#!/bin/bash
#!/usr/bin/env bash

set -euo pipefail

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

remote=${BUILDKITE_PLUGIN_GIT_COMMIT_REMOTE:-origin}
branch=${BUILDKITE_PLUGIN_GIT_COMMIT_BRANCH:-${BUILDKITE_BRANCH}}
message=${BUILDKITE_PLUGIN_GIT_COMMIT_MESSAGE:-"Build #${BUILDKITE_BUILD_NUMBER}"}

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

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

if [[ ${BUILDKITE_PLUGIN_GIT_COMMIT_CREATE_BRANCH:-false} = "true" ]]
then
git checkout -b "$branch"
else
git fetch "$remote" "$branch:$branch"
git checkout "$branch"
fi
git add -A "${BUILDKITE_PLUGIN_GIT_COMMIT_ADD:-.}"

if ! git diff-index --quiet HEAD
then
echo "--- Committing changes"
git commit -m "${message}"
echo "--- Pushing to origin"
git push "$remote" "$branch"
else
echo "--- No changes to commit"
fi
30 changes: 20 additions & 10 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
---
name: template-buildkite-plugin
description: what your plugin does
author: Datum
requirements:
- if you have requirements
name: Git Commit
description: A buildkite plugin to commit and push changes to a git repository
author: https://github.com/datumforge
requirements: []
configuration:
properties:
propertyname:
add:
type: string
required: []
# - if any properties are required
dependencies:
dependencyname: [dep]
branch:
type: string
create-branch:
type: boolean
message:
type: string
remote:
type: string
user:
type: object
properties:
email:
type: string
name:
type: string
3 changes: 0 additions & 3 deletions tests/post-checkout.bats

This file was deleted.

0 comments on commit 6ef7493

Please sign in to comment.