yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Ellie HermaszewskaAdd CI to check ir module versioning (#7821)f25e5a89f

master
6.3 KiB197 linesraw
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() {
9  if [[ "$DEBUG" == "true" ]]; then
10    echo "[DEBUG] $*" >&2
11  fi
12}
13
14# Check if running in GitHub Actions
15if [[ -z "${GITHUB_ACTIONS:-}" ]]; then
16  echo "This script is designed to run in GitHub Actions"
17  exit 0
18fi
19
20# Check for required tools
21if ! command -v gh &>/dev/null; then
22  echo "Error: GitHub CLI (gh) is not installed"
23  exit 1
24fi
25
26# Verify GitHub authentication
27if ! gh auth status &>/dev/null; then
28  echo "Error: Not authenticated with GitHub CLI"
29  exit 1
30fi
31
32# Function to check if module ir version constants were modified
33check_module_versions_modified() {
34  local base_ref="$1"
35
36  # Check if slang-ir.h was modified and if the version constants were changed
37  if git diff --name-only "$base_ref...HEAD" | grep -q "^source/slang/slang-ir\.h$"; then
38    # Check if either version constant was modified
39    if git diff "$base_ref...HEAD" -- source/slang/slang-ir.h | grep -E "^\+.*k_(min|max)SupportedModuleVersion\s*="; then
40      debug_log "Module version constants were modified"
41      return 0
42    fi
43  fi
44
45  debug_log "Module version constants were not modified"
46  return 1
47}
48
49# Function to check if serialization version was modified
50check_serialization_version_modified() {
51  local base_ref="$1"
52
53  # Check if the serialization version constant was modified
54  if git diff "$base_ref...HEAD" -- source/slang/slang-serialize-ir.cpp | grep -E "^\+.*kSupportedSerializationVersion\s*="; then
55    debug_log "Serialization version constant was modified"
56    return 0
57  fi
58
59  debug_log "Serialization version constant was not modified"
60  return 1
61}
62
63# Get PR number if this is a pull request
64PR_NUMBER=""
65if [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
66  PR_NUMBER="${GITHUB_EVENT_PULL_REQUEST_NUMBER:-${GITHUB_PULL_REQUEST_NUMBER:-}}"
67  if [[ -z "$PR_NUMBER" ]] && [[ -f "${GITHUB_EVENT_PATH:-}" ]]; then
68    PR_NUMBER=$(jq -r '.pull_request.number // empty' "$GITHUB_EVENT_PATH" 2>/dev/null || echo "")
69  fi
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
77  BASE_REF="origin/${GITHUB_BASE_REF}"
78  debug_log "Fetching base ref: $GITHUB_BASE_REF"
79  if ! git fetch origin "$GITHUB_BASE_REF" --depth=1; then
80    echo "Warning: Failed to fetch base ref, trying without depth limit"
81    git fetch origin "$GITHUB_BASE_REF"
82  fi
83else
84  BASE_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
97  INST_FILES_CHANGED=true
98  debug_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
104  SERIALIZE_CHANGED=true
105  debug_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
115  if check_module_versions_modified "$BASE_REF"; then
116    echo "::notice::IR instruction files changed but module version constants were already updated"
117  else
118    NEEDS_COMMENT=true
119    if [[ -n "$COMMENT_BODY" ]]; then
120      COMMENT_BODY="${COMMENT_BODY}
121
122"
123    fi
124    COMMENT_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
133    echo "::warning::IR instruction files changed - please check if module version constants need updating"
134  fi
135fi
136
137if [[ "$SERIALIZE_CHANGED" == "true" ]]; then
138  # Check if the serialization version has already been updated
139  if check_serialization_version_modified "$BASE_REF"; then
140    echo "::notice::Serialization code changed but serialization version was already updated"
141  else
142    NEEDS_COMMENT=true
143    if [[ -n "$COMMENT_BODY" ]]; then
144      COMMENT_BODY="${COMMENT_BODY}
145
146"
147    fi
148    COMMENT_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
156    echo "::warning::Serialization code changed - please check if serialization version needs updating"
157  fi
158fi
159
160# Create artifact directory only if we need to comment
161if [[ "$NEEDS_COMMENT" == "true" ]] && [[ -n "$PR_NUMBER" ]]; then
162  ARTIFACT_DIR="${ARTIFACT_DIR:-ir-version-check-artifact}"
163  debug_log "Creating artifact directory: $ARTIFACT_DIR"
164  mkdir -p "$ARTIFACT_DIR"
165
166  # Write artifact files
167  echo "$PR_NUMBER" >"$ARTIFACT_DIR/pr-number.txt"
168
169  # Write comment body with marker
170  {
171    echo "<!-- slang-ir-version-check -->"
172    echo "$COMMENT_BODY"
173  } >"$ARTIFACT_DIR/comment-body.txt"
174
175  debug_log "Artifact files created:"
176  debug_log "  pr-number: $PR_NUMBER"
177  debug_log "  comment-body: $(wc -l <"$ARTIFACT_DIR/comment-body.txt") lines"
178
179  # Set output to indicate artifact was created
180  if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
181    echo "artifact_created=true" >>"$GITHUB_OUTPUT"
182  else
183    echo "::set-output name=artifact_created::true"
184  fi
185else
186  debug_log "No artifact needed (needs_comment=$NEEDS_COMMENT, pr_number=${PR_NUMBER:-<empty>})"
187
188  # Set output to indicate no artifact was created
189  if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
190    echo "artifact_created=false" >>"$GITHUB_OUTPUT"
191  else
192    echo "::set-output name=artifact_created::false"
193  fi
194fi
195
196debug_log "Script completed successfully"
197exit 0