@@ -24,48 +24,66 @@ jobs:
2424 uses : actions/github-script@v7
2525 with :
2626 script : |
27- const prNumber = ${{ inputs.pr_number }};
28- const pr = await github.rest.pulls.get({
29- owner: context.repo.owner,
30- repo: context.repo.repo,
31- pull_number: prNumber
32- });
33-
34- // Get PR body and branch name
35- const prBody = pr.data.body;
36- const branchName = pr.data.head.ref;
37-
38- // Output the PR body and branch name
39- core.setOutput('pr_body', prBody);
40- core.setOutput('branch_name', branchName);
41-
42- return {prBody, branchName};
27+ try {
28+ const prNumber = ${{ inputs.pr_number }};
29+ const pr = await github.rest.pulls.get({
30+ owner: context.repo.owner,
31+ repo: context.repo.repo,
32+ pull_number: prNumber
33+ });
34+
35+ // Get branch name
36+ const branchName = pr.data.head.ref;
37+
38+ // Output the branch name only, not the body
39+ core.setOutput('branch_name', branchName);
40+
41+ return { branchName };
42+ } catch (error) {
43+ console.error('Error getting PR data:', error);
44+ core.setFailed(`Failed to get PR data: ${error.message}`);
45+ }
4346
4447 - name : Extract details from PR body
4548 id : info
4649 uses : actions/github-script@v7
4750 with :
4851 script : |
49- const prBody = '${{ steps.pr_data.outputs.pr_body }}';
50-
51- // More robust pattern matching with regex
52- const vendorMatch = prBody.match(/### Vendor\s*\n\s*\n\s*(.*?)(\n\s*\n|\n\s*###|$)/s);
53- const cameraMatch = prBody.match(/### Camera\s*\n\s*\n\s*(.*?)(\n\s*\n|\n\s*###|$)/s);
54-
55- let vendor = vendorMatch ? vendorMatch[1].trim() : '';
56- const camera = cameraMatch ? cameraMatch[1].trim() : '';
57-
58- if (vendor === 'Other') {
59- const otherVendorMatch = prBody.match(/### Other Vendor\s*\n\s*\n\s*(.*?)(\n\s*\n|\n\s*###|$)/s);
60- if (otherVendorMatch) vendor = otherVendorMatch[1].trim();
52+ const prBody = context.payload.inputs.pr_body || '';
53+ try {
54+ // Get PR data first
55+ const prNumber = ${{ inputs.pr_number }};
56+ const pr = await github.rest.pulls.get({
57+ owner: context.repo.owner,
58+ repo: context.repo.repo,
59+ pull_number: prNumber
60+ });
61+
62+ // Get PR body from the actual PR data
63+ const prBodyText = pr.data.body || '';
64+
65+ // More robust pattern matching with regex
66+ const vendorMatch = prBodyText.match(/### Vendor\s*\n\s*\n\s*(.*?)(\n\s*\n|\n\s*###|$)/s);
67+ const cameraMatch = prBodyText.match(/### Camera\s*\n\s*\n\s*(.*?)(\n\s*\n|\n\s*###|$)/s);
68+
69+ let vendor = vendorMatch ? vendorMatch[1].trim() : '';
70+ const camera = cameraMatch ? cameraMatch[1].trim() : '';
71+
72+ if (vendor === 'Other') {
73+ const otherVendorMatch = prBodyText.match(/### Other Vendor\s*\n\s*\n\s*(.*?)(\n\s*\n|\n\s*###|$)/s);
74+ if (otherVendorMatch) vendor = otherVendorMatch[1].trim();
75+ }
76+
77+ core.exportVariable('vendor', vendor);
78+ core.exportVariable('camera', camera);
79+
80+ console.log(`Extracted Vendor: ${vendor}`);
81+ console.log(`Extracted Camera: ${camera}`);
82+ } catch (error) {
83+ console.error('Error extracting PR details:', error);
84+ core.setFailed(`Failed to extract PR details: ${error.message}`);
6185 }
6286
63- core.exportVariable('vendor', vendor);
64- core.exportVariable('camera', camera);
65-
66- console.log(`Extracted Vendor: ${vendor}`);
67- console.log(`Extracted Camera: ${camera}`);
68-
6987 - name : Debug extracted data
7088 run : |
7189 echo "Vendor: ${{ env.vendor }}"
7997
8098 - name : Process and update JSON with Python
8199 id : python
82- run : |
83- pip install -r ./scripts/requirements.txt
84- python3 ./scripts/update_sensors_and_generate_json.py "${{ steps.pr_data.outputs.pr_body }}" 2> python_error.log || { cat python_error.log; echo "::set-output name=error::$(cat python_error.log)"; exit 1; }
100+ uses : actions/github-script@v7
101+ with :
102+ script : |
103+ const { execSync } = require('child_process');
104+ try {
105+ // Get PR data first to get body
106+ const prNumber = ${{ inputs.pr_number }};
107+ const pr = await github.rest.pulls.get({
108+ owner: context.repo.owner,
109+ repo: context.repo.repo,
110+ pull_number: prNumber
111+ });
112+
113+ // Write PR body to a file to avoid command line escaping issues
114+ const fs = require('fs');
115+ fs.writeFileSync('pr_body.txt', pr.data.body || '');
116+
117+ const result = execSync('pip install -r ./scripts/requirements.txt && python3 ./scripts/update_sensors_and_generate_json.py "$(cat pr_body.txt)" 2> python_error.log || { cat python_error.log; exit 1; }', { encoding: 'utf8' });
118+ console.log(result);
119+ } catch (error) {
120+ console.error('Error running Python script:', error);
121+ const errorLog = require('fs').readFileSync('python_error.log', 'utf8');
122+ core.setOutput('error', errorLog);
123+ core.setFailed(`Failed to run Python script: ${error.message}`);
124+ }
85125
86126 - name : Generate csv
87127 id : csv
0 commit comments