diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml new file mode 100644 index 0000000..4aa8c59 --- /dev/null +++ b/.github/workflows/sync.yml @@ -0,0 +1,22 @@ + +name: Sync Fork + +on: + schedule: + - cron: '*/30 * * * *' # every 30 minutes + workflow_dispatch: # on button click + +jobs: + sync: + + runs-on: ubuntu-latest + + steps: + - uses: tgymnich/fork-sync@v1.3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + personal_token: ${{ secrets.KALEIDOBOT_TOKEN }} + owner: hyperledger-labs + base: main + head: main + auto_approve: true diff --git a/src/lib/config.ts b/src/lib/config.ts index 54246a3..7bcabc6 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -67,5 +67,27 @@ const loadConfig = async () => { }; export const persistPeers = async () => { + await ensurePeersDirectoryExists(); await fs.writeFile(peersFilePath, JSON.stringify(config.peers, null, 2)); +}; + +const ensurePeersDirectoryExists = async () => { + try { + await fs.access(peersFilePath); + } catch(err) { + if(err.code === 'ENOENT') { + await createPeersDirectory(); + } else { + log.warn(`Could not check for existence of peers subdirectory ${err.code}`); + } + } +}; + +const createPeersDirectory = async () => { + try { + await fs.mkdir(path.parse(peersFilePath).dir, { recursive: true }); + log.info('Peers subdirectory created'); + } catch(err) { + log.error(`Failed to create peers subdirectory ${err.code}`); + } }; \ No newline at end of file