Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 0 additions & 56 deletions .github/workflows/sync-docs.yml

This file was deleted.

57 changes: 39 additions & 18 deletions scripts/syncDocs/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import path from 'path'
import fs from 'fs-extra'
import { glob } from 'glob'
import { execSync } from 'child_process'
import simpleGit from 'simple-git'

import log from './log'
import createPullRequest from './createPullRequest'
import sendDiscordNotification from './sendDiscordNotification'


const branchName = 'sync-sdk'
Expand All @@ -15,9 +15,32 @@ const docsRepoPath = `${process.cwd()}/docs`
const documentationPath = `${process.cwd()}/documentation`
const docsRepoUrl = 'git@github.com:stakewise/stakewise-docs.git'

const commitAuthor = process.env.COMMIT_AUTHOR || 'unknown'
const syncDocsToken = process.env.SYNC_DOCS_TOKEN
const discordWebhookUrl = process.env.DISCORD_WEBHOOK_URL
const getGitUserName = () => {
try {
return execSync('git config user.name', { encoding: 'utf-8' }).trim()
}
catch {
return 'unknown'
}
}

const getGitHubToken = () => {
try {
const output = execSync(
'echo "protocol=https\nhost=github.com" | git credential fill',
{ encoding: 'utf-8', shell: '/bin/sh' },
)
const match = output.match(/password=(.+)/)

return match?.[1]?.trim()
}
catch {
return undefined
}
}

const commitAuthor = getGitUserName()
const syncDocsToken = getGitHubToken()

const changeTargetPath = (path: string) => path
.replace('services/', 'API/')
Expand All @@ -37,6 +60,11 @@ const changeTargetPath = (path: string) => path

log.info('🤖 Start of documentation synchronization...')

if (!syncDocsToken) {
log.error('GitHub token not found. Make sure your git credentials for github.com are configured.')
process.exit(1)
}

try {
const isExist = await fs.pathExists(docsRepoPath)

Expand Down Expand Up @@ -103,11 +131,7 @@ const changeTargetPath = (path: string) => path

log.success('Files are copied')

await git
.addConfig('user.name', 'github-actions[bot]')
.addConfig('user.email', 'github-actions[bot]@users.noreply.github.com')

log.success(`GitHub Commit signer is set.`)
log.info(`👤 Commit author: ${commitAuthor}`)

await git.add('.')

Expand All @@ -122,24 +146,21 @@ const changeTargetPath = (path: string) => path

log.success(`Changes are pushed to '${branchName}' branch.`)

const prData = await createPullRequest({
await createPullRequest({
authToken: syncDocsToken,
repo: 'stakewise-docs',
owner: 'stakewise',
baseBranch: 'main',
branchName,
title,
})

await sendDiscordNotification({
discordWebhookUrl,
author: commitAuthor,
prUrl: prData.html_url,
filesCount: filesCount,
})
}
catch (error) {
log.error(`${error}`)
process.exit(1)
}
}
finally {
await fs.remove(docsRepoPath)
log.success('🧹 Cloned docs repository has been cleaned up.')
}
})()
76 changes: 0 additions & 76 deletions scripts/syncDocs/sendDiscordNotification.ts

This file was deleted.