[Manual Test] Actor_Creation by svelderrainruiz #4
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: Manual Test Processing | |
on: | |
issues: | |
types: [opened, edited, labeled] | |
jobs: | |
process-manual-test: | |
runs-on: ubuntu-latest | |
# Only proceed if the issue is labeled 'manual-test' | |
if: contains(toJson(github.event.issue.labels), 'manual-test') | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v3 | |
- name: Parse issue form data | |
id: parse | |
uses: issue-ops/[email protected] | |
with: | |
body: ${{ github.event.issue.body }} | |
# ------------------------ | |
# Example Output Step | |
# ------------------------ | |
- name: Show parsed data | |
id: show_parsed | |
run: | | |
echo "User Name: ${{ steps.parse.outputs.json.user_name }}" | |
echo "Test ID: ${{ steps.parse.outputs.json.test_id }}" | |
echo "LabVIEW Version: ${{ steps.parse.outputs.json.labview_version }}" | |
echo "LabVIEW Bitness: ${{ steps.parse.outputs.json.labview_bitness }}" | |
echo "Operating System: ${{ steps.parse.outputs.json.os_used }}" | |
echo "Test Result: ${{ steps.parse.outputs.json.test_result }}" | |
echo "Notes: ${{ steps.parse.outputs.json.notes }}" | |
- name: Add to Project | |
uses: actions/[email protected] | |
with: | |
# e.g.: "https://github.com/orgs/<ORG_OR_USER>/projects/<PROJECT_NUMBER>" | |
project-url: ${{ secrets.PROJECT_URL }} | |
github-token: ${{ secrets.PROJECT_PAT }} | |
# If the item already exists in the project, it won't be duplicated | |
- name: Update Project Fields | |
uses: leonsteinhaeuser/[email protected] | |
with: | |
gh_token: ${{ secrets.PROJECT_PAT }} | |
organization: <ORG_OR_USER> | |
project_id: <PROJECT_NUMBER> | |
resource_node_id: ${{ github.event.issue.node_id }} | |
operation_mode: custom_field | |
custom_field_values: ${{ steps.build_project_fields.outputs.fields }} | |
# Make sure your Project field names match the "name" properties above | |
# ------------------------ | |
# Step 2: Archive to docs/test_reports.json | |
# ------------------------ | |
- name: Update JSON archive | |
uses: actions/github-script@v6 | |
env: | |
FORM_DATA: ${{ steps.parse.outputs.json }} | |
with: | |
script: | | |
const owner = context.repo.owner; | |
const repo = context.repo.repo; | |
const path = "docs/test_reports.json"; | |
// Try to fetch existing file | |
let existingData = []; | |
let sha; | |
try { | |
const res = await github.rest.repos.getContent({ owner, repo, path }); | |
sha = res.data.sha; | |
const decoded = Buffer.from(res.data.content, 'base64').toString(); | |
existingData = JSON.parse(decoded); | |
} catch (error) { | |
if (error.status !== 404) { | |
throw error; | |
} | |
} | |
const form = JSON.parse(process.env.FORM_DATA); | |
const issueNumber = context.payload.issue.number; | |
// Remove any existing record for this issueNumber | |
existingData = existingData.filter(r => r.issue_number !== issueNumber); | |
// Build a fresh record | |
const newRecord = { | |
issue_number: issueNumber, | |
user_name: form.user_name, | |
test_id: form.test_id, | |
labview_version: form.labview_version, | |
labview_bitness: form.labview_bitness, | |
os_used: form.os_used, | |
test_result: form.test_result, | |
notes: form.notes || '', | |
created_at: context.payload.issue.created_at, | |
}; | |
existingData.push(newRecord); | |
existingData.sort((a, b) => a.issue_number - b.issue_number); | |
const newContent = JSON.stringify(existingData, null, 2); | |
const encoded = Buffer.from(newContent).toString('base64'); | |
await github.rest.repos.createOrUpdateFileContents({ | |
owner, | |
repo, | |
path, | |
message: `Update test_reports.json for issue #${issueNumber}`, | |
content: encoded, | |
sha: sha || undefined, | |
}); |