├── package.json ├── action.yml ├── README.md └── index.js /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nomad-deploy-result-action", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/let-sh/nomad-deploy-result-action.git" 12 | }, 13 | "keywords": [], 14 | "author": "", 15 | "license": "ISC", 16 | "bugs": { 17 | "url": "https://github.com/let-sh/nomad-deploy-result-action/issues" 18 | }, 19 | "homepage": "https://github.com/let-sh/nomad-deploy-result-action#readme", 20 | "dependencies": { 21 | "@actions/core": "^1.9.1", 22 | "@actions/github": "^5.0.0", 23 | "node-fetch": "^3.1.1" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: "Nomad Deploy Result" 2 | description: "Handle with nomad deployment result" 3 | branding: 4 | icon: "check" 5 | color: "blue" 6 | inputs: 7 | nomad-addr: # id of input 8 | description: "Nomad endpoint address" 9 | required: true 10 | default: "http://localhost:4646" 11 | nomad-token: # id of input 12 | description: "Nomad token to access endpoint" 13 | required: true 14 | nomad-job-name: # id of input 15 | description: "Nomad job to inspect" 16 | required: true 17 | nomad-namespace: # id of input 18 | description: "Nomad namespace" 19 | default: "default" 20 | outputs: 21 | result: # id of output 22 | description: "nomad job result, e.g. successful, failed" 23 | runs: 24 | using: "node12" 25 | main: "index.js" 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Nomad deploy result action 2 | 3 | This action waiting for nomad deployment result. Sucess to continue, Failed to stop. 4 | 5 | ## Inputs 6 | 7 | | input | required | default | sample | description | 8 | | --------------- | -------- | ----------------------- | -------------------------------------- | ------------------------------ | 9 | | nomad-addr | ✅ | "http://localhost:4646" | "http://localhost:4646" | Nomad endpoint address | 10 | | nomad-token | ✅ | "" | "F5476034-7A75-4A27-BA45-65B0F7B291B9" | Nomad token to access endpoint | 11 | | nomad-job-name | ✅ | "" | "nginx" | Nomad job to inspect | 12 | | nomad-namespace | | "default" | "default" | Nomad namespace | 13 | 14 | ## Outputs 15 | 16 | | output | sample | description | 17 | | ------ | ----------- | ---------------------------- | 18 | | result | "succesful" | job deployment status result | 19 | 20 | ## Example usage 21 | 22 | ```yml 23 | - name: Check deployment result 24 | uses: let-sh/nomad-deploy-result-action@v1 25 | with: 26 | nomad-addr: ${{ secrets.NOMAD_ADDR }} 27 | nomad-token: ${{ secrets.NOMAD_TOKEN }} 28 | nomad-job-name: ${{ secrets.NOMAD_JOB }} 29 | nomad-namespace: ${{ secrets.NOMAD_NAMESPACE }} 30 | ``` 31 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const core = require('@actions/core'); 2 | const github = require('@actions/github'); 3 | const fetch = require('node-fetch'); 4 | let round = 1; 5 | 6 | try { 7 | fetchDeploymentResult(); 8 | } catch (error) { 9 | core.setFailed(error.message); 10 | } 11 | 12 | function fetchDeploymentResult() { 13 | const nomadEndpoint = core.getInput('nomad-addr'); 14 | const nomadToken = core.getInput('nomad-token'); 15 | const nomadJobName = core.getInput('nomad-job-name'); 16 | const nomadNamespace = core.getInput('nomad-namespace'); 17 | 18 | fetch(`${nomadEndpoint}/v1/job/${nomadJobName}/deployment?namespace=${nomadNamespace}&index=1`, { 19 | "headers": { 20 | "accept": "*/*", 21 | "accept-language": "en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7", 22 | "sec-ch-ua": "\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"91\", \"Chromium\";v=\"91\"", 23 | "sec-ch-ua-mobile": "?0", 24 | "sec-fetch-dest": "empty", 25 | "sec-fetch-mode": "cors", 26 | "sec-fetch-site": "same-origin", 27 | "x-nomad-token": nomadToken 28 | }, 29 | "body": null, 30 | "method": "GET", 31 | "mode": "cors" 32 | }) 33 | .then(res => res.json()) 34 | .then((jsonData) => { 35 | result = jsonData.Status 36 | 37 | if (result === "failed") { 38 | console.log("deployment description:", jsonData.StatusDescription); 39 | core.setFailed(jsonData.StatusDescription); 40 | return result 41 | } 42 | else if (result === "successful") { 43 | core.setOutput("result", result); 44 | console.log("deployment description:", jsonData.StatusDescription); 45 | console.log(`finshed check up deploy result: ${result}.`); 46 | 47 | return result 48 | } else { 49 | var waitTill = new Date(new Date().getTime() + 4 * 1000); 50 | while (waitTill > new Date()) { } 51 | 52 | console.log(jsonData.Status, ", round:", round) 53 | // add round counter 54 | round += 1 55 | 56 | fetchDeploymentResult() 57 | } 58 | }) 59 | .catch((err) => { 60 | // handle error 61 | console.log(err); 62 | core.setFailed(err); 63 | throw err; 64 | }); 65 | } --------------------------------------------------------------------------------