[New Sensor]: RED V-RAPTOR 8K VV #42
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: Sensor Submission | |
| on: | |
| issues: | |
| types: [opened, edited] | |
| jobs: | |
| create_pr: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 # Prevent stuck workflows | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: main | |
| - name: Extract issue details | |
| id: info | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const issueBody = `${{ github.event.issue.body }}`; | |
| // More robust pattern matching with regex | |
| const vendorMatch = issueBody.match(/### Vendor\s*\n\s*\n\s*(.*?)(\n\s*\n|\n\s*###|$)/s); | |
| const cameraMatch = issueBody.match(/### Camera\s*\n\s*\n\s*(.*?)(\n\s*\n|\n\s*###|$)/s); | |
| let vendor = vendorMatch ? vendorMatch[1].trim() : ''; | |
| const camera = cameraMatch ? cameraMatch[1].trim() : ''; | |
| if (vendor === 'Other') { | |
| const otherVendorMatch = issueBody.match(/### Other Vendor\s*\n\s*\n\s*(.*?)(\n\s*\n|\n\s*###|$)/s); | |
| if (otherVendorMatch) vendor = otherVendorMatch[1].trim(); | |
| } | |
| core.exportVariable('vendor', vendor); | |
| core.exportVariable('camera', camera); | |
| console.log(`Extracted Vendor: ${vendor}`); | |
| console.log(`Extracted Camera: ${camera}`); | |
| - name: Debug extracted data | |
| run: | | |
| echo "Vendor: ${{ env.vendor }}" | |
| echo "Camera: ${{ env.camera }}" | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| cache: "pip" | |
| - name: Process and update JSON with Python | |
| id: python | |
| run: | | |
| pip install -r ./scripts/requirements.txt | |
| python3 ./scripts/update_sensors_and_generate_json.py "${{ github.event.issue.body }}" 2> python_error.log || { cat python_error.log; echo "::set-output name=error::$(cat python_error.log)"; exit 1; } | |
| - name: Generate csv | |
| id: csv | |
| run: | | |
| python3 scripts/generate_csv.py 2> csv_error.log || { cat csv_error.log; echo "::set-output name=error::$(cat csv_error.log)"; exit 1; } | |
| - name: Generate yaml | |
| id: yaml | |
| run: | | |
| python3 scripts/generate_yaml.py 2> yaml_error.log || { cat yaml_error.log; echo "::set-output name=error::$(cat yaml_error.log)"; exit 1; } | |
| - name: Generate markdown/documentation | |
| id: markdown | |
| run: | | |
| python3 scripts/generate_markdown.py 2> markdown_error.log || { cat markdown_error.log; echo "::set-output name=error::$(cat markdown_error.log)"; exit 1; } | |
| - name: Create a safe branch name | |
| run: | | |
| title=$(echo '${{ github.event.issue.title }}' | tr ' ' '_' | tr -cd '[:alnum:]_-') | |
| timestamp=$(date +%Y%m%d%H%M%S) | |
| echo "branch_name=sensor_${title}_${timestamp}" >> $GITHUB_ENV | |
| - name: Create Pull Request | |
| uses: peter-evans/create-pull-request@v6 | |
| with: | |
| commit-message: New sensor data for ${{ env.camera }} - ${{ env.vendor }} | |
| labels: submission | |
| branch: ${{ env.branch_name }} | |
| title: ${{ github.event.issue.title }} | |
| body: | | |
| This pull request adds new sensor data for the camera ${{ env.camera }} by ${{ env.vendor }} | |
| Closes #${{ github.event.issue.number }} | |
| ${{ github.event.issue.body }} | |
| - name: Comment on Issue if all succeeded | |
| if: ${{ success() }} | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: ${{ github.event.issue.number }}, | |
| body: "Submission successful! A pull request has been created with your submitted data." | |
| }); | |
| - name: Comment on Issue if Python scripts fail | |
| if: ${{ failure() }} | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const stepOutputs = { | |
| python: `${{ steps.python.outputs.error || 'No specific error message available' }}`, | |
| csv: `${{ steps.csv.outputs.error || 'No specific error message available' }}`, | |
| yaml: `${{ steps.yaml.outputs.error || 'No specific error message available' }}`, | |
| markdown: `${{ steps.markdown.outputs.error || 'No specific error message available' }}` | |
| }; | |
| const failedSteps = []; | |
| if ("${{ steps.python.outcome }}" == "failure") { | |
| failedSteps.push(`Error in update_sensors_and_generate_json.py:\n\`\`\`\n${stepOutputs.python}\n\`\`\``); | |
| } | |
| if ("${{ steps.csv.outcome }}" == "failure") { | |
| failedSteps.push(`Error in generate_csv.py:\n\`\`\`\n${stepOutputs.csv}\n\`\`\``); | |
| } | |
| if ("${{ steps.yaml.outcome }}" == "failure") { | |
| failedSteps.push(`Error in generate_yaml.py:\n\`\`\`\n${stepOutputs.yaml}\n\`\`\``); | |
| } | |
| if ("${{ steps.markdown.outcome }}" == "failure") { | |
| failedSteps.push(`Error in generate_markdown.py:\n\`\`\`\n${stepOutputs.markdown}\n\`\`\``); | |
| } | |
| if (failedSteps.length === 0) { | |
| failedSteps.push("An error occurred but specific details could not be determined."); | |
| } | |
| github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: ${{ github.event.issue.number }}, | |
| body: 'There was an error processing the sensor data:\n\n' + failedSteps.join("\n\n") + '\n\n Please check your submitted data.\nIf everything looks good, an Admin will take a look as soon as possible.' | |
| }); |