Skip to content

Commit

Permalink
feat(#minor); CI/CD; Add capability to deploy only and add action to …
Browse files Browse the repository at this point in the history
…test builds on pushing to the remote branched in this repo. (#879)
  • Loading branch information
steegecs authored Aug 30, 2022
1 parent 6968fd8 commit 5c0f556
Show file tree
Hide file tree
Showing 44 changed files with 205 additions and 163 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/build-checker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
on:
push:
branches-ignore:
- master

jobs:
Deployment:
runs-on: ubuntu-latest
steps:
- id: files
uses: Ana06/get-changed-files@v1.2
continue-on-error: true

- uses: actions/checkout@v2
- uses: steegecs/Subgraph-Build-Checker@main
with:
HOSTED_SERVICE_ACCESS_TOKEN: ${{ secrets.HOSTED_SERVICE_ACCESS_TOKEN }}
CHANGED_FILES: "${{ steps.files.outputs.all }}"
ABSOLUTE_PATH: ${{ github.workspace }}
GRAPH_DEPLOYMENT_LOCATION: messari

2 changes: 1 addition & 1 deletion .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- id: files
uses: jitterbit/get-changed-files@v1
uses: Ana06/get-changed-files@v1.2
continue-on-error: true

- uses: actions/checkout@v2
Expand Down
39 changes: 33 additions & 6 deletions deployment/deployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ if (
args.network === undefined ||
args.location === undefined ||
args.printlogs === undefined ||
args.merge === undefined
args.merge === undefined ||
args.type === undefined
) {
console.log(
"Usage: node deployment.js --subgraph=" +
Expand All @@ -33,13 +34,17 @@ if (
" --printlogs=" +
args.printlogs +
" --merge=" +
args.merge
args.merge +
" --type=" +
args.type
);
console.log(
"Please check subgraph:deploy script in package.json. Make sure it matches example script in the deployments folder. "
);
} else if (!args.subgraph || !args.location) {
console.log("Please provide at least --SUBGRAPH and --LOCATION");
} else if (!["build", "deploy", ""].includes(args.type.toLowerCase())) {
console.log("Please provide --TYPE=build or --TYPE=deploy");
} else if (args.subgraph && args.protocol && args.network && args.location) {
if (args.subgraph in protocolNetworkMap == false) {
console.log(
Expand Down Expand Up @@ -92,7 +97,14 @@ if (
} else {
allScripts.set(
location,
scripts(protocol, network, template, location, prepareConstants)
scripts(
protocol,
network,
template,
location,
prepareConstants,
args.type
)
);
}
runCommands(allScripts, results, args, function (results) {});
Expand Down Expand Up @@ -140,13 +152,21 @@ if (
"deploy-on-merge"
]
) &&
["true", "t"].includes(args.merge.toLowerCase())
["true", "t"].includes(args.merge.toLowerCase()) &&
args.deploy != "build"
) {
results += "Ignored in Deployment Configurations: " + location + "\n";
} else {
allScripts.set(
location,
scripts(protocol, network, template, location, prepareConstants)
scripts(
protocol,
network,
template,
location,
prepareConstants,
args.type
)
);
}
}
Expand Down Expand Up @@ -198,7 +218,14 @@ if (
} else {
allScripts.set(
location,
scripts(protocol, network, template, location, prepareConstants)
scripts(
protocol,
network,
template,
location,
prepareConstants,
args.type
)
);
}
}
Expand Down
48 changes: 24 additions & 24 deletions deployment/deployment.json
Original file line number Diff line number Diff line change
Expand Up @@ -778,21 +778,21 @@
"template": "apeswap.bsc.template.yaml",
"steegecs": "steegecs/apeswap-bsc",
"deploy-on-merge": false,
"prepare:constants": false
"prepare:constants": true
},
"polygon": {
"template": "apeswap.matic.template.yaml",
"steegecs": "steegecs/apeswap-matic",
"deploy-on-merge": false,
"prepare:constants": false
"prepare:constants": true
}
},
"mm-finance": {
"polygon": {
"template": "mm.finance.template.yaml",
"messari": "messari/mm-finance-polygon",
"deploy-on-merge": false,
"prepare:constants": false
"prepare:constants": true
}
},
"quickswap": {
Expand All @@ -801,7 +801,7 @@
"steegecs": "steegecs/quickswap-matic",
"messari": "messari/quickswap-polygon",
"deploy-on-merge": false,
"prepare:constants": false
"prepare:constants": true
}
},
"solarbeam": {
Expand All @@ -810,7 +810,7 @@
"steegecs": "steegecs/solarbeam-moonriver",
"messari": "messari/solarbeam-moonriver",
"deploy-on-merge": false,
"prepare:constants": false
"prepare:constants": true
}
},
"spiritswap": {
Expand All @@ -819,7 +819,7 @@
"steegecs": "steegecs/spiritswap-fantom",
"messari": "messari/spiritswap-fantom",
"deploy-on-merge": false,
"prepare:constants": false
"prepare:constants": true
}
},
"spookyswap": {
Expand All @@ -828,24 +828,24 @@
"steegecs": "steegecs/spookyswap-fantom",
"messari": "messari/spookyswap-fantom",
"deploy-on-merge": false,
"prepare:constants": false
"prepare:constants": true
}
},
"sushiswap": {
"arbitrum": {
"template": "sushiswap.alt.template.yaml",
"deploy-on-merge": false,
"prepare:constants": false
"prepare:constants": true
},
"avalanche": {
"template": "uniswap.v2.template.yaml",
"deploy-on-merge": false,
"prepare:constants": false
"prepare:constants": true
},
"bsc": {
"template": "uniswap.v2.template.yaml",
"deploy-on-merge": false,
"prepare:constants": false
"prepare:constants": true
},
"celo": {
"template": "sushiswap.alt.template.yaml",
Expand All @@ -855,44 +855,44 @@
"fantom": {
"template": "sushiswap.alt.template.yaml",
"deploy-on-merge": false,
"prepare:constants": false
"prepare:constants": true
},
"fuse": {
"template": "sushiswap.alt.template.yaml",
"deploy-on-merge": false,
"prepare:constants": false
"prepare:constants": true
},
"ethereum": {
"template": "sushiswap.mainnet.template.yaml",
"steegecs": "steegecs/sushiswap-mainnet",
"messari": "messari/sushiswap-ethereum",
"deploy-on-merge": false,
"prepare:constants": false
"prepare:constants": true
},
"polygon": {
"template": "sushiswap.alt.template.yaml",
"steegecs": "steegecs/sushiswap-matic",
"deploy-on-merge": false,
"prepare:constants": false
"prepare:constants": true
},
"moonbeam": {
"template": "sushiswap.alt.template.yaml",
"deploy-on-merge": false,
"prepare:constants": false
"prepare:constants": true
},
"moonriver": {
"template": "sushiswap.alt.template.yaml",
"steegecs": "steegecs/sushiswap-moonriver",
"messari": "messari/sushiswap-moonriver",
"deploy-on-merge": false,
"prepare:constants": false
"prepare:constants": true
},
"gnosis": {
"template": "sushiswap.alt.template.yaml",
"steegecs": "steegecs/sushiswap-xdai",
"messari": "messari/sushiswap-gnosis",
"deploy-on-merge": false,
"prepare:constants": false
"prepare:constants": true
}
},
"trader-joe": {
Expand All @@ -901,7 +901,7 @@
"steegecs": "steegecs/trader-joe-avalanche",
"messari": "messari/trader-joe-avalanche",
"deploy-on-merge": false,
"prepare:constants": false
"prepare:constants": true
}
},
"trisolaris": {
Expand All @@ -910,7 +910,7 @@
"steegecs": "steegecs/trisolaris-aurora",
"messari": "messari/trisolaris-aurora",
"deploy-on-merge": false,
"prepare:constants": false
"prepare:constants": true
}
},
"ubeswap": {
Expand All @@ -920,15 +920,15 @@
"messari": "messari/ubeswap-celo",
"sevenshi": "sevenshi/ubeswap_celo",
"deploy-on-merge": false,
"prepare:constants": false
"prepare:constants": true
}
},
"uniswap-v2": {
"ethereum": {
"template": "uniswap.v2.template.yaml",
"steegecs": "steegecs/uniswap-v2",
"deploy-on-merge": false,
"prepare:constants": false
"prepare:constants": true
}
},
"vvs-finance": {
Expand All @@ -937,7 +937,7 @@
"steegecs": "steegecs/trisolaris-aurora",
"messari": "messari/trisolaris-aurora",
"deploy-on-merge": false,
"prepare:constants": false
"prepare:constants": true
}
},
"honeyswap": {
Expand All @@ -946,13 +946,13 @@
"mrbrianhobo": "mrbrianhobo/honeyswap-xdai",
"messari": "messari/honeyswap-gnosis",
"deploy-on-merge": false,
"prepare:constants": false
"prepare:constants": true
},
"polygon": {
"template": "honeyswap.matic.template.yaml",
"mrbrianhobo": "mrbrianhobo/honeyswap-polygon",
"deploy-on-merge": false,
"prepare:constants": false
"prepare:constants": true
}
}
},
Expand Down
41 changes: 35 additions & 6 deletions deployment/execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ const fs = require("fs");
* @param {string} template - Template location that will be used to create subgraph.yaml
* @param {string} location - Location in the subgraph will be deployed to {e.g. messari/uniswap-v2-ethereum}
*/
function scripts(protocol, network, template, location, constants) {
function scripts(protocol, network, template, location, constants, type) {
let scripts = [];
let removeGenerated = "rm -rf generated";
let removeBuild = "rm -rf build";
let removeResults = "rm -rf results.txt";
let removeConfig = "rm -rf configurations/configure.ts";
let removeSubgraphYaml = "rm -rf subgraph.yaml";
Expand All @@ -25,8 +27,11 @@ function scripts(protocol, network, template, location, constants) {
" --NETWORK=" +
network;
let codegen = "graph codegen";
let build = "graph build";
let deployment = "npm run deploy:subgraph --LOCATION=" + location;

scripts.push(removeGenerated);
scripts.push(removeBuild);
scripts.push(removeResults);
scripts.push(removeConfig);
scripts.push(removeSubgraphYaml);
Expand All @@ -35,7 +40,15 @@ function scripts(protocol, network, template, location, constants) {
scripts.push(prepareConstants);
}
scripts.push(codegen);
scripts.push(deployment);

// Null value for type assumes you want to deploy
if (["deploy", ""].includes(type.toLowerCase())) {
scripts.push(deployment);
} else if (type.toLowerCase() == "build") {
scripts.push(build);
} else {
console.log("Error: invalid type - Neither build nor deploy");
}

return scripts;
}
Expand Down Expand Up @@ -98,8 +111,17 @@ async function runCommands(allScripts, results, args, callback) {
);
} else {
logs = logs + "Exec error: " + error;
results +=
"Deployment Failed: " + allDeployments[deploymentIndex] + "\n";

if (args.type == "build") {
results +=
"Build Failed: " + allDeployments[deploymentIndex] + "\n";
} else {
results +=
"Deployment Failed: " +
allDeployments[deploymentIndex] +
"\n";
}

console.log(error);
deploymentIndex++;
scriptIndex = 0;
Expand All @@ -109,8 +131,15 @@ async function runCommands(allScripts, results, args, callback) {
scriptIndex ==
allScripts.get(allDeployments[deploymentIndex]).length
) {
results +=
"Deployment Successful: " + allDeployments[deploymentIndex] + "\n";
if (args.type == "build") {
results +=
"Build Successful: " + allDeployments[deploymentIndex] + "\n";
} else {
results +=
"Deployment Successful: " +
allDeployments[deploymentIndex] +
"\n";
}
deploymentIndex++;
scriptIndex = 0;
httpCounter = 1;
Expand Down
2 changes: 1 addition & 1 deletion deployment/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"prepare:yaml": "mustache protocols/${npm_config_protocol}/config/networks/${npm_config_network}/${npm_config_network}.json protocols/${npm_config_protocol}/config/templates/${npm_config_template} > subgraph.yaml",
"prepare:constants": "mustache protocols/${npm_config_protocol}/config/networks/${npm_config_network}/${npm_config_network}.json configurations/configure.template.ts > configurations/configure.ts",
"deploy:subgraph": "graph deploy --product hosted-service ${npm_config_location}",
"deploy": "node ../../deployment/deployment.js --subgraph=${npm_config_subgraph} --protocol=${npm_config_protocol} --network=${npm_config_network} --location=${npm_config_location} --printlogs=${npm_config_printlogs} --merge=${npm_config_merge}"
"deploy": "node ../../deployment/deployment.js --subgraph=${npm_config_subgraph} --protocol=${npm_config_protocol} --network=${npm_config_network} --location=${npm_config_location} --printlogs=${npm_config_printlogs} --merge=${npm_config_merge} --deploy=$(npm_config_deploy)"
},
"dependencies": {
"@graphprotocol/graph-cli": "0.28.0",
Expand Down
Loading

0 comments on commit 5c0f556

Please sign in to comment.