|
| 1 | +name: Publish SU2 Validation Test Cases Results |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + branch_name: |
| 7 | + description: "SU2 Branch Checked Out (e.g. master, develop)" |
| 8 | + required: true |
| 9 | + type: choice |
| 10 | + options: |
| 11 | + - master |
| 12 | + - develop |
| 13 | + case_code: |
| 14 | + description: "Validation Case Code (e.g. 2DML)" |
| 15 | + required: true |
| 16 | + type: choice |
| 17 | + options: |
| 18 | + - 2DML |
| 19 | + - All |
| 20 | + case_name: |
| 21 | + description: "Validation Case Name (e.g. 2D Mixing Layer)" |
| 22 | + required: true |
| 23 | + type: choice |
| 24 | + options: |
| 25 | + - 2D Mixing Layer |
| 26 | + - All |
| 27 | + flow_condition: |
| 28 | + description: "Incompressible Flow or Compressible Flow" |
| 29 | + required: true |
| 30 | + type: choice |
| 31 | + options: |
| 32 | + - Incompressible Flow |
| 33 | + - Compressible Flow |
| 34 | + - All |
| 35 | + author_name: |
| 36 | + description: "Author's Name (e.g. Harsh)" |
| 37 | + required: true |
| 38 | + type: string |
| 39 | + |
| 40 | +env: |
| 41 | + SANITIZED_AUTHOR: "Automated_Update" |
| 42 | + |
| 43 | +jobs: |
| 44 | + process-and-publish: |
| 45 | + runs-on: ubuntu-latest |
| 46 | + steps: |
| 47 | + - name: Validate Inputs |
| 48 | + run: | |
| 49 | + echo "Validating workflow inputs..." |
| 50 | +
|
| 51 | + CASE_CODE="${{ github.event.inputs.case_code }}" |
| 52 | + CASE_NAME="${{ github.event.inputs.case_name }}" |
| 53 | + FLOW_CONDITION="${{ github.event.inputs.flow_condition }}" |
| 54 | +
|
| 55 | + ERRORS="" |
| 56 | +
|
| 57 | + if [[ "$CASE_CODE" == "All" && "$CASE_NAME" != "All" ]]; then |
| 58 | + ERRORS+="\n'All' case code cannot be paired with a specific case name ($CASE_NAME)" |
| 59 | + fi |
| 60 | +
|
| 61 | + if [[ "$CASE_CODE" != "All" && "$CASE_NAME" == "All" ]]; then |
| 62 | + ERRORS+="\nSpecific case code ($CASE_CODE) cannot be paired with 'All' case name" |
| 63 | + fi |
| 64 | +
|
| 65 | + if [[ "$CASE_CODE" != "All" && "$FLOW_CONDITION" == "All" ]]; then |
| 66 | + ERRORS+="\nSpecific case code ($CASE_CODE) cannot be paired with 'All' flow condition" |
| 67 | + fi |
| 68 | +
|
| 69 | + if [[ "$CASE_CODE" == "All" && "$FLOW_CONDITION" != "All" ]]; then |
| 70 | + ERRORS+="\n'All' case code must also have 'All' flow condition" |
| 71 | + fi |
| 72 | +
|
| 73 | + if [[ -n "$ERRORS" ]]; then |
| 74 | + echo "::error::Input Validation Failed:$ERRORS" |
| 75 | + echo "Tip: Use either all 'All' values or all specific values for a single run." |
| 76 | + exit 1 |
| 77 | + fi |
| 78 | +
|
| 79 | + echo "Inputs are valid. Continuing..." |
| 80 | +
|
| 81 | + - name: Sanitize Author's Name |
| 82 | + run: | |
| 83 | + SANITIZED=$(echo "${{ github.event.inputs.author_name }}" | |
| 84 | + tr -d '\n' | # Remove newlines |
| 85 | + tr ' ' '_' | # Convert spaces |
| 86 | + tr -s '_' | # Collapse multiple ____ |
| 87 | + sed 's/^_\+//; s/_\+$//' | # Trim leading/trailing _ |
| 88 | + tr -dc '[:alnum:]_' | # Strict character set |
| 89 | + head -c 50) |
| 90 | +
|
| 91 | + # Fallback Conditions |
| 92 | + if [[ -z "$SANITIZED" || "$SANITIZED" =~ ^[0-9_]+$ ]]; then |
| 93 | + SANITIZED="Automated_Update" |
| 94 | + fi |
| 95 | + echo "SANITIZED_AUTHOR=${SANITIZED}" >> $GITHUB_ENV |
| 96 | +
|
| 97 | + - name: Checkout Develop Branch |
| 98 | + uses: actions/checkout@v4 |
| 99 | + with: |
| 100 | + ref: develop |
| 101 | + |
| 102 | + - name: Check If Target Branch Exists |
| 103 | + id: branch-check |
| 104 | + env: |
| 105 | + TARGET_BRANCH: "ValidationCases_${{ github.event.inputs.branch_name}}_${{ env.SANITIZED_AUTHOR }}" |
| 106 | + run: | |
| 107 | + if git ls-remote --heads origin $TARGET_BRANCH | grep -q $TARGET_BRANCH; then |
| 108 | + echo "Branch $TARGET_BRANCH exists. Proceeding..." |
| 109 | + echo "branch_exists=true" >> $GITHUB_OUTPUT |
| 110 | + else |
| 111 | + echo "::error::Branch $TARGET_BRANCH does not exist. Aborting." |
| 112 | + echo "branch_exists=false" >> $GITHUB_OUTPUT |
| 113 | + exit 1 |
| 114 | + fi |
| 115 | +
|
| 116 | + - name: Checkout Target Branch |
| 117 | + if: steps.branch-check.outputs.branch_exists == 'true' |
| 118 | + uses: actions/checkout@v4 |
| 119 | + with: |
| 120 | + ref: "ValidationCases_${{ github.event.inputs.branch_name}}_${{ env.SANITIZED_AUTHOR }}" |
| 121 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 122 | + persist-credentials: true |
| 123 | + fetch-depth: 0 |
| 124 | + |
| 125 | + - name: Prepare Markdown File For All Validation Cases |
| 126 | + if: steps.branch-check.outputs.branch_exists == 'true' && inputs.case_code == 'All' && inputs.case_name == 'All' |
| 127 | + run: | |
| 128 | + BASE_PATH="vandv_files" |
| 129 | + TEMPLATE="template_README.md" |
| 130 | + OUTPUT_DIR="_vandv" |
| 131 | + OUTPUT_FILE="${OUTPUT_DIR}/All_Validation_Cases.md" |
| 132 | +
|
| 133 | + for case_dir in "$BASE_PATH"/*/; do |
| 134 | + if [ -d "$case_dir" ] && [[ "$(basename "$case_dir")" != .* ]]; then |
| 135 | + casecode=$(basename "$case_dir") |
| 136 | + IMAGE_COUNT=0 |
| 137 | + IMAGE_DIR="vandv_files/${casecode}" |
| 138 | +
|
| 139 | + # Validate inputs and paths |
| 140 | + if [ ! -f "${TEMPLATE}" ]; then |
| 141 | + echo "::error::Template ${TEMPLATE} not found!" |
| 142 | + exit 1 |
| 143 | + fi |
| 144 | +
|
| 145 | + if [ ! -d "${OUTPUT_DIR}" ]; then |
| 146 | + echo "::error::Directory ${OUTPUT_DIR} must exist in the repository. Deploy it first." |
| 147 | + exit 1 |
| 148 | + fi |
| 149 | +
|
| 150 | + if [ ! -d "${IMAGE_DIR}" ]; then |
| 151 | + echo "::error::Image directory ${IMAGE_DIR} not found!" |
| 152 | + exit 1 |
| 153 | + fi |
| 154 | +
|
| 155 | + if ! grep -q '{Case_Code}' "${TEMPLATE}" || ! grep -q 'Your Case Study Title' "${TEMPLATE}"; then |
| 156 | + echo "::error::Template missing required placeholders" |
| 157 | + exit 1 |
| 158 | + fi |
| 159 | +
|
| 160 | + # Update front matter and write to new file |
| 161 | + sed \ |
| 162 | + -e "s/{Case_Code}/All_Validation_Cases/g" \ |
| 163 | + -e "s/Your Case Study Title/All Validation Cases/g" \ |
| 164 | + "${TEMPLATE}" > "${OUTPUT_FILE}" |
| 165 | +
|
| 166 | + # Count images first |
| 167 | + IMAGE_COUNT=$(find "${IMAGE_DIR}" -type f \( -iname "*.png" -o -iname "*.jpg" -o -iname "*.jpeg" \) | wc -l) |
| 168 | +
|
| 169 | + if [ "${IMAGE_COUNT}" -eq 0 ]; then |
| 170 | + echo "::error::ABORTING: No plot images found in ${IMAGE_DIR}/" |
| 171 | + rm -f "${OUTPUT_FILE}" # Delete the empty Markdown file |
| 172 | + exit 1 |
| 173 | + fi |
| 174 | +
|
| 175 | + echo -e "\n## Results Plots For ${casecode}\n" >> "${OUTPUT_FILE}" |
| 176 | +
|
| 177 | + # Find and process images |
| 178 | + find "${IMAGE_DIR}" -type d -name "${casecode}_*" | sort | while read -r dir; do |
| 179 | + folder_name=$(basename "${dir}") |
| 180 | + echo -e "\n### ${folder_name}\n" >> "${OUTPUT_FILE}" |
| 181 | + |
| 182 | + # Process images with their relative path |
| 183 | + find "${dir}" -type f \( -iname "*.png" -o -iname "*.jpg" -o -iname "*.jpeg" \) | sort | while read -r img; do |
| 184 | + # Calculate relative path |
| 185 | + rel_path="../${img#*/vandv_files/}" |
| 186 | + echo "<img src=\"${rel_path}\" alt=\"${folder_name} - $(basename "${img}")\" style=\"width:80%; display: block; margin: 0 auto;\">" >> "${OUTPUT_FILE}" |
| 187 | + echo "" >> "${OUTPUT_FILE}" |
| 188 | + done |
| 189 | + done |
| 190 | + fi |
| 191 | + done |
| 192 | + # Verify creation |
| 193 | + echo "Generated ${OUTPUT_FILE}" |
| 194 | +
|
| 195 | + - name: Prepare Markdown File For Specific Validation Case |
| 196 | + if: steps.branch-check.outputs.branch_exists == 'true' && inputs.case_code != 'All' && inputs.case_name != 'All' |
| 197 | + run: | |
| 198 | + # Initialize variables |
| 199 | + IMAGE_COUNT=0 |
| 200 | + SANITIZED_CASE_NAME=$(echo "${{ github.event.inputs.case_name }}" | tr -dc '[:alnum:] ') |
| 201 | + SANITIZED_CASE_CODE=$(echo "${{ github.event.inputs.case_code }}" | tr -dc '[:alnum:]' | tr '[:lower:]' '[:upper:]') |
| 202 | +
|
| 203 | + # Define paths |
| 204 | + TEMPLATE="template_README.md" |
| 205 | + OUTPUT_DIR="_vandv" |
| 206 | + OUTPUT_FILE="${OUTPUT_DIR}/${SANITIZED_CASE_CODE}.md" |
| 207 | + IMAGE_DIR="vandv_files/${SANITIZED_CASE_CODE}" |
| 208 | +
|
| 209 | + # Validate inputs and paths |
| 210 | + if [ ! -f "${TEMPLATE}" ]; then |
| 211 | + echo "::error::Template ${TEMPLATE} not found!" |
| 212 | + exit 1 |
| 213 | + fi |
| 214 | +
|
| 215 | + if [ ! -d "${OUTPUT_DIR}" ]; then |
| 216 | + echo "::error::Directory ${OUTPUT_DIR} must exist in the repository. Deploy it first." |
| 217 | + exit 1 |
| 218 | + fi |
| 219 | +
|
| 220 | + if [ ! -d "${IMAGE_DIR}" ]; then |
| 221 | + echo "::error::Image directory ${IMAGE_DIR} not found!" |
| 222 | + exit 1 |
| 223 | + fi |
| 224 | +
|
| 225 | + if ! grep -q '{Case_Code}' "${TEMPLATE}" || ! grep -q 'Your Case Study Title' "${TEMPLATE}"; then |
| 226 | + echo "::error::Template missing required placeholders" |
| 227 | + exit 1 |
| 228 | + fi |
| 229 | +
|
| 230 | + # Update front matter and write to new file |
| 231 | + sed \ |
| 232 | + -e "s/{Case_Code}/${SANITIZED_CASE_CODE}/g" \ |
| 233 | + -e "s/Your Case Study Title/${SANITIZED_CASE_NAME}/g" \ |
| 234 | + "${TEMPLATE}" > "${OUTPUT_FILE}" |
| 235 | +
|
| 236 | + # Count images first |
| 237 | + IMAGE_COUNT=$(find "${IMAGE_DIR}" -type f \( -iname "*.png" -o -iname "*.jpg" -o -iname "*.jpeg" \) | wc -l) |
| 238 | +
|
| 239 | + if [ "${IMAGE_COUNT}" -eq 0 ]; then |
| 240 | + echo "::error::ABORTING: No plot images found in ${IMAGE_DIR}/" |
| 241 | + rm -f "${OUTPUT_FILE}" # Delete the empty Markdown file |
| 242 | + exit 1 |
| 243 | + fi |
| 244 | +
|
| 245 | + echo -e "\n## Results Plots\n" >> "${OUTPUT_FILE}" |
| 246 | +
|
| 247 | + # Find and process images |
| 248 | + find "${IMAGE_DIR}" -type d -name "${SANITIZED_CASE_CODE}_*" | sort | while read -r dir; do |
| 249 | + folder_name=$(basename "${dir}") |
| 250 | + echo -e "\n### ${folder_name}\n" >> "${OUTPUT_FILE}" |
| 251 | +
|
| 252 | + # Process images with their relative path |
| 253 | + find "${dir}" -type f \( -iname "*.png" -o -iname "*.jpg" -o -iname "*.jpeg" \) | sort | while read -r img; do |
| 254 | + # Calculate relative path |
| 255 | + rel_path="../${img#*/vandv_files/}" |
| 256 | + echo "<img src=\"${rel_path}\" alt=\"${folder_name} - $(basename "${img}")\" style=\"width:80%; display: block; margin: 0 auto;\">" >> "${OUTPUT_FILE}" |
| 257 | + echo "" >> "${OUTPUT_FILE}" |
| 258 | + done |
| 259 | + done |
| 260 | +
|
| 261 | + # Verify creation |
| 262 | + echo "Generated ${OUTPUT_FILE}" |
| 263 | +
|
| 264 | + - name: Install yq (Go version) |
| 265 | + run: | |
| 266 | + sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 |
| 267 | + sudo chmod +x /usr/local/bin/yq |
| 268 | + yq --version |
| 269 | +
|
| 270 | + - name: Update V&V Listing |
| 271 | + if: steps.branch-check.outputs.branch_exists == 'true' |
| 272 | + run: | |
| 273 | + # Verify yq installation |
| 274 | + if ! command -v yq &>/dev/null; then |
| 275 | + echo "::error::yq not installed" |
| 276 | + exit 1 |
| 277 | + fi |
| 278 | +
|
| 279 | + VANDV_YML="_data/vandv.yml" |
| 280 | +
|
| 281 | + # Verify file exists |
| 282 | + if [ ! -f "${VANDV_YML}" ]; then |
| 283 | + echo "::error::YAML file ${VANDV_YML} not found" |
| 284 | + exit 1 |
| 285 | + fi |
| 286 | +
|
| 287 | + # Create backup |
| 288 | + cp "${VANDV_YML}" "${VANDV_YML}.bak" |
| 289 | +
|
| 290 | + if [ "${{ github.event.inputs.flow_condition }}" == "All" ]; then |
| 291 | + NEW_SECTION_TITLE="All Validation Cases" |
| 292 | + NEW_ENTRY="All_Validation_Cases" |
| 293 | +
|
| 294 | + # Check if section exists |
| 295 | + SECTION_EXISTS=$(yq eval ".[] | select(.title == \"${NEW_SECTION_TITLE}\") | length" "${VANDV_YML}") |
| 296 | + |
| 297 | + if [ "${SECTION_EXISTS}" -gt 0 ]; then |
| 298 | + echo "Section '${NEW_SECTION_TITLE}' already exists. No changes made." |
| 299 | + else |
| 300 | + echo "Adding new '${NEW_SECTION_TITLE}' section..." |
| 301 | + |
| 302 | + # Create new section in a temporary file |
| 303 | + TEMP_FILE=$(mktemp) |
| 304 | + trap 'rm -f "${TEMP_FILE}" "${VANDV_YML}.tmp"' EXIT |
| 305 | + echo "- title: ${NEW_SECTION_TITLE}" > "${TEMP_FILE}" |
| 306 | + echo " vandv:" >> "${TEMP_FILE}" |
| 307 | + echo " - ${NEW_ENTRY}" >> "${TEMP_FILE}" |
| 308 | +
|
| 309 | + # Merge with existing content |
| 310 | + yq eval-all 'select(fileIndex == 0) *+ select(fileIndex == 1)' "${VANDV_YML}" "${TEMP_FILE}" > "${VANDV_YML}.tmp" |
| 311 | + |
| 312 | + # Verify merge was successful |
| 313 | + MERGED_COUNT=$(yq eval 'length' "${VANDV_YML}.tmp") |
| 314 | + ORIGINAL_COUNT=$(yq eval 'length' "${VANDV_YML}") |
| 315 | + |
| 316 | + if [ "${MERGED_COUNT}" -le "${ORIGINAL_COUNT}" ]; then |
| 317 | + echo "::error::Failed to properly merge new section" |
| 318 | + rm -f "${TEMP_FILE}" "${VANDV_YML}.tmp" |
| 319 | + mv "${VANDV_YML}.bak" "${VANDV_YML}" |
| 320 | + exit 1 |
| 321 | + fi |
| 322 | + |
| 323 | + # Verify new section exists in merged file |
| 324 | + if [ $(yq eval ".[] | select(.title == \"${NEW_SECTION_TITLE}\") | length" "${VANDV_YML}.tmp") -eq 0 ]; then |
| 325 | + echo "::error::New section not found in merged file" |
| 326 | + rm -f "${TEMP_FILE}" "${VANDV_YML}.tmp" |
| 327 | + mv "${VANDV_YML}.bak" "${VANDV_YML}" |
| 328 | + exit 1 |
| 329 | + fi |
| 330 | + |
| 331 | + # Replace original file if all checks pass |
| 332 | + mv "${VANDV_YML}.tmp" "${VANDV_YML}" |
| 333 | + echo "Successfully added new section while preserving existing content" |
| 334 | + rm -f "${TEMP_FILE}" |
| 335 | + fi |
| 336 | + else |
| 337 | + CASE_CODE="${{ github.event.inputs.case_code }}" |
| 338 | + FLOW_TYPE="${{ github.event.inputs.flow_condition }}" |
| 339 | +
|
| 340 | + # Check if case exists |
| 341 | + EXISTS=$(yq eval ".[] | select(.title == \"${FLOW_TYPE}\").vandv[] | select(. == \"${CASE_CODE}\")" "${VANDV_YML}") |
| 342 | + if [ -n "${EXISTS}" ]; then |
| 343 | + echo "Case ${CASE_CODE} already exists. Skipping update." |
| 344 | + rm -f "${VANDV_YML}.bak" |
| 345 | + exit 0 |
| 346 | + fi |
| 347 | +
|
| 348 | + # Update YAML |
| 349 | + yq eval -i ".[] |= (select(.title == \"${FLOW_TYPE}\").vandv += [\"${CASE_CODE}\"])" "${VANDV_YML}" |
| 350 | +
|
| 351 | + # Verify update |
| 352 | + UPDATED=$(yq eval ".[] | select(.title == \"${FLOW_TYPE}\").vandv[] | select(. == \"${CASE_CODE}\")" "${VANDV_YML}") |
| 353 | + if [ -z "${UPDATED}" ]; then |
| 354 | + echo "::error::Failed to add case code to YAML" |
| 355 | + mv "${VANDV_YML}.bak" "${VANDV_YML}" |
| 356 | + exit 1 |
| 357 | + fi |
| 358 | + fi |
| 359 | +
|
| 360 | + echo "Successful update to vandv.yml" |
| 361 | + rm -f "${VANDV_YML}.bak" |
| 362 | +
|
| 363 | + - name: Commit And Push Changes |
| 364 | + if: steps.branch-check.outputs.branch_exists == 'true' |
| 365 | + run: | |
| 366 | + git config --global user.name "GitHub Actions" |
| 367 | + git config --global user.email "[email protected]" |
| 368 | +
|
| 369 | + git add . |
| 370 | + git status |
| 371 | +
|
| 372 | + if ! git diff-index --quiet HEAD --; then |
| 373 | + git commit -m "Automated Update" |
| 374 | + git push origin HEAD:"ValidationCases_${{ github.event.inputs.branch_name}}_${{ env.SANITIZED_AUTHOR }}" |
| 375 | + else |
| 376 | + echo "No changes to commit" |
| 377 | + fi |
0 commit comments