Skip to content

Commit

Permalink
test workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
mmd-afegbua committed Feb 20, 2024
1 parent 8288609 commit e4a18fb
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 1 deletion.
51 changes: 51 additions & 0 deletions .github/workflows/weekly-snapsots.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Weekly Sentinel Snapshots
on:
schedule:
- cron: '0 0 * * 0'
push:
branches:
- '*'

jobs:
snapshots:
name: "Create Snapshots, Upload and Update Manifests"
runs-on: ubuntu-latest

strategy:
matrix:
network: [base-mainnet, bsc-mainnet, eth-mainnet, optimism-mainnet]

steps:
- name: Check out the repo
uses: actions/checkout@v2

- name: Get current date
id: get-date
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: 21.x

- name: Install jq
uses: dcarbone/[email protected]

- name: Set up IPFS
uses: ibnesayeed/setup-ipfs@master
id: ipfs_setup

- name: Build Snapshot
run: ./scripts/manageSnapshot.sh -g ${{ matrix.network }}

- name: Upload Snapshot
run: ./scripts/manageSnapshot.sh -u

- name: Create Pull Request
uses: peter-evans/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
add-paths: |
manifest.json
commit-message: ${{ steps.get-date.outputs.date }} uupdate manifest
title: 'Update manifests for ${{ steps.get-date.outputs.date }}'
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ datadir/
snapshots/
coverage
typechain
networks
*error.log

# Hardhat files
cache
Expand Down
2 changes: 1 addition & 1 deletion scripts/buildSnapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const EventModel = require("./../src/models/EventModel");
const Bootstrap = require("./../src/boot/bootstrap");
const LoadEvents = require("./../src/boot/loadEvents");
const DB = require("./../src/database/db");
const Repository = require("./../src/database/repository");
const Repository = require("./../src/database/businessRepository");
const Timer = require("./../src/utils/timer");
const metadata = require("@superfluid-finance/metadata/networks.json");
const {QueryTypes} = require("sequelize");
Expand Down
54 changes: 54 additions & 0 deletions scripts/generateManifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const { writeFileSync, readFileSync } = require("fs");

function cleanLogData(path) {
const newCIDs = new Map();
try {
readFileSync(path, "utf8").split(/\r?\n/).forEach(line => {
const splitLine = line.split(",");
const fileName = splitLine[0];
const filtered = fileName.match("_(.*)_")
if(filtered) {
newCIDs.set(filtered[1], splitLine[1]);
}
});
return newCIDs;
} catch (err) {
console.log(err);
}
}

(() => {
try {
const myArgs = process.argv.slice(2);
const ipfsLog = myArgs[0];
const outputFile = myArgs[1];

console.log(`ipfs log file: ${ipfsLog}, output file: ${outputFile}`);

if(!ipfsLog) {
throw new Error("No IPFS log")
}
if(!outputFile) {
throw new Error("No output file")
}

const newCIDs = cleanLogData(ipfsLog);
/*if(newCIDs.size !== 10) {
throw new Error("IPFS log not complety")
}*/

// Read manifest data from local file
const manifestJson = JSON.parse(readFileSync('manifest.json', 'utf8'));

// Update manifest in memory
for (const [key, value] of newCIDs) {
manifestJson.networks[key].cid = value;
}

// Write updated manifest to output file
writeFileSync(outputFile, JSON.stringify(manifestJson, null, 2));

} catch (err) {
console.error(err)
}
})();
28 changes: 28 additions & 0 deletions scripts/getMetadata.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#Generate networks file from Superfluid Metadata
#!/bin/bash

# Superfluid Metdata URL
input_json_url="https://raw.githubusercontent.com/superfluid-finance/protocol-monorepo/dev/packages/metadata/networks.json"

# Variables
common_domain="${COMMON_DOMAIN}"

# Download the input JSON file
wget -O input.json "$input_json_url"

# Check if jq is installed
if ! command -v jq &>/dev/null; then
echo "jq is required but it's not installed. Aborting."
exit 1
fi

# Process the input JSON file
# Create output file
output_file="output.txt"

# Extract data from JSON and write to text file
jq -r --arg common_domain "$common_domain" '.[] | "\(.name),https://\(.name)\($common_domain)"' input.json > networks

echo "Text file created: networks"

rm input.json
83 changes: 83 additions & 0 deletions scripts/manageSnapshots.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/bash

set -xe

#Variables
filename="networks"
ipfs_api="${IPFS_API:-"/ip4/65.21.152.182/tcp/5001"}"

generate_snapshot() {
echo "Generating new snapshots..."
yarn install

if [ ! -d "snapshots" ]; then
mkdir snapshots
fi

# Check if network argument is provided
if [ -z "$1" ]; then
echo "Usage: $0 -g <network>"
exit 1
fi

# Search for the specified network in the filename
if grep -q "^$1," "$filename"; then
echo "Generating snapshot for $1..."
url=$(grep "^$1," "$filename" | cut -d ',' -f 2) # Extract URL
[ -n "$url" ] && node ./scripts/buildSnapshot.js "$url"
echo "Generating done"
else
echo "Error: Network '$1' not found in '$filename'."
exit 1
fi
}


upload_snapshot() {
echo "Uploading snapshots..."
ipfs_logfile="logs/ipfs_$(date '+%Y-%m-%d').txt"
rm -f -- "$ipfs_logfile"
for file in ./snapshots/*.sqlite.gz; do
ipfs_hash=`ipfs --api "$ipfs_api" add -q $file`
echo $file,$ipfs_hash >> "$ipfs_logfile"
done
rm manifest.json
node ./scripts/generateManifest.js "$ipfs_logfile" manifest.json
ipfs_hash=`ipfs --api "$ipfs_api" add -q manifest.json`
echo manifest.json,$ipfs_hash >> "$ipfs_logfile"
# updating the manifest ipns link
ipfs --api "$ipfs_api" name publish --key=sentinel-manifest "$ipfs_hash"
echo "Uploading snapshots done"
}

clean_snapshots() {
echo "Cleaning snapshot folder..."
rm -f -- "$HOME/snapshots"/*.gz
echo "Cleaning done"
}

# Usage
usage() {
echo "Usage: $0 [-g] [-u] [-p] [-c]"
echo "Options:"
echo " -g <network-name> Generate snapshots"
echo " -u Upload snapshots"
echo " -c Clean snapshots"
exit 1
}

# Command line options
while getopts "g:upc" opt; do
case $opt in
g) generate_snapshot "$OPTARG" ;;
u) upload_snapshot ;;
c) clean_snapshots ;;
*) usage ;;
esac
done


# If no options are provided, show usage
if [[ $# -eq 0 ]]; then
usage
fi

0 comments on commit e4a18fb

Please sign in to comment.