-
Notifications
You must be signed in to change notification settings - Fork 0
225 lines (200 loc) · 9.85 KB
/
integration-examples.yml
File metadata and controls
225 lines (200 loc) · 9.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
name: Integration Examples Test
# Triggers integration tests in wasm-component-examples repo
# to validate that rules changes don't break downstream users.
#
# This is an optional check - it provides early warning but
# won't block merges if the examples repo has its own issues.
#
# BREAKING CHANGE PROTOCOL:
# When introducing breaking changes, create a branch in the examples repo
# with the SAME NAME as your PR branch. The CI will automatically detect
# and test against that matching branch.
#
# Example:
# Your PR branch: feature/new-api
# Create in examples: feature/new-api (with updated examples)
# CI tests: rules:feature/new-api against examples:feature/new-api
on:
pull_request:
branches: [main]
# Only run for significant changes, not docs-only updates
paths:
- '*.bzl'
- 'MODULE.bazel'
- 'rust/**'
- 'go/**'
- 'cpp/**'
- 'js/**'
- 'wasm/**'
- 'wit/**'
- 'toolchains/**'
- 'providers/**'
# Allow manual trigger for testing
workflow_dispatch:
inputs:
examples_repo:
description: 'Examples repository to test against'
required: false
default: 'pulseengine/wasm-component-examples'
type: string
env:
CI: true
# The examples repository to trigger
EXAMPLES_REPO: ${{ github.event.inputs.examples_repo || 'pulseengine/wasm-component-examples' }}
jobs:
trigger-integration:
name: Trigger Integration Tests
runs-on: ubuntu-latest
# This job requires a PAT with repo scope stored as INTEGRATION_TEST_TOKEN
# If the secret is not configured, the job will be skipped gracefully
steps:
- name: Check for integration token
id: check-token
run: |
if [ -z "${{ secrets.INTEGRATION_TEST_TOKEN }}" ]; then
echo "has_token=false" >> $GITHUB_OUTPUT
echo "⚠️ INTEGRATION_TEST_TOKEN not configured - skipping integration tests"
echo "To enable: Add a PAT with repo scope as INTEGRATION_TEST_TOKEN secret"
else
echo "has_token=true" >> $GITHUB_OUTPUT
fi
- name: Trigger examples integration test
if: steps.check-token.outputs.has_token == 'true'
uses: peter-evans/repository-dispatch@v4
with:
token: ${{ secrets.INTEGRATION_TEST_TOKEN }}
repository: ${{ env.EXAMPLES_REPO }}
event-type: test-integration
client-payload: |
{
"ref": "${{ github.head_ref || github.ref_name }}",
"repo": "${{ github.repository }}",
"pr_number": "${{ github.event.pull_request.number }}",
"sha": "${{ github.event.pull_request.head.sha || github.sha }}"
}
- name: Log integration test trigger
if: steps.check-token.outputs.has_token == 'true'
run: |
echo "✅ Triggered integration tests in ${{ env.EXAMPLES_REPO }}"
echo ""
echo "Test configuration:"
echo " Branch: ${{ github.head_ref || github.ref_name }}"
echo " Repository: ${{ github.repository }}"
echo " PR: #${{ github.event.pull_request.number }}"
echo " SHA: ${{ github.event.pull_request.head.sha || github.sha }}"
echo ""
echo "View results: https://github.com/${{ env.EXAMPLES_REPO }}/actions"
# Alternative: Run integration tests directly in this workflow
# This doesn't require cross-repo dispatch but duplicates the test logic
direct-integration-test:
name: Direct Integration Test
runs-on: ubuntu-latest
# Only run if we don't have the dispatch token
# This provides a fallback for forks and repos without the secret
steps:
- name: Checkout rules_wasm_component (this PR)
uses: actions/checkout@v6
with:
path: rules_wasm_component
- name: Check for matching examples branch
id: examples-branch
run: |
RULES_BRANCH="${{ github.head_ref || github.ref_name }}"
echo "══════════════════════════════════════════════════════════"
echo "INTEGRATION TEST BRANCH RESOLUTION"
echo "══════════════════════════════════════════════════════════"
echo "Rules PR branch: $RULES_BRANCH"
echo "Checking examples repo for matching branch..."
echo ""
# Check if a matching branch exists in the examples repo
if git ls-remote --heads https://github.com/pulseengine/wasm-component-examples.git "$RULES_BRANCH" | grep -q "$RULES_BRANCH"; then
echo "✅ Found matching branch: $RULES_BRANCH"
echo " Using examples branch: $RULES_BRANCH"
echo ""
echo " This means the rules PR has breaking changes that require"
echo " corresponding updates in the examples repo."
echo "branch=$RULES_BRANCH" >> $GITHUB_OUTPUT
echo "matched=true" >> $GITHUB_OUTPUT
else
echo "ℹ️ No matching branch found: $RULES_BRANCH"
echo " Using examples branch: main"
echo ""
echo " This is expected for non-breaking changes."
echo "branch=main" >> $GITHUB_OUTPUT
echo "matched=false" >> $GITHUB_OUTPUT
fi
echo "══════════════════════════════════════════════════════════"
- name: Checkout examples repository
uses: actions/checkout@v6
with:
repository: pulseengine/wasm-component-examples
ref: ${{ steps.examples-branch.outputs.branch }}
path: examples
- name: Setup integration test
working-directory: examples
run: |
# Replace git_override with local_path_override between markers
sed -i '/RULES_WASM_COMPONENT_OVERRIDE_START/,/RULES_WASM_COMPONENT_OVERRIDE_END/c\
# RULES_WASM_COMPONENT_OVERRIDE_START\
local_path_override(\
module_name = "rules_wasm_component",\
path = "../rules_wasm_component",\
)\
# RULES_WASM_COMPONENT_OVERRIDE_END' MODULE.bazel
echo "=== MODULE.bazel override block ==="
sed -n '/OVERRIDE_START/,/OVERRIDE_END/p' MODULE.bazel
echo "=== Testing against PR branch ==="
cd ../rules_wasm_component && git log -1 --oneline
- name: Install Bazelisk
run: |
curl -LO https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-linux-amd64
chmod +x bazelisk-linux-amd64
sudo mv bazelisk-linux-amd64 /usr/local/bin/bazel
- name: Build examples
working-directory: examples
run: bazel build //...
- name: Install Wasmtime
run: |
curl https://wasmtime.dev/install.sh -sSf | bash
echo "$HOME/.wasmtime/bin" >> $GITHUB_PATH
- name: Test Rust components
working-directory: examples
run: |
echo "=== Testing hello_rust ==="
WASM_FILE=$(bazel cquery --output=files //rust:hello_rust 2>/dev/null | head -1)
$HOME/.wasmtime/bin/wasmtime run "$WASM_FILE"
echo ""
echo "=== Testing calculator ==="
WASM_FILE=$(bazel cquery --output=files //rust:calculator 2>/dev/null | head -1)
OUTPUT=$($HOME/.wasmtime/bin/wasmtime run "$WASM_FILE" 8 + 8)
echo "$OUTPUT"
echo "$OUTPUT" | grep -q "8 + 8 = 16"
- name: Report result
if: success()
run: |
echo "══════════════════════════════════════════════════════════"
echo "✅ INTEGRATION TEST PASSED"
echo "══════════════════════════════════════════════════════════"
echo "Rules: ${{ github.repository }}@${{ github.head_ref || github.ref_name }}"
echo "Examples: ${{ steps.examples-branch.outputs.branch }}"
if [ "${{ steps.examples-branch.outputs.matched }}" == "true" ]; then
echo ""
echo "Note: Used matching examples branch for breaking changes."
fi
echo "══════════════════════════════════════════════════════════"
- name: Report failure
if: failure()
run: |
echo "══════════════════════════════════════════════════════════"
echo "❌ INTEGRATION TEST FAILED"
echo "══════════════════════════════════════════════════════════"
echo "Rules: ${{ github.repository }}@${{ github.head_ref || github.ref_name }}"
echo "Examples: ${{ steps.examples-branch.outputs.branch }}"
if [ "${{ steps.examples-branch.outputs.matched }}" == "false" ]; then
echo ""
echo "💡 TIP: If this is a breaking change, create a branch in"
echo " pulseengine/wasm-component-examples with the same name:"
echo " ${{ github.head_ref || github.ref_name }}"
echo " Update the examples to work with the new API, then re-run."
fi
echo "══════════════════════════════════════════════════════════"