fix(ci): resolve newman auth errors and broken markdown links #40
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: API Contract Testing | |
| on: | |
| push: | |
| branches: [ main, master ] | |
| pull_request: | |
| branches: [ main, master ] | |
| jobs: | |
| contract-validation: | |
| name: Newman Postman Tests & Linting | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Install Testing Tools (Newman, Prism & Spectral) | |
| run: npm install -g newman @stoplight/prism-cli @stoplight/spectral-cli | |
| - name: Lint OpenAPI Specification (Contract Quality) | |
| # Creamos el archivo de reglas físicamente para que Spectral lo lea sin problemas | |
| run: | | |
| echo 'extends: ["spectral:oas"]' > .spectral.yaml | |
| spectral lint api/openapi.yaml --ruleset=.spectral.yaml | |
| - name: Prepare Workspace and Clean Collection | |
| run: | | |
| echo "fake image content" > test-image.jpg | |
| node -e " | |
| const fs = require('fs'); | |
| let data = JSON.parse(fs.readFileSync('postman/LumaTrace_Cloud_API.postman_collection.json', 'utf8')); | |
| function fixItems(items) { | |
| for (let i = items.length - 1; i >= 0; i--) { | |
| let item = items[i]; | |
| if (item.item) { | |
| fixItems(item.item); | |
| } else { | |
| if (item.request && item.request.url && item.request.url.raw) { | |
| item.request.url.raw = item.request.url.raw.replace(/https:\/\/api\.lumatrace\.es/g, '{{base_url}}'); | |
| if (Array.isArray(item.request.url.host)) { | |
| item.request.url.host = ['{{base_url}}']; | |
| } | |
| } | |
| if (item.request && item.request.body && item.request.body.formdata) { | |
| item.request.body.formdata.forEach(fd => { | |
| if (fd.type === 'file') { | |
| fd.src = 'test-image.jpg'; | |
| } | |
| }); | |
| } | |
| } | |
| } | |
| } | |
| fixItems(data.item); | |
| fs.writeFileSync('postman/LumaTrace_Cloud_API.postman_collection.json', JSON.stringify(data, null, 2)); | |
| " | |
| - name: Start OpenAPI Mock Server (Prism) | |
| run: | | |
| touch prism.log | |
| prism mock api/openapi.yaml -p 4010 > prism.log 2>&1 & | |
| - name: Wait for Mock Server to boot | |
| run: sleep 8 | |
| - name: Run Postman Collection via Newman | |
| run: | | |
| newman run postman/LumaTrace_Cloud_API.postman_collection.json \ | |
| --env-var "base_url=http://127.0.0.1:4010" \ | |
| --env-var "tenant_id=system-admin-tenant" \ | |
| --env-var "username=admin" \ | |
| --env-var "password=Admin_LumaTrace_2026#" \ | |
| --reporters cli \ | |
| --working-dir . | |
| - name: Debug Prism on Failure | |
| if: failure() | |
| run: | | |
| echo "--- PRISM LOGS ---" | |
| [ -f prism.log ] && cat prism.log || echo "Prism log file not found." |