• Stars
    star
    155
  • Rank 233,592 (Top 5 %)
  • Language
    PHP
  • Created about 11 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

TryLib is a simple php library that helps you generate a diff of your working copy and send it to Jenkins to run the test suite(s) on the latest code patched with your changes.

TryLib Build Status

"try" your changes on your CI server before committing them to the repository!

TryLib is a simple PHP library that helps you generate a diff of your working copy and send it to Jenkins to run the test suite(s) on the latest code patched with your changes. You can read more about try on Etsy technical blog Code As Craft.

TryLib currently supports Freestyle projects, when your test suite consist of a single Jenkins job and MasterProject projects, when your test suite consist of multiple Jenkins jobs.

Example usage:

try --help output

$ try -h
usage: try [options...] [subjob] [subjob] ...

    -h, --help            Show help
    -n, --diff-only       Create diff, but do not send to Hudson
    -v, --verbose         Verbose (show shell commands as they're run)
    -p, --patch ...       Path to patch file to use instead of generating a diff
    -U, --lines-of-context ...  Generate a diff with n lines of context (like git-diff's -U option)
    -s, --staged          Use staged changes only to generate the diff
    -w, --safelist ...    Generate the patch for only the safelisted files
    -b, --branch ...      Remote branch to diff and try against [main]

    -c, --show-results    Show final try job results
    -P, --show-progress   Print subtasks progressively as they complete
    --extra-param ...     Extra parameters to send to jenkins - format key=value
    -C, --callback ...    Callback string to execute at the end of the try run.

Use ${status} and ${url} as placeholders for the try build status and url
Example: --callback 'echo "**Try status : [${status}](${url})**"'

    --jenkinsjob ...      Master Job Name in Jenkins  [try]
    --jenkinsjobprefix ...  Subjobs prefix              [try]
    --jenkinsserver ...   URL to the jenkins server   [localhost:8080]
    --wcpath ...          Working Copy Path           [.]

Run try on FreeStyle project and show the results in the console.

$ try --show-results
Started try-unit-tests #25
Completed try-unit-tests #25 : SUCCESS

Run the unit-tests and integration-tests only (MasterProject setup) and show the sub-jobs status as they complete

$ try --show-progress
Executing DEFAULT sub-jobs: try-functional-tests try-integration-tests try-unit-tests
......... try ( pending )
......... try ( pending )
......... try ( http://etsyny-l523.local:8080/job/try/13/console )


                  try-unit-tests SUCCESS
            try-functional-tests SUCCESS
           try-integration-tests SUCCESS

Try Status : SUCCESS (http://etsyny-l523.local:8080/job/try/13)

Run try and post the results to a github issue

try --callback "curl -s --user <login>:<password> --request POST --data '{\"body\":\"Try status : [${status}](${url})\"}'" https://github.com/api/v3/repos/etsy/try/issues/1/comments"

Run try with custom parameters defined in your jenkins job

try --extra-param foo=bar --extra-param baz=boo

Try script configuration

Feel free to re-use the boiler plate code in try and update the parameters to fit your environment. Depending on your setup (FreeStyle project or master-project), you may have to comment/uncomment some sections of the code - look for [Jenkins MasterProject only] in the comments.

# URL to your jenkins server (without http)
$jenkins_server = 'localhost:8080';

# Path to the jenkins cli.jar - download it from http://your.jenkins.instance/cli
$jenkins_cli_jar = '/usr/bin/jenkins-cli.jar';

# Jenkins job name
$default_jenkins_job = 'try';

# Working copy path (path to your local git repository)
$repo_path = '.';

Important : the try script generates the patch.diff file at the root of the working copy - add it to your .gitignore to avoid any conflicts in applying the patch.

Jenkins configuration

FreeStyle project

  • Create a new FreeStyle Project

  • Enter the SCM settings

    • make sure to select Clean after checkout in the SCM options
    • If you want support for branches, use ${branch} in the name of branch to checkout
  • Tick the this build is parameterized checkbox and enter the following parameters:

    File Parameter File location : patch.diff

    String Parameter Name : guid This is optional - specifying a guid will help if you have many developers 'trying' concurrently

    String Parameter Name : branch This is optional, if you want to build on branches

  • Enter the following shell command to apply the patch

      echo "Patch..."
      git apply --verbose patch.diff
      git add .
      # your command to launch your unit tests
    

MasterProject

The master-project plugin provides a new project type where you can select a list of sub-projects which should be executed in one logical master project.

In order to run try on a master project, each sub-projects must be pre-fixed by the master project name. An example of setup would be:

try : master-project
    try-unit-tests : sub-project to run the unit tests
    try-integration-tests : sub-project to run the integrations tests
    try-functional-tests : sub-project to run the functional tests

If your subjobs are not prefixed with your master-job name, set the $jenkinsjobprefix accordingly, either in the the try script or via command line

$default_jenkins_job_prefix = 'foo';

./try --jenkinsjobprefix foo

More info can be found in the divide and concur Code As Craft blog entry.

Setting up the master-project in Jenkins

  • Install the master-project plugin if you don't have it already

  • Setup the individual subjobs following the instructions for the FreeStyle project. Each subjobs must be have the same prefix - for example : try-. By default, the prefix used it the master project name, but you can override this behavior by specifying the --jenkinsjobprefix

  • Create a new Master Project and name it try

  • Tick the Allow building and hiding of select sub-jobs checkbox

  • Specify the Default Project names, eg : try-unit-tests try-orm-tests try-integration-tests

  • Tick the this build is parameterized checkbox and enter the following parameters:

    File Parameter File location : patch.diff

    String Parameter Name : guid This is optional - specifying a guid will help if you have many developers 'trying' concurrently

    String Parameter Name : branch This is optional, if you want to build on branches

  • In the Sub-Jobs, tick all the sub-projects that should be enabled with the master project ( at least all the default projects, but you can select more jobs)

Working with branches (Git)

Try will work with your branches! The below scenarios are supported:

  • You are working on main:

    • You want to try against main

        try [options] [subjobs]
      
    • You want to diff and try against a different branch

        try --branch=my_other_branch [options] [subjobs]
      
  • You are working on a branch tracked remotely

    • You want to try against that branch

        try [options] [subjobs]
      
    • You want to diff and try against a different branch (main for example)

        try --branch=main [options] [subjobs]
      
  • You are working on a local branch not tracked

    • If the remote has a branch with the same name, it will be used to generate the diff and try against it

    • If the remote does not have a branch with the same name, it will use the default remote : main

    • You want to diff and try against a specific remote branch

        try --branch=my_branch [options] [subjobs]
      

Working with pre-checks

Prior to generate the diff, you can configure try to run a list of pre-checks.

$pre_checks = array(
    new TryLib\Precheck\ScriptRunner('/path/to/some/script'),
    new TryLib\Precheck\GitCopyBehind(array('main')),
    new TryLib\Precheck\GitCopyAge(48, 96, $remote_branch)
    new TryLib\Precheck\GitReportUntracked(),
);

$repo_manager->runPrechecks($pre_checks);

Some pre-checks will just emit a warning, some can block the try execution.

Running the tests

You can run the unit test suite with:

phpunit

More Repositories

1

AndroidStaggeredGrid

An Android staggered grid view which supports multiple columns with rows of varying sizes.
Java
4,763
star
2

skyline

It'll detect your anomalies! Part of the Kale stack.
Python
2,131
star
3

logster

Parse log files, generate metrics for Graphite and Ganglia
Python
1,965
star
4

deployinator

Deployinate!
Ruby
1,879
star
5

morgue

post mortem tracker
PHP
1,011
star
6

411

An Alert Management Web Application
PHP
968
star
7

feature

Etsy's Feature flagging API used for operational rampups and A/B testing.
PHP
864
star
8

MIDAS

Mac Intrusion Detection Analysis System
831
star
9

opsweekly

On call alert classification and reporting
JavaScript
761
star
10

oculus

The metric correlation component of Etsy's Kale system
Java
706
star
11

mctop

a top like tool for inspecting memcache key values in realtime
Ruby
504
star
12

supergrep

realtime log streamer
JavaScript
410
star
13

Conjecture

Scalable Machine Learning in Scalding
Java
358
star
14

statsd-jvm-profiler

Simple JVM Profiler Using StatsD and Other Metrics Backends
Java
328
star
15

nagios-herald

Add context to Nagios alerts
Ruby
324
star
16

dashboard

JavaScript
308
star
17

Testing101

Etsy's educational materials on testing and design
PHP
262
star
18

boundary-layer

Builds Airflow DAGs from configuration files. Powers all DAGs on the Etsy Data Platform
Python
261
star
19

DebriefingFacilitationGuide

Leading Groups at Etsy to Learn From Accidents
245
star
20

phpunit-extensions

Etsy PHPUnit Extensions
PHP
228
star
21

nagios_tools

Tools for use with Nagios
Python
174
star
22

open-api

We are working on a new version of Etsy’s Open API and want feedback from developers like you.
149
star
23

BugHunt-iOS

Objective-C
145
star
24

ab

Etsy's little framework for A/B testing, feature ramp up, and more.
129
star
25

mod_realdoc

Apache module to support atomic deploys - http://codeascraft.com/2013/07/01/atomic-deploys-at-etsy/
C
126
star
26

wpt-script

Scripts to generate WebPagetest tests and download results
PHP
121
star
27

applepay-php

A PHP extension that verifies and decrypts Apple Pay payment tokens
C
119
star
28

foodcritic-rules

Etsy's foodcritic rules
Ruby
117
star
29

kevin-middleware

This is an Express middleware that makes developing javascript in a monorepo easier.
JavaScript
110
star
30

mixer

a tool to initiate meetings by randomly pairing individuals
Go
100
star
31

cloud-jewels

Estimate energy consumption using GCP Billing Data
TSQL
93
star
32

jenkins-master-project

Jenkins Plugin: Master Project. Jenkins project type that allows for selection of sub-jobs to execute, watch, and report worst status of all sub-projects.
Java
84
star
33

Sahale

A Cascading Workflow Visualizer
JavaScript
83
star
34

cdncontrol

CLI tool for working with multiple CDNs
Ruby
80
star
35

PushBot

An IRC Bot for organizing code pushes
Java
79
star
36

chef-whitelist

Simple library to enable host based rollouts of changes
Ruby
68
star
37

rules_grafana

Bazel rules for building Grafana dashboards
Starlark
66
star
38

rfid-checkout

Low Frequency RFID check out/in client for Raspberry Pi
Python
63
star
39

Etsy-Engineering-Career-Ladder

Etsy's Engineering Career Ladder
HTML
61
star
40

Evokit

Rust
59
star
41

ELK-utils

Utilities for working with the ELK (Elasticsearch, Logstash, Kibana) stack
Ruby
58
star
42

incpath

PHP extension to support atomic deploys
C
52
star
43

arbiter

A utility for generating Oozie workflows from a YAML definition
Java
48
star
44

chef-handlers

Chef handlers we use at Etsy
Ruby
41
star
45

VIPERBuilder

Scaffolding for building apps in a clean way with VIPER architecture
Swift
41
star
46

sbt-checkstyle-plugin

SBT Plugin for Running Checkstyle on Java Sources
Scala
32
star
47

es-restlog

Plugin for logging Elasticsearch REST requests
Java
29
star
48

yubigpgkeyer

Script to make RSA authentication key generation on Yubikeys differently painful
Python
28
star
49

Apotheosis

Python
28
star
50

jenkins-deployinator

Jenkins Plugin: Deployinator. Links key deployinator information to Jenkins builds via the CLI.
Java
25
star
51

sbt-compile-quick-plugin

SBT Plugin for Compiling a Single File
Scala
25
star
52

geonames

Scripts for using Geonames
PHP
24
star
53

jading

cascading.jruby build and execution tool
16
star
54

etsy.github.com

Etsy! on Github!
HTML
16
star
55

divertsy-client

The Android client for running DIVERTsy, a waste stream recording tool to help track diversion rates.
Java
13
star
56

cdncontrol_ui

A web UI for Etsy's cdncontrol tool
CSS
13
star
57

terraform-demux

A user-friendly launcher (Γ  la bazelisk) for Terraform.
Go
12
star
58

logstash-plugins

Ruby
11
star
59

jenkins-triggering-user

Jenkins Plugin: Triggering User. Populates a $TRIGGERING_USER environment variable from the build cause and other sources, a best guess.
10
star
60

EtsyCompositionalLayoutBridge

iOS framework that allows for simultaneously leveraging flow layout and compositional layout in collection views
Swift
3
star
61

soft-circuits-workshop

Etsy Soft Circuits Workshop
Arduino
1
star