GithubHelp home page GithubHelp logo

prepsmith / circleci_webhook_listener Goto Github PK

View Code? Open in Web Editor NEW
0.0 15.0 0.0 74 KB

Node express application that listens to CircleCI webhooks and downloads the generated artifacts

License: MIT License

JavaScript 100.00%

circleci_webhook_listener's Introduction

codeship

CircleCI webhook listener

This webhook listener awaits webhook notifications from CircleCI, when a notification is received it downloads the files from CircleCI's artifacts folder. CircleCIflow

install

  1. clone repository
  2. navigate to root of repository
  3. run "npm install"

start

  1. navigate to root of repository
  2. setup CircleCI
  3. setup settings.json
  4. run "npm start"

test

  1. navigate to root of repository
  2. run "npm test"

setting up circleCI

in your circle.yml file add the following lines

notify:
  webhooks:
    - url: {yourWebHookAddress}:{portWebHookListener}/webhook

in your circle.yml file write a copy command for all the files that need to be downloaded, to the $CIRCLE_ARTIFACTS directory, after the lines that build your project. For example an android project:

test:
  override:
      - ./gradlew build
      - cp -r app/build/outputs/apk $CIRCLE_ARTIFACTS

note: circle.yml only takes 2 spaces, not tabs

settings up settings.json

circle_ci_token:

This is where you place your API token, this can be obtained by going to circleci -> project settings -> API permissions (if needed-> click "Create Token") "circle_ci_token": "ABCDEFGHIJKLMNOPQRTSUVWXY123"

circle_ci_url:

This is the URL of your circleCI project, it should have this format,

	"circle_ci_url": "https://circleci.com/api/v1.1/project/{VCS}/{TEAM_NAME}/{PROJECT_NAME}/.
  • VCS is the Version Control System used for this project, can either be "github" or "bitbucket"
  • TEAM_NAME is the name of the team this project was created under on CircleCI.
  • PROJECT_NAME is the name of the project on CircleCI.

TEAM_NAME and PROJECT_NAME can be found when browsing to your project on CircleCI and looking at the url, it should a format like this: "https://circleci.com/gh/{TEAM_NAME}/{PROJECT_NAME}"

hostName:

This is the hostname the webhook listener will listen to, if null or not present it will listen to all addresses on the given port.

port:

This is the port that the webhook listener will listen to, this is the same port that you have to enter in the circle.yml file in the line {yourWebHookAddress}:{thisPort}/webhook

download_path:

This is the path the webhook listener will download the obtained artifacts to. You can use "{cwd}", this will be replaced with the root directory of the webhook listener project, for example:

"download_path": "{cwd}/downloads/"
"download_path": "C:\\Users\\ThimoVSS\\circleCIArtifacts"

deploying from the ci

example with codeship:

Setup environment to have $BOTNAME and $TARGETHOST in environment variables

npm pack
PACKAGE=`ls circleci_webhook_listener-*.tgz`
REMOTE_EXEC="ssh $BOTNAME@$TARGETHOST -C"
scp $PACKAGE $BOTNAME@$TARGETHOST:apps/circleci_webhook_listener/releases/
$REMOTE_EXEC mkdir -p apps/circleci_webhook_listener/releases/ apps/circleci_webhook_listener/current apps/circleci_webhook_listener/shared
$REMOTE_EXEC "cd apps/circleci_webhook_listener/current; cnpm install --production ../releases/$PACKAGE"
$REMOTE_EXEC "cd apps/circleci_webhook_listener/current; ln -sf ../shared/settings.json"

setup service

use:

https://github.com/nicokaiser/node-monit

circleci_webhook_listener's People

Contributors

thimovss avatar rngadam avatar

Watchers

Dmitry Kazakov avatar Jeewook Moon avatar  avatar Gabriel Paquin avatar James Cloos avatar William Hund avatar Ka Ming L. avatar  avatar aurelien Petit avatar  avatar  avatar  avatar  avatar Emily Lu avatar DorothyWang avatar

circleci_webhook_listener's Issues

add hostname to configuration spec instead of just port

you should change this to not only request for port specification but also the IP to bind to. it's quite common to want to bind specifically to 127.0.0.1:port and then forward traffic to and from using a reverse proxy like nginx.

as it is:

If the hostname is omitted, the server will accept connections on any IPv6 address (::) when IPv6 is available, or any IPv4 address (0.0.0.0) otherwise

https://nodejs.org/api/http.html#http_server_listen_port_hostname_backlog_callback

not good if you care about securing or restricting access.

Says "your settings.json has been created" but it hasn't

> npm install

> [email protected] install /Users/rngadam/EIC/src/circleci_webhook_listener
> node install.js

settings.json doesn't exist yet, creating a new one.
settings.json:
{
	"circle_ci_token": "{TOKEN}",
	"circle_ci_url": "https://circleci.com/api/v1.1/project/{github|bitbucket}/{TEAM_NAME}/{PROJECT_NAME}/",
	"port": {PORT},
	"download_path": "{DOWNLOAD_PATH}" // "{cwd}" will be replaced with the current working directory
}
your settings.json has been created

...but...

find . -name "settings.json"

nothing returned.

package name should map repo name

when I do npm pack, I get:

pad_sales_tool_webhook-0.3.0.tgz

the name of the package.json is pad_sales_tool_webhook. should be the repo name.

Tests failing on clean install

rngadam@rngadam-mac ~/E/s/circleci_webhook_listener> npm run test

> [email protected] test /Users/rngadam/EIC/src/circleci_webhook_listener
> mocha

loading settings from settings.json


{ Error: ENOENT: no such file or directory, open '/Users/rngadam/EIC/src/circleci_webhook_listener/settings.json'
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/Users/rngadam/EIC/src/circleci_webhook_listener/settings.json' }
  WebHook unit tests
    AppendToken
      ✓ works with correct input
      ✓ doesn't work when there is no https
      ✓ doesn't work when there is no url
    obtainArtifactsUrl
      1) works with correct input
      ✓ doesn't work when there is no build number
    obtainAPKpath
      2) works with correct input
      ✓ doesn't work when there is no url
      ✓ doesn't work when there is apk file in the path
    Download
      ✓ downloads bing (793ms)
      ✓ doesn't work when there is no uri
      ✓ doesn't work when there is no file path


  9 passing (812ms)
  2 failing

  1) WebHook unit tests obtainArtifactsUrl works with correct input:
     Error: url 'NaN/artifacts' doesn't start with correct https prefix
      at appendToken (app.js:84:46)
      at Object.obtainArtifactsUrl (app.js:93:5)
      at Context.<anonymous> (test/unit_tests.js:41:17)

  2) WebHook unit tests obtainAPKpath works with correct input:
     TypeError: path must be a string or Buffer
      at Object.fs.mkdir (fs.js:839:11)
      at Object.obtainAPKpath (app.js:109:8)
      at Context.<anonymous> (test/unit_tests.js:57:19)

Implement logger

Currently logs are being logged whilst testing, make it so this doesn't happen anymore.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.