example(connector_sdk) : re-raised new connector #234
This file contains hidden or 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
| name: README | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| permissions: | |
| contents: read | |
| jobs: | |
| check-readme-update: | |
| runs-on: ubuntu-latest | |
| name: Check Updates for New Examples | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | |
| with: | |
| fetch-depth: 0 # Fetch all history for proper diff | |
| persist-credentials: false | |
| - name: Ensure SHAs are fetched | |
| env: | |
| BASE_SHA: ${{ github.event.pull_request.base.sha }} | |
| HEAD_SHA: ${{ github.event.pull_request.head.sha }} | |
| HEAD_REPO: ${{ github.event.pull_request.head.repo.clone_url }} | |
| run: | | |
| git fetch --no-tags --prune origin "$BASE_SHA" | |
| git fetch --no-tags --prune "$HEAD_REPO" "$HEAD_SHA" | |
| - name: Create check script | |
| id: create-script | |
| run: | | |
| cat > check-readme-update.js << 'EOF' | |
| const path = require('path'); | |
| const { execFileSync } = require('child_process'); | |
| const SHA_RE = /^[0-9a-f]{40}$/i; | |
| function getRequiredSha(name) { | |
| const value = process.env[name]; | |
| if (!SHA_RE.test(value || '')) { | |
| console.error(`${name} is not a valid git SHA`); | |
| process.exit(1); | |
| } | |
| return value; | |
| } | |
| // Get the list of files changed in the PR | |
| function getChangedFiles() { | |
| try { | |
| // Get the base branch (target) of the PR | |
| const baseSha = getRequiredSha('BASE_SHA'); | |
| // Get current branch (source) of the PR | |
| const headSha = getRequiredSha('HEAD_SHA'); | |
| // Use Git directly to get all changed files between branches | |
| const gitDiff = execFileSync( | |
| 'git', | |
| ['diff', '--name-status', `${baseSha}...${headSha}`], | |
| { encoding: 'utf-8' } | |
| ); | |
| // Parse the git diff output | |
| return gitDiff.trim().split('\n').filter(line => line).map(line => { | |
| const fields = line.split('\t'); | |
| const status = fields[0]; | |
| const filename = | |
| status.startsWith('R') || status.startsWith('C') ? fields[2] : fields[1]; | |
| if (!filename) { | |
| throw new Error(`Unexpected git diff --name-status output: ${line}`); | |
| } | |
| return { status, filename }; | |
| }); | |
| } catch (error) { | |
| console.error('Error getting changed files:', error); | |
| process.exit(1); | |
| } | |
| } | |
| // Check if a directory exists before our PR | |
| function directoryExistsInBase(dirPath) { | |
| try { | |
| const baseSha = getRequiredSha('BASE_SHA'); | |
| // Check if this directory exists in the base branch | |
| const result = execFileSync( | |
| 'git', | |
| ['ls-tree', '-d', baseSha, '--', dirPath], | |
| { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'ignore'] } | |
| ); | |
| return result.trim() !== ''; | |
| } catch (error) { | |
| // If we get an error, the directory doesn't exist in base | |
| return false; | |
| } | |
| } | |
| // Main function to check if directories were added without README update | |
| function checkReadmeUpdate() { | |
| // Define directories to ignore (infrastructure directories) | |
| const ignoredDirectories = [ | |
| 'git_hooks', | |
| '.github', | |
| '.github/workflows', | |
| '.circleci', | |
| '.devops', | |
| 'ci', | |
| '.ci', | |
| 'scripts' | |
| ]; | |
| // Get all files changed in this PR | |
| const changedFiles = getChangedFiles(); | |
| // Track added directories | |
| const addedDirs = new Set(); | |
| // Check for README.md update | |
| let isReadmeUpdated = false; | |
| // Process each changed file | |
| changedFiles.forEach(file => { | |
| // Skip deleted files | |
| if (file.status === 'D') return; | |
| // Check if this is the root README.md | |
| if (file.filename === 'README.md' && !file.filename.includes('/')) { | |
| isReadmeUpdated = true; | |
| } | |
| // Check if this file adds a new directory | |
| const dirPath = path.dirname(file.filename); | |
| if (dirPath !== '.') { | |
| // Add this directory and all parent directories, but only if they're new | |
| let currentPath = dirPath; | |
| while (currentPath && currentPath !== '.') { | |
| // Only add if this directory doesn't exist in the base branch | |
| // and is not in our ignore list (including subdirectories) | |
| if ( | |
| !directoryExistsInBase(currentPath) && | |
| !ignoredDirectories.some( | |
| ignored => currentPath === ignored || currentPath.startsWith(ignored + '/') | |
| ) | |
| ) { | |
| addedDirs.add(currentPath); | |
| } | |
| currentPath = path.dirname(currentPath); | |
| } | |
| } | |
| }); | |
| // Log what we found | |
| if (addedDirs.size > 0) { | |
| console.log(`New directories added: ${Array.from(addedDirs).join(', ')}`); | |
| } else { | |
| console.log('No new directories added.'); | |
| } | |
| // If we have new directories but README isn't updated, fail the check | |
| if (addedDirs.size > 0 && !isReadmeUpdated) { | |
| console.error(`::error::PR adds new directories (${Array.from(addedDirs).join(', ')}) but README.md is not updated. Please update README.md to document these new directories.`); | |
| process.exit(1); | |
| } | |
| console.log('Check passed!'); | |
| } | |
| // Run the check | |
| checkReadmeUpdate(); | |
| EOF | |
| - name: Run directory check script | |
| env: | |
| BASE_SHA: ${{ github.event.pull_request.base.sha }} | |
| HEAD_SHA: ${{ github.event.pull_request.head.sha }} | |
| run: node check-readme-update.js | |
| - name: Debug information | |
| if: always() | |
| env: | |
| BASE_SHA: ${{ github.event.pull_request.base.sha }} | |
| HEAD_SHA: ${{ github.event.pull_request.head.sha }} | |
| HEAD_REPO: ${{ github.event.pull_request.head.repo.clone_url }} | |
| run: | | |
| printf 'BASE_SHA: %s\n' "$BASE_SHA" | |
| printf 'HEAD_SHA: %s\n' "$HEAD_SHA" | |
| printf 'HEAD_REPO: %s\n' "$HEAD_REPO" | |
| echo "Git Branches:" | |
| git branch -a |