From 850e4298f2299a30e7a33c0db49714b2b9f30548 Mon Sep 17 00:00:00 2001 From: Andrey Kopylov Date: Tue, 31 Mar 2026 17:24:31 +0500 Subject: [PATCH 1/2] [remove-sync-docs] remove git action and change script --- .github/workflows/sync-docs.yml | 56 --------------- scripts/syncDocs/index.ts | 57 +++++++++++----- scripts/syncDocs/sendDiscordNotification.ts | 76 --------------------- 3 files changed, 39 insertions(+), 150 deletions(-) delete mode 100644 .github/workflows/sync-docs.yml delete mode 100644 scripts/syncDocs/sendDiscordNotification.ts diff --git a/.github/workflows/sync-docs.yml b/.github/workflows/sync-docs.yml deleted file mode 100644 index c6465813..00000000 --- a/.github/workflows/sync-docs.yml +++ /dev/null @@ -1,56 +0,0 @@ -name: Sync docs to StakeWise Docs - -on: - push: - branches: - - main - paths: - - 'src/**/*.md' - - 'src/**/*.mdx' - - 'documentation/**/*.md' - -permissions: - contents: read - pull-requests: read - -jobs: - sync-docs: - runs-on: ubuntu-latest - - steps: - - name: Checkout repo - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Setup pnpm - uses: pnpm/action-setup@v4 - with: - version: 10.25.0 - - - name: Setup Node.js - uses: actions/setup-node@v6 - with: - node-version: '24' - cache: 'pnpm' - - - name: Setup SSH key for docs repository - uses: webfactory/ssh-agent@v0.9.0 - with: - ssh-private-key: ${{ secrets.SYNC_DOCS_SSH_KEY }} - - - name: Install dependencies - run: | - pnpm install - - - name: Version check - run: pnpm check:version - continue-on-error: false - - - name: Run docs sync - env: - SYNC_DOCS_TOKEN: ${{ secrets.SYNC_DOCS_TOKEN }} - DISCORD_USERS_JSON: ${{ secrets.DISCORD_USERS_JSON }} - DISCORD_WEBHOOK_URL: ${{ secrets.SYNC_DOCS_DISCORD_WEBHOOK_URL }} - COMMIT_AUTHOR: ${{ github.actor }} - run: pnpm sync:docs diff --git a/scripts/syncDocs/index.ts b/scripts/syncDocs/index.ts index 6a9e1f16..d080a29d 100644 --- a/scripts/syncDocs/index.ts +++ b/scripts/syncDocs/index.ts @@ -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' @@ -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/') @@ -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) @@ -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('.') @@ -122,7 +146,7 @@ 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', @@ -130,16 +154,13 @@ const changeTargetPath = (path: string) => path 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.') + } })() diff --git a/scripts/syncDocs/sendDiscordNotification.ts b/scripts/syncDocs/sendDiscordNotification.ts deleted file mode 100644 index c7ce3116..00000000 --- a/scripts/syncDocs/sendDiscordNotification.ts +++ /dev/null @@ -1,76 +0,0 @@ -import log from './log' - - -type Input = { - prUrl: string - author: string - filesCount: number - discordWebhookUrl?: string -} - -const sendDiscordNotification = async (values: Input) => { - const { prUrl, author, filesCount, discordWebhookUrl } = values - - if (!discordWebhookUrl) { - log.info('Discord webhook URL not provided, skipping notification.') - - return - } - - try { - const users = JSON.parse(process.env.DISCORD_USERS_JSON || '{}') - - const user = users[author] - - const mention = user ? `**<@${user}>**` : 'Unknown author' - - const discordMessage = { - username: 'SDK Docs Sync', - avatar_url: 'https://github.com/github.png', - embeds: [ - { - title: '๐Ÿ“š SDK Documentation Synced', - description: `${mention} Documentation has been automatically synchronized and a PR is ready for review.`, - color: 0x00ff00, - fields: [ - { - name: '๐Ÿ”— Pull Request', - value: `**[View PR](${prUrl})**`, - inline: true - }, - { - name: '๐Ÿ“ Files Synced', - value: `${filesCount} files`, - inline: true - } - ], - timestamp: new Date().toISOString(), - footer: { - text: 'StakeWise Docs Sync' - } - } - ] - } - - const response = await fetch(discordWebhookUrl, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify(discordMessage), - }) - - if (response.ok) { - log.success('๐Ÿ“ข Discord notification sent successfully.') - } - else { - log.error(`Failed to send Discord notification: ${response.statusText}`) - } - } - catch (error) { - log.error(`Error sending Discord notification: ${error}`) - } -} - - -export default sendDiscordNotification From 0f8ec8c479bbb711cbf9756c7ce458a87165d8ea Mon Sep 17 00:00:00 2001 From: Andrey Kopylov Date: Tue, 31 Mar 2026 19:50:27 +0500 Subject: [PATCH 2/2] change git action --- .github/workflows/build-check.yml | 6 +++--- .github/workflows/unit-tests.yml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-check.yml b/.github/workflows/build-check.yml index 0f4f9b82..cc7b0b05 100644 --- a/.github/workflows/build-check.yml +++ b/.github/workflows/build-check.yml @@ -13,15 +13,15 @@ jobs: packages: read steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 - name: Setup pnpm - uses: pnpm/action-setup@v4 + uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 with: version: 10.25.0 - name: Setup Node - uses: actions/setup-node@v6 + uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f with: node-version: '24.12.0' diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 8f0e95ee..e05a49e1 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -13,15 +13,15 @@ jobs: packages: read steps: - name: Checkout ๐Ÿ›Ž๏ธ - uses: actions/checkout@v4 + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 - name: Setup pnpm - uses: pnpm/action-setup@v4 + uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 with: version: 10.25.0 - name: Setup Node - uses: actions/setup-node@v6 + uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f with: cache: pnpm scope: '@stakewise'