yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f25e5a89f
master
1#!/usr/bin/env bash 2 3set -euo pipefail 4 5# Enable debug mode if DEBUG env var is set 6DEBUG =" ${ DEBUG :-false} " 7 8debug_log () { 9if [[" $ DEBUG " =="true" ]];then 10echo "[DEBUG] $ *" >&2 11fi 12} 13 14# Check if running in GitHub Actions 15if [[ -z" ${ GITHUB_ACTIONS :-} " ]];then 16echo "This script is designed to run in GitHub Actions" 17exit 0 18fi 19 20# Check for required tools 21if !command -v gh &>/dev/null;then 22echo "Error: GitHub CLI (gh) is not installed" 23exit 1 24fi 25 26# Verify GitHub authentication 27if !gh auth status &>/dev/null;then 28echo "Error: Not authenticated with GitHub CLI" 29exit 1 30fi 31 32# Function to check if module ir version constants were modified 33check_module_versions_modified () { 34 localbase_ref =" $ 1 " 35 36# Check if slang-ir.h was modified and if the version constants were changed 37if git diff--name-only " $ base_ref ...HEAD" | grep -q "^source/slang/slang-ir\.h $ " ;then 38# Check if either version constant was modified 39if git diff" $ base_ref ...HEAD" -- source/slang/slang-ir.h| grep -E "^\+.*k_(min|max)SupportedModuleVersion\s*=" ;then 40debug_log "Module version constants were modified" 41return 0 42fi 43fi 44 45debug_log "Module version constants were not modified" 46return 1 47} 48 49# Function to check if serialization version was modified 50check_serialization_version_modified () { 51 localbase_ref =" $ 1 " 52 53# Check if the serialization version constant was modified 54if git diff" $ base_ref ...HEAD" -- source/slang/slang-serialize-ir.cpp| grep -E "^\+.*kSupportedSerializationVersion\s*=" ;then 55debug_log "Serialization version constant was modified" 56return 0 57fi 58 59debug_log "Serialization version constant was not modified" 60return 1 61} 62 63# Get PR number if this is a pull request 64PR_NUMBER ="" 65if [[" $ GITHUB_EVENT_NAME " =="pull_request" ]];then 66PR_NUMBER =" ${ GITHUB_EVENT_PULL_REQUEST_NUMBER :-${ GITHUB_PULL_REQUEST_NUMBER :-}} " 67if [[ -z" $ PR_NUMBER " ]]&& [[ -f" ${ GITHUB_EVENT_PATH :-} " ]];then 68PR_NUMBER =$( jq -r '.pull_request.number // empty' " $ GITHUB_EVENT_PATH " 2 > /dev/null || echo "" ) 69fi 70fi 71 72debug_log "Event name: $ GITHUB_EVENT_NAME " 73debug_log "PR number: ${ PR_NUMBER :-<none>} " 74 75# Get the base ref for comparison 76if [[" $ GITHUB_EVENT_NAME " =="pull_request" ]];then 77BASE_REF ="origin/ ${ GITHUB_BASE_REF } " 78debug_log "Fetching base ref: $ GITHUB_BASE_REF " 79if !git fetch origin" $ GITHUB_BASE_REF " --depth=1 ;then 80echo "Warning: Failed to fetch base ref, trying without depth limit" 81git fetch origin" $ GITHUB_BASE_REF " 82fi 83else 84BASE_REF ="HEAD^1" 85fi 86 87debug_log "Base ref for comparison: $ BASE_REF " 88 89# Get list of changed files 90CHANGED_FILES =$( git diff --name-only " $ BASE_REF ...HEAD" || echo "" ) 91debug_log "Changed files:" 92debug_log " $ CHANGED_FILES " 93 94# Check for changes in IR instruction files 95INST_FILES_CHANGED =false 96if echo " $ CHANGED_FILES " | grep -E "^source/slang/slang-ir-insts(-stable-names)?\.lua $ " ;then 97INST_FILES_CHANGED =true 98debug_log "IR instruction files have changed" 99fi 100 101# Check for changes in serialization file 102SERIALIZE_CHANGED =false 103if echo " $ CHANGED_FILES " | grep -q "^source/slang/slang-serialize-ir\.cpp $ " ;then 104SERIALIZE_CHANGED =true 105debug_log "Serialization file has changed" 106fi 107 108# Initialize comment body 109COMMENT_BODY ="" 110NEEDS_COMMENT =false 111 112# Check if we need to add warnings 113if [[" $ INST_FILES_CHANGED " =="true" ]];then 114# Check if the version constants have already been updated 115if check_module_versions_modified " $ BASE_REF " ;then 116echo "::notice::IR instruction files changed but module version constants were already updated" 117else 118NEEDS_COMMENT =true 119if [[ -n" $ COMMENT_BODY " ]];then 120COMMENT_BODY =" ${ COMMENT_BODY } 121 122" 123fi 124COMMENT_BODY =" ${ COMMENT_BODY } ⚠️ **IR Instruction Files Changed** 125 126This PR modifies IR instruction definition files. Please review if you need to update the following constants in \`source/slang/slang-ir.h\`: 127 128- \`k_minSupportedModuleVersion\`: Should be incremented if you're removing instructions or making breaking changes 129- \`k_maxSupportedModuleVersion\`: Should be incremented when adding new instructions 130 131These version numbers help ensure compatibility between different versions of compiled modules." 132 133echo "::warning::IR instruction files changed - please check if module version constants need updating" 134fi 135fi 136 137if [[" $ SERIALIZE_CHANGED " =="true" ]];then 138# Check if the serialization version has already been updated 139if check_serialization_version_modified " $ BASE_REF " ;then 140echo "::notice::Serialization code changed but serialization version was already updated" 141else 142NEEDS_COMMENT =true 143if [[ -n" $ COMMENT_BODY " ]];then 144COMMENT_BODY =" ${ COMMENT_BODY } 145 146" 147fi 148COMMENT_BODY =" ${ COMMENT_BODY } ⚠️ **Serialization Code Changed** 149 150This PR modifies \`source/slang/slang-serialize-ir.cpp\`. Please review if you need to update: 151 152- \`kSupportedSerializationVersion\`: Should be incremented if you're making backwards-incompatible changes to the serialization format 153 154This version number helps maintain compatibility when loading serialized IR modules." 155 156echo "::warning::Serialization code changed - please check if serialization version needs updating" 157fi 158fi 159 160# Create artifact directory only if we need to comment 161if [[" $ NEEDS_COMMENT " =="true" ]]&& [[ -n" $ PR_NUMBER " ]];then 162ARTIFACT_DIR =" ${ ARTIFACT_DIR :- ir -version-check-artifact} " 163debug_log "Creating artifact directory: $ ARTIFACT_DIR " 164mkdir -p " $ ARTIFACT_DIR " 165 166# Write artifact files 167echo " $ PR_NUMBER " > " $ ARTIFACT_DIR /pr-number.txt" 168 169# Write comment body with marker 170 { 171echo "<!-- slang-ir-version-check -->" 172echo " $ COMMENT_BODY " 173 }> " $ ARTIFACT_DIR /comment-body.txt" 174 175debug_log "Artifact files created:" 176debug_log " pr-number: $ PR_NUMBER " 177debug_log " comment-body: $( wc -l < " $ ARTIFACT_DIR /comment-body.txt" ) lines" 178 179# Set output to indicate artifact was created 180if [[ -n" ${ GITHUB_OUTPUT :-} " ]];then 181echo "artifact_created=true" >> " $ GITHUB_OUTPUT " 182else 183echo "::set-output name=artifact_created::true" 184fi 185else 186debug_log "No artifact needed (needs_comment= $ NEEDS_COMMENT , pr_number= ${ PR_NUMBER :-<empty>} )" 187 188# Set output to indicate no artifact was created 189if [[ -n" ${ GITHUB_OUTPUT :-} " ]];then 190echo "artifact_created=false" >> " $ GITHUB_OUTPUT " 191else 192echo "::set-output name=artifact_created::false" 193fi 194fi 195 196debug_log "Script completed successfully" 197exit 0