name: Postman CLI Test Run on: push: branches: - master - staging pull_request: branches: - master - staging workflow_dispatch: permissions: contents: read pages: write id-token: write pull-requests: write jobs: postman-cli: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: pnpm/action-setup@v4 - uses: actions/setup-node@v4 with: node-version: "18" cache: "pnpm" - run: pnpm install --frozen-lockfile - name: Start API server run: pnpm start & env: NODE_ENV: test - name: Wait for API to be ready run: npx wait-on http://localhost:3000/docs --timeout 30000 - name: Install Postman CLI run: | curl -o- "https://dl-cli.pstmn.io/install/linux64.sh" | sh - name: Run Postman Collection id: postman-run run: | postman collection run "ci-local-newman.postman_collection.json" \ --env-var baseUrl=http://localhost:3000 \ -r cli,json,html \ --reporter-html-export ./postman-cli-reports/postman-cli-report.html \ --reporter-json-export ./postman-cli-reports/postman-cli-report.json continue-on-error: true - name: Comment PR with test results if: github.event_name == 'pull_request' uses: actions/github-script@v7 with: script: | const fs = require('fs'); let body = '## Postman CLI Test Results\n\n'; try { const raw = fs.readFileSync('./postman-cli-reports/postman-cli-report.json', 'utf8'); const report = JSON.parse(raw); const run = report.run ? report.run : report; const statsTests = run.stats && (run.stats.assertions ? run.stats.assertions : run.stats.assertion); const tests = (run.summary && run.summary.tests) ? run.summary.tests : (statsTests ? statsTests : {}); const passed = tests.passed != null ? tests.passed : (tests.pass != null ? tests.pass : 0); const failed = tests.failed != null ? tests.failed : (tests.fail != null ? tests.fail : 0); const total = tests.executed != null ? tests.executed : (passed + failed > 0 ? passed + failed : '?'); const status = failed === 0 ? '✅ All tests passed!' : `❌ ${failed} test(s) failed`; body += `| Metric | Count |\n|--------|-------|\n`; body += `| Passed | ${passed} |\n`; body += `| Failed | ${failed} |\n`; body += `| Total | ${total} |\n\n`; body += `**Status:** ${status}\n\n`; } catch (e) { body += 'Report generated. Check workflow logs for details.\n\n'; } body += `📊 [View workflow run](${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}) to download the HTML report.\n`; const { data: comments } = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number }); const botComment = comments.find(c => c.user.type === 'Bot' && c.body.includes('Postman CLI Test Results')); if (botComment) { await github.rest.issues.updateComment({ owner: context.repo.owner, repo: context.repo.repo, comment_id: botComment.id, body }); } else { await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, body }); } - name: Upload test reports if: success() || failure() uses: actions/upload-artifact@v4 with: name: postman-cli-reports path: postman-cli-reports publish-pages-artifact: if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/staging') && (success() || failure()) && !cancelled() needs: postman-cli runs-on: ubuntu-latest steps: - name: Download test reports uses: actions/download-artifact@v4 with: name: postman-cli-reports - name: Prepare GitHub Pages artifact run: | mkdir -p pages-output REPORT=$(find . -name "postman-cli-report.html" -o -name "newman-report.html" 2>/dev/null | head -1) if [ -n "$REPORT" ]; then cp "$REPORT" pages-output/index.html else echo '

No report generated

Check workflow logs.

' > pages-output/index.html fi mkdir -p pages-output/postman-cli-reports [ -f postman-cli-report.html ] && cp postman-cli-report.html pages-output/postman-cli-reports/ || true [ -f postman-cli-report.json ] && cp postman-cli-report.json pages-output/postman-cli-reports/ || true [ -d postman-cli-reports ] && cp -r postman-cli-reports/* pages-output/postman-cli-reports/ 2>/dev/null || true - name: Upload Pages artifact uses: actions/upload-pages-artifact@v3 with: path: pages-output deploy-pages: if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/staging') && always() && !cancelled() needs: publish-pages-artifact runs-on: ubuntu-latest environment: name: github-pages url: ${{ steps.deploy.outputs.page_url }} steps: - name: Configure Pages uses: actions/configure-pages@v4 - name: Deploy to GitHub Pages id: deploy uses: actions/deploy-pages@v4