|
| 1 | +name: Process Connection Changes |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + paths: |
| 7 | + - 'store/connections/*.yml' |
| 8 | + workflow_dispatch: # Para testar manualmente |
| 9 | + |
| 10 | +jobs: |
| 11 | + process-connections: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout repository |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 19 | + |
| 20 | + - name: Setup Node.js |
| 21 | + uses: actions/setup-node@v4 |
| 22 | + with: |
| 23 | + node-version: '18' |
| 24 | + |
| 25 | + - name: Install dependencies |
| 26 | + run: | |
| 27 | + npm install -g js-yaml mustache |
| 28 | + |
| 29 | + - name: Process connection files |
| 30 | + run: | |
| 31 | + # Criar script para processar as conexões |
| 32 | + cat << 'EOF' > process_connections.js |
| 33 | + const fs = require('fs'); |
| 34 | + const yaml = require('js-yaml'); |
| 35 | + const mustache = require('mustache'); |
| 36 | + const path = require('path'); |
| 37 | + |
| 38 | + // Ler template |
| 39 | + const template = fs.readFileSync('templates/connection-template.mdx', 'utf8'); |
| 40 | + |
| 41 | + // Processar todos os YAMLs |
| 42 | + const connectionsDir = 'store/connections'; |
| 43 | + const outputDir = 'connections'; |
| 44 | + const connections = []; |
| 45 | + |
| 46 | + // Garantir que o diretório de saída existe |
| 47 | + if (!fs.existsSync(outputDir)) { |
| 48 | + fs.mkdirSync(outputDir, { recursive: true }); |
| 49 | + } |
| 50 | + |
| 51 | + // Ler todos os arquivos YAML |
| 52 | + const files = fs.readdirSync(connectionsDir).filter(file => file.endsWith('.yml')); |
| 53 | + |
| 54 | + files.forEach(file => { |
| 55 | + try { |
| 56 | + const filePath = path.join(connectionsDir, file); |
| 57 | + const yamlContent = fs.readFileSync(filePath, 'utf8'); |
| 58 | + const connection = yaml.load(yamlContent); |
| 59 | + |
| 60 | + // Adicionar à lista de conexões |
| 61 | + connections.push(connection); |
| 62 | + |
| 63 | + // Gerar MDX usando template |
| 64 | + const mdxContent = mustache.render(template, connection); |
| 65 | + const outputFile = path.join(outputDir, `${connection.id}.mdx`); |
| 66 | + fs.writeFileSync(outputFile, mdxContent); |
| 67 | + |
| 68 | + console.log(`Generated: ${outputFile}`); |
| 69 | + } catch (error) { |
| 70 | + console.error(`Error processing ${file}:`, error); |
| 71 | + } |
| 72 | + }); |
| 73 | + |
| 74 | + // Atualizar JSON consolidado |
| 75 | + const jsonOutput = { |
| 76 | + connections: connections |
| 77 | + }; |
| 78 | + |
| 79 | + fs.writeFileSync('store/connections.json', JSON.stringify(jsonOutput, null, 2)); |
| 80 | + console.log('Updated store/connections.json'); |
| 81 | + |
| 82 | + EOF |
| 83 | + |
| 84 | + node process_connections.js |
| 85 | + |
| 86 | + - name: Commit and push changes |
| 87 | + run: | |
| 88 | + git config --local user.email "[email protected]" |
| 89 | + git config --local user.name "GitHub Action" |
| 90 | + git add connections/*.mdx store/connections.json |
| 91 | + git diff --staged --quiet || git commit -m "Auto-generate connection docs from YAML [skip ci]" |
| 92 | + git push |
0 commit comments