Skip to content

Commit 98f4e18

Browse files
committed
Merge branch 'master' of github.com:tideflow-io/tideflow-agent
2 parents f83a914 + 1302d79 commit 98f4e18

File tree

20 files changed

+2141
-567
lines changed

20 files changed

+2141
-567
lines changed

.circleci/config.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.

.github/workflows/nodejs.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Node CI
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
10+
strategy:
11+
matrix:
12+
node-version: [8.x, 10.x, 11.x, 12.x, 13.x]
13+
14+
steps:
15+
- uses: actions/checkout@v1
16+
- name: Use Node.js ${{ matrix.node-version }}
17+
uses: actions/setup-node@v1
18+
with:
19+
node-version: ${{ matrix.node-version }}
20+
- name: npm install, build, and test
21+
run: |
22+
npm ci
23+
npm run build --if-present
24+
npm test
25+
env:
26+
CI: true

.github/workflows/npmpublish.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Node.js Package
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v1
12+
- uses: actions/setup-node@v1
13+
with:
14+
node-version: 12
15+
- run: npm ci
16+
- run: npm test
17+
18+
publish-npm:
19+
needs: build
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v1
23+
- uses: actions/setup-node@v1
24+
with:
25+
node-version: 12
26+
registry-url: https://registry.npmjs.org/
27+
- run: npm ci
28+
- run: npm publish
29+
env:
30+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
a.js

.vscode/settings.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

LICENSE.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

README.md

Lines changed: 84 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
# Tideflow's agent [![CircleCI](https://circleci.com/gh/tideflow-io/tideflow-agent.svg?style=svg)](https://circleci.com/gh/tideflow-io/tideflow-agent) [![Greenkeeper badge](https://badges.greenkeeper.io/tideflow-io/tideflow-agent.svg)](https://greenkeeper.io/)
1+
# Tideflow's Self-hosted Runner
22

3-
> Run commands as workflow steps via [Tideflow](https://tideflow.io)
3+
> With Tideflow's Self-hosted Runner, you can run workflow's task in your own server via [TideFlow](https://www.tideflow.io)
44
5-
## Install
5+
For more information, visit [TideFlow.io](https://www.tideflow.io)
66

7-
Ensure you have [Node.js](https://nodejs.org) version 8+ installed. Then run the following:
7+
## Usage
88

99
```bash
10-
npm i -g @tideflowio/tideflow-agent
10+
npx @tideflowio/tideflow-agent -t [token] -u tideflow.example.com
1111
```
1212

13-
## Usage
14-
1513
$ tideflow-agent --help
1614
Usage: index [options]
1715

@@ -27,21 +25,93 @@ npm i -g @tideflowio/tideflow-agent
2725
$ tideflow-agent --help
2826
$ tideflow-agent -h
2927

30-
You can also run the agent without installing it, via npx.
31-
32-
```bash
33-
npx @tideflowio/tideflow-agent -t [token] -u tideflow.example.com
34-
```
35-
3628
## Environment variables
3729

3830
```bash
3931
# Specify the URL to connect to the Tideflow's platform.
4032
# Optional. Defaults to localhost:1337 if no -u parameter set
4133
# Example: http://subdomain.example.com:1337
4234
TF_AGENT_URL
35+
36+
# Specify authentication token.
37+
# Optional. Having the authentication token stored as an environment
38+
# variable allows users to run the agent without passing the -t parameter.
39+
# Example: d2a04f78-ff8a-4eb4-a12c-57fb7abf03a7
40+
TIDEFLOWIO_AGENT_TOKEN
4341
```
4442

45-
## Resources
43+
## How to process data from previous tasks
44+
45+
Each of the predecesor tasks results is represented as an array element with
46+
two root properties:
47+
48+
- **type**: an string that defines the kind of data retuned by the previous
49+
step (object, array, file, etc)
50+
- **data**: an object containing the task's result.
51+
52+
### Command actions
53+
54+
The result from previous tasks are sent to the agent commands via the parameter
55+
`--tf_previous`.
56+
57+
For example, if the command to run is `meow`, the agent will execute it as
58+
`meow --tf_previous <previous-tasks-output>`
59+
60+
The previous task's output is an stringified representation of the following
61+
JSON array format:
62+
63+
```json
64+
[
65+
{
66+
"data": {
67+
"firstName": "Jose",
68+
"lastName": "Samantino",
69+
},
70+
"files": [
71+
{
72+
"fieldname": "file",
73+
"url": "https://...?token=....",
74+
"filename": "CV.pdf",
75+
"mimetype": "application/pdf"
76+
}
77+
],
78+
"links": []
79+
}
80+
]
81+
```
82+
83+
### NodeJS SFC actions
84+
85+
The result from previous tasks are stored in a file. You can get the absolute
86+
path to this file in a environment variable called `TF_PREVIOUS_FILE`. This is
87+
an example on how you can retrieve the previous actions results:
88+
89+
```javascript
90+
// Include the FileSystem package to access file system files.
91+
const fs = require('fs')
92+
93+
// Grab the full path of the file that contents previous actions results
94+
const filePath = process.env.TF_PREVIOUS_FILE
95+
96+
// Read the file contents
97+
const fileContents = fs.readFileSync(filePath, 'utf8')
98+
99+
// Conver the previous actions results to Javascript object
100+
const previousResults = JSON.parse(fileContents)
101+
```
102+
103+
---
104+
105+
## Contributing
106+
107+
If you would like to contribute to Tideflow, check out the
108+
[Contributing Guide](https://docs.tideflow.io/docs/contribute).
109+
110+
## License
111+
112+
GNU AFFERO GENERAL PUBLIC LICENSE
113+
114+
## Developer Resources
46115

47116
- Documentation: https://docs.tideflow.io/docs/services-agent
117+
- Contribute: https://docs.tideflow.io/docs/contribute

agent.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const os = require('os')
1010
* @param {Object} cli's parameters parsed via commander's npm package
1111
*/
1212
module.exports.exec = (program) => {
13-
13+
1414
const cpusCounts = os.cpus().length
1515
const programConcurrency = program.concurrency || cpusCounts
1616
let concurrency = programConcurrency >= cpusCounts ? cpusCounts : programConcurrency
@@ -28,9 +28,9 @@ module.exports.exec = (program) => {
2828

2929
// Shows welcome messages
3030
console.log(pretty.logo(pjson))
31-
console.log(` || Tideflow.io - agent ${pjson.version}`.blue)
32-
console.log(` || Using ${concurrency} as concurrency`.yellow)
33-
console.log(` || Target URL ${URL}`.yellow)
31+
console.log(` || ${new Date()} Tideflow.io - agent ${pjson.version}`.blue)
32+
console.log(` || ${new Date()} Using ${concurrency} as concurrency`.yellow)
33+
console.log(` || ${new Date()} Target URL ${URL}`.yellow)
3434

3535
const socket = io(`${URL}?token=${program.token}`)
3636

@@ -54,6 +54,16 @@ module.exports.exec = (program) => {
5454
q.push(services.githubCi.executionFinished(socket, 'tf.githubCi.push.execution.finished', req))
5555
})
5656

57+
socket.on('tf.githubCi.checksuite', (req) => {
58+
if (!agent.authenticated) return
59+
q.push(services.githubCi.checksuite(socket, 'tf.githubCi.checksuite', req))
60+
})
61+
62+
socket.on('tf.githubCi.checksuite.execution.finished', (req) => {
63+
if (!agent.authenticated) return
64+
q.push(services.githubCi.executionFinished(socket, 'tf.githubCi.checksuite.execution.finished', req))
65+
})
66+
5767
socket.on('tf.githubCi.test_cmd', (req) => {
5868
if (!agent.authenticated) return
5969
q.push(services.githubCi.test_cmd(socket, 'tf.githubCi.test_cmd', req))
@@ -67,28 +77,30 @@ module.exports.exec = (program) => {
6777
// Execute command
6878
socket.on('tf.agent.execute', function (req) {
6979
if (!agent.authenticated) return
80+
console.log(` => ${new Date()} ${req.execution} Execute`.blue)
7081
q.push(services.agent.execute(socket, 'tf.agent.execute', req))
7182
})
7283

7384
socket.on('tf.agent.code_nodesfc', function(req) {
7485
if (!agent.authenticated) return
86+
console.log(` => ${new Date()} ${req.execution} Node SFC`.blue)
7587
q.push(services.agent.codeNodeSfc(socket, 'tf.agent.code_nodesfc', req))
7688
})
7789

7890
// Authorize agent
7991
socket.on('tf.authz', function (auth) {
8092
agent = Object.assign({authenticated: true}, agent, auth)
81-
console.log(` || Agent ${auth.title} authorized`.green)
93+
console.log(` || ${new Date()} Agent ${auth.title} authorized`.green)
8294
})
8395

8496
// Show a connection lost message
8597
socket.on('reconnecting', function () {
86-
console.error(` || Connection lost, reconnecting...`.red)
98+
console.error(` || ${new Date()} Connection lost, reconnecting...`.red)
8799
})
88100

89101
// Warm the user in case of error
90102
socket.on('error', function (e) {
91-
console.error(` || Error`.red)
92-
console.error(` || ${e}`.red)
103+
console.error(` || ${new Date()} Error`.red)
104+
console.error(` || ${new Date()} ${e}`.red)
93105
})
94-
}
106+
}

helpers/pretty.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Returns a pretty logo for terminal
33
*/
4-
module.exports.logo = (pjson) => {
4+
module.exports.logo = pjson => {
55
return `
66
_ _ _ ___ _ _
77
| |_|_|_| |___| _| |___ _ _ _ |_|___

0 commit comments

Comments
 (0)