Created
September 2, 2022 21:48
-
-
Save ed-parsadanyan/d9215c7b271117357adb7a0b4e697105 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"meta": { | |
"instanceId": "dfdeafd1c3ed2ee08eeab8c2fa0c3f522066931ed8138ccd35dc20a1e69decd3" | |
}, | |
"nodes": [ | |
{ | |
"parameters": {}, | |
"id": "7dbe7f1e-3400-447d-b33b-1401af681fd2", | |
"name": "Start", | |
"type": "n8n-nodes-base.start", | |
"typeVersion": 1, | |
"position": [ | |
-1540, | |
360 | |
] | |
}, | |
{ | |
"parameters": {}, | |
"name": "Merge", | |
"type": "n8n-nodes-base.merge", | |
"position": [ | |
200, | |
560 | |
], | |
"typeVersion": 1, | |
"id": "8b4bc1d6-8568-4de5-9107-329c8f6712a2" | |
}, | |
{ | |
"parameters": { | |
"dataType": "string", | |
"value1": "={{$json[\"github_status\"]}}", | |
"rules": { | |
"rules": [ | |
{ | |
"value2": "same" | |
}, | |
{ | |
"value2": "different", | |
"output": 1 | |
}, | |
{ | |
"value2": "new", | |
"output": 2 | |
} | |
] | |
} | |
}, | |
"name": "github_status", | |
"type": "n8n-nodes-base.switch", | |
"position": [ | |
500, | |
560 | |
], | |
"typeVersion": 1, | |
"id": "33ec6c61-6660-45b1-913d-5752f949b53f" | |
}, | |
{ | |
"parameters": {}, | |
"name": "same", | |
"type": "n8n-nodes-base.noOp", | |
"position": [ | |
700, | |
360 | |
], | |
"typeVersion": 1, | |
"id": "61c3122f-5cad-4773-a4d5-1737fe3df638" | |
}, | |
{ | |
"parameters": {}, | |
"name": "different", | |
"type": "n8n-nodes-base.noOp", | |
"position": [ | |
700, | |
560 | |
], | |
"typeVersion": 1, | |
"id": "790e22b0-97bb-40e6-b202-b2442fea6119" | |
}, | |
{ | |
"parameters": {}, | |
"name": "new", | |
"type": "n8n-nodes-base.noOp", | |
"position": [ | |
700, | |
760 | |
], | |
"typeVersion": 1, | |
"id": "306d44dd-dbbe-42e4-a0b2-dc9dd85c2bc0" | |
}, | |
{ | |
"parameters": { | |
"authentication": "oAuth2", | |
"resource": "file", | |
"operation": "edit", | |
"owner": "={{$node[\"Globals\"].json[\"repo\"][\"owner\"]}}", | |
"repository": "={{$node[\"Globals\"].json[\"repo\"][\"name\"]}}", | |
"filePath": "={{$node[\"Globals\"].json[\"repo\"][\"path\"]}}{{JSON.parse($node[\"Move Binary Data\"].json[\"data\"]).name}}.json", | |
"fileContent": "={{$node[\"isDiffOrNew\"].json[\"n8n_data_stringy\"]}}", | |
"commitMessage": "=[N8N Backup] {{JSON.parse($node[\"Move Binary Data\"].json[\"data\"]).name}}.json ({{$json[\"github_status\"]}})" | |
}, | |
"name": "GitHub Edit", | |
"type": "n8n-nodes-base.github", | |
"position": [ | |
900, | |
560 | |
], | |
"typeVersion": 1, | |
"id": "b01ca3df-5932-460b-a76f-91d450ec18a0", | |
"credentials": { | |
"githubOAuth2Api": { | |
"id": "1", | |
"name": "n8n-locoarm-app" | |
} | |
} | |
}, | |
{ | |
"parameters": { | |
"authentication": "oAuth2", | |
"resource": "file", | |
"owner": "={{$node[\"Globals\"].json[\"repo\"][\"owner\"]}}", | |
"repository": "={{$node[\"Globals\"].json[\"repo\"][\"name\"]}}", | |
"filePath": "={{$node[\"Globals\"].json[\"repo\"][\"path\"]}}{{JSON.parse($node[\"Move Binary Data\"].json[\"data\"]).name}}.json", | |
"fileContent": "={{$node[\"isDiffOrNew\"].json[\"n8n_data_stringy\"]}}", | |
"commitMessage": "=[N8N Backup] {{JSON.parse($node[\"Move Binary Data\"].json[\"data\"]).name}}.json ({{$json[\"github_status\"]}})" | |
}, | |
"name": "GitHub Create", | |
"type": "n8n-nodes-base.github", | |
"position": [ | |
900, | |
760 | |
], | |
"typeVersion": 1, | |
"id": "d1bd44d1-cd0b-4d05-a389-97737d91e62a", | |
"credentials": { | |
"githubOAuth2Api": { | |
"id": "1", | |
"name": "n8n-locoarm-app" | |
} | |
} | |
}, | |
{ | |
"parameters": { | |
"functionCode": "// File Returned with Content\nif (Object.keys(items[0].json).includes(\"content\")) {\n // Get JSON Objects\n var origWorkflow = JSON.parse(Buffer.from(items[0].json.content, 'base64'));\n var n8nWorkflow = items[1].json.data;\n var orderedOriginal = JSON.stringify(origWorkflow, null, 2);\n \n // Determine Difference\n if ( orderedOriginal === n8nWorkflow ) {\n items[0].json.github_status = \"same\";\n items[0].json.content_decoded = orderedOriginal;\n } else {\n items[0].json.github_status = \"different\";\n items[0].json.content_decoded = orderedOriginal;\n items[0].json.n8n_data_stringy = n8nWorkflow;\n }\n// No File Returned / New Workflow\n} else {\n // Order JSON Object\n var n8nWorkflow = (items[1].json.data);\n \n // Proper Formatting\n items[0].json.github_status = \"new\";\n items[0].json.n8n_data_stringy = n8nWorkflow;\n}\n\n// Return Items\nreturn items;" | |
}, | |
"name": "isDiffOrNew", | |
"type": "n8n-nodes-base.function", | |
"position": [ | |
360, | |
560 | |
], | |
"typeVersion": 1, | |
"id": "9fa65139-dd1e-4f6d-ac2b-15008e4c179c" | |
}, | |
{ | |
"parameters": { | |
"triggerTimes": { | |
"item": [ | |
{ | |
"hour": 5 | |
}, | |
{}, | |
{ | |
"hour": 23 | |
} | |
] | |
} | |
}, | |
"name": "Every 2 hours", | |
"type": "n8n-nodes-base.cron", | |
"position": [ | |
-1540, | |
620 | |
], | |
"typeVersion": 1, | |
"id": "f2f836f6-832c-4316-90e4-56ae9f04078e" | |
}, | |
{ | |
"parameters": { | |
"filePath": "={{$json[\"filename\"]}}" | |
}, | |
"name": "Read Binary File", | |
"type": "n8n-nodes-base.readBinaryFile", | |
"position": [ | |
-400, | |
580 | |
], | |
"typeVersion": 1, | |
"id": "79f814ec-e374-4b8b-a036-4d65c233b7a8" | |
}, | |
{ | |
"parameters": { | |
"setAllData": false, | |
"options": {} | |
}, | |
"name": "Move Binary Data", | |
"type": "n8n-nodes-base.moveBinaryData", | |
"position": [ | |
-200, | |
580 | |
], | |
"typeVersion": 1, | |
"id": "6a866495-4d5c-4c13-91af-836fb3c101a9" | |
}, | |
{ | |
"parameters": { | |
"values": { | |
"string": [ | |
{ | |
"name": "repo.owner", | |
"value": "ed-parsadanyan" | |
}, | |
{ | |
"name": "repo.name", | |
"value": "low-code-armenia-n8n-backup" | |
}, | |
{ | |
"name": "repo.path", | |
"value": "workflows/" | |
}, | |
{ | |
"name": "backupFolder", | |
"value": "/home/node/.n8n/git-workflows/" | |
} | |
] | |
}, | |
"options": {} | |
}, | |
"name": "Globals", | |
"type": "n8n-nodes-base.set", | |
"position": [ | |
-1380, | |
480 | |
], | |
"typeVersion": 1, | |
"id": "672b4109-af8d-4a9a-a381-53b20849f8f5" | |
}, | |
{ | |
"parameters": { | |
"command": "=n8n export:workflow --backup --output={{$json[\"backupFolder\"]}}" | |
}, | |
"name": "Run CLI to export Workflows", | |
"type": "n8n-nodes-base.executeCommand", | |
"position": [ | |
-1140, | |
580 | |
], | |
"typeVersion": 1, | |
"id": "f0ae00ea-7369-4c4c-8cf6-4a7c54bd5799" | |
}, | |
{ | |
"parameters": { | |
"command": "=ls -1 {{$node[\"Globals\"].json[\"backupFolder\"]}}" | |
}, | |
"name": "List filenames", | |
"type": "n8n-nodes-base.executeCommand", | |
"position": [ | |
-960, | |
580 | |
], | |
"typeVersion": 1, | |
"id": "3a3e1118-cee4-4714-9c06-79baaa04a31c" | |
}, | |
{ | |
"parameters": { | |
"functionCode": "const newItems = [];\nfor (file of items[0].json.stdout.split('\\n')) {\n newItems.push({\n json: {\n filename: $node[\"Globals\"].json[\"backupFolder\"] + file\n }\n });\n}\nreturn newItems;" | |
}, | |
"name": "Convert filenames to objects with path", | |
"type": "n8n-nodes-base.function", | |
"position": [ | |
-780, | |
580 | |
], | |
"typeVersion": 1, | |
"id": "99f07375-d9b9-42a9-bdfe-d181ae568ec2" | |
}, | |
{ | |
"parameters": { | |
"batchSize": 1, | |
"options": {} | |
}, | |
"name": "One at a time", | |
"type": "n8n-nodes-base.splitInBatches", | |
"position": [ | |
-600, | |
580 | |
], | |
"typeVersion": 1, | |
"id": "062bbe90-fb91-447d-843e-ddc223c8f507" | |
}, | |
{ | |
"parameters": { | |
"authentication": "oAuth2", | |
"resource": "file", | |
"operation": "get", | |
"owner": "={{$node[\"Globals\"].json[\"repo\"][\"owner\"]}}", | |
"repository": "={{$node[\"Globals\"].json[\"repo\"][\"name\"]}}", | |
"filePath": "={{$node[\"Globals\"].json[\"repo\"][\"path\"]}}{{JSON.parse($json[\"data\"]).name}}.json", | |
"additionalParameters": {} | |
}, | |
"name": "GitHub", | |
"type": "n8n-nodes-base.github", | |
"position": [ | |
0, | |
380 | |
], | |
"typeVersion": 1, | |
"alwaysOutputData": true, | |
"id": "d109ac94-dcad-433e-bf04-2944de7b9595", | |
"credentials": { | |
"githubOAuth2Api": { | |
"id": "1", | |
"name": "n8n-locoarm-app" | |
} | |
}, | |
"continueOnFail": true | |
} | |
], | |
"connections": { | |
"Start": { | |
"main": [ | |
[ | |
{ | |
"node": "Globals", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"Merge": { | |
"main": [ | |
[ | |
{ | |
"node": "isDiffOrNew", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"github_status": { | |
"main": [ | |
[ | |
{ | |
"node": "same", | |
"type": "main", | |
"index": 0 | |
} | |
], | |
[ | |
{ | |
"node": "different", | |
"type": "main", | |
"index": 0 | |
} | |
], | |
[ | |
{ | |
"node": "new", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"same": { | |
"main": [ | |
[ | |
{ | |
"node": "One at a time", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"different": { | |
"main": [ | |
[ | |
{ | |
"node": "GitHub Edit", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"new": { | |
"main": [ | |
[ | |
{ | |
"node": "GitHub Create", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"GitHub Edit": { | |
"main": [ | |
[ | |
{ | |
"node": "One at a time", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"GitHub Create": { | |
"main": [ | |
[ | |
{ | |
"node": "One at a time", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"isDiffOrNew": { | |
"main": [ | |
[ | |
{ | |
"node": "github_status", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"Every 2 hours": { | |
"main": [ | |
[ | |
{ | |
"node": "Globals", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"Read Binary File": { | |
"main": [ | |
[ | |
{ | |
"node": "Move Binary Data", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"Move Binary Data": { | |
"main": [ | |
[ | |
{ | |
"node": "GitHub", | |
"type": "main", | |
"index": 0 | |
}, | |
{ | |
"node": "Merge", | |
"type": "main", | |
"index": 1 | |
} | |
] | |
] | |
}, | |
"Globals": { | |
"main": [ | |
[ | |
{ | |
"node": "Run CLI to export Workflows", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"Run CLI to export Workflows": { | |
"main": [ | |
[ | |
{ | |
"node": "List filenames", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"List filenames": { | |
"main": [ | |
[ | |
{ | |
"node": "Convert filenames to objects with path", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"Convert filenames to objects with path": { | |
"main": [ | |
[ | |
{ | |
"node": "One at a time", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"One at a time": { | |
"main": [ | |
[ | |
{ | |
"node": "Read Binary File", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"GitHub": { | |
"main": [ | |
[ | |
{ | |
"node": "Merge", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment