CISD [4Fe-4S] #72
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: Submissions workflow | |
| on: | |
| issues: | |
| types: [labeled] | |
| jobs: | |
| process_verified_submission: | |
| runs-on: ubuntu-latest | |
| if: contains(github.event.issue.labels.*.name, 'submission') && github.event.label.name == 'verified' | |
| permissions: | |
| pull-requests: write | |
| contents: write | |
| steps: | |
| - name: Determine path based on labels | |
| id: path_selector | |
| run: | | |
| ISSUE_TEMPLATE_PATH="" | |
| SUBMISSIONS_PATH="" | |
| JSON_LABELS='${{ toJSON(github.event.issue.labels.*.name) }}' | |
| readarray -t LABELS <<< "$(echo "$JSON_LABELS" | jq -r '.[]')" | |
| for LABEL in "${LABELS[@]}"; do | |
| case "$LABEL" in | |
| "path: observable-estimations") | |
| ISSUE_TEMPLATE_PATH="01-submission-path-observable-estimations.yml" | |
| SUBMISSIONS_PATH="data/observable-estimations/submissions.json" | |
| break | |
| ;; | |
| "path: variational-problems") | |
| ISSUE_TEMPLATE_PATH="02-submission-path-variational-problems.yml" | |
| SUBMISSIONS_PATH="data/variational-problems/submissions.json" | |
| break | |
| ;; | |
| "path: classically-verifiable-problems") | |
| ISSUE_TEMPLATE_PATH="03-submission-path-classically-verifiable-problems.yml" | |
| SUBMISSIONS_PATH="data/classically-verifiable-problems/submissions.json" | |
| break | |
| ;; | |
| esac | |
| done | |
| if [ -z "$ISSUE_TEMPLATE_PATH" ]; then | |
| echo "::error::No valid template label was found on the issue." | |
| echo "::error::Processing skipped as the correct form template cannot be determined." | |
| exit 1 | |
| fi | |
| echo "selected_issue_template=$ISSUE_TEMPLATE_PATH" >> $GITHUB_OUTPUT | |
| echo "Selected issue template: $ISSUE_TEMPLATE_PATH" | |
| echo "selected_submissions_path=$SUBMISSIONS_PATH" >> $GITHUB_OUTPUT | |
| echo "Selected submissions path: $SUBMISSIONS_PATH" | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| - name: Parse issue body | |
| id: issue_form_parser | |
| uses: issue-ops/parser@v4 | |
| with: | |
| body: ${{ github.event.issue.body }} | |
| issue-form-template: ${{ steps.path_selector.outputs.selected_issue_template }} | |
| - name: Modify parsed JSON | |
| id: modify_json | |
| env: | |
| INPUT_JSON: ${{ steps.issue_form_parser.outputs.json }} | |
| ISSUE_CREATED_AT: ${{ github.event.issue.created_at }} | |
| ISSUE_URL: ${{ github.event.issue.html_url }} | |
| run: | | |
| SUBMISSION=$(node -e " | |
| const data = JSON.parse(process.env.INPUT_JSON); | |
| if (data.circuit) { | |
| data.circuit = data.circuit[0]; | |
| } | |
| if (data.hamiltonian) { | |
| data.hamiltonian = data.hamiltonian[0]; | |
| } | |
| delete data.methodProof; | |
| const numericFields = [ | |
| 'runtimeQuantum', | |
| 'runtimeClassical', | |
| 'observableValue', | |
| 'errorBoundLow', | |
| 'errorBoundHigh', | |
| 'energy', | |
| 'qubits', | |
| 'gates', | |
| ]; | |
| for (const key of numericFields) { | |
| if (!(key in data)) continue; | |
| const parsedNumber = Number(data[key]); | |
| if (isNaN(parsedNumber)) { | |
| delete data[key]; | |
| } else { | |
| data[key] = parsedNumber; | |
| } | |
| } | |
| const output = { | |
| createdAt: process.env.ISSUE_CREATED_AT, | |
| url: process.env.ISSUE_URL, | |
| ...data, | |
| }; | |
| console.log(JSON.stringify(output)); | |
| ") | |
| echo "submission=$SUBMISSION" >> $GITHUB_OUTPUT | |
| - name: Modify submissions file | |
| env: | |
| SUBMISSIONS_PATH: ${{ steps.path_selector.outputs.selected_submissions_path }} | |
| SUBMISSION: ${{ steps.modify_json.outputs.submission }} | |
| run: | | |
| tmp_file=$(mktemp) | |
| jq ". += [${SUBMISSION}]" "$SUBMISSIONS_PATH" > "$tmp_file" && mv "$tmp_file" "$SUBMISSIONS_PATH" | |
| - name: Create pull request | |
| id: create_pull_request | |
| uses: peter-evans/create-pull-request@v7 | |
| with: | |
| commit-message: 'Add new submission from issue #${{ github.event.issue.number }}' | |
| title: 'Add new submission from issue #${{ github.event.issue.number }}' | |
| body: 'Closes #${{ github.event.issue.number }}.' | |
| branch: submission-issue-${{ github.event.issue.number }} | |
| - name: Enable pull request auto-merge | |
| if: steps.create_pull_request.outputs.pull-request-operation == 'created' | |
| run: gh pr merge --merge --auto "${{ steps.create_pull_request.outputs.pull-request-number }}" | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |