Skip to content

Commit 91a8e2f

Browse files
CopilotHackingGate
andauthored
Add smart NEW version detection with array-based version management for intelligent test matrix scaling (#933)
* Initial plan * Add workflow_dispatch trigger for manual comprehensive testing Co-authored-by: HackingGate <8541644+HackingGate@users.noreply.github.com> * Remove manual trigger and add automatic version change detection Co-authored-by: HackingGate <8541644+HackingGate@users.noreply.github.com> * Add explicit permissions to address security findings Co-authored-by: HackingGate <8541644+HackingGate@users.noreply.github.com> * Update typst commit hash to resolve merge conflict Co-authored-by: HackingGate <8541644+HackingGate@users.noreply.github.com> * Improve readability of conditional OS matrix logic Co-authored-by: HackingGate <8541644+HackingGate@users.noreply.github.com> * Add granular version change detection for targeted testing Co-authored-by: HackingGate <8541644+HackingGate@users.noreply.github.com> * Fix regex pattern for semantic version extraction Co-authored-by: HackingGate <8541644+HackingGate@users.noreply.github.com> * Centralize version definitions and update Renovate config Co-authored-by: HackingGate <8541644+HackingGate@users.noreply.github.com> * Convert version definitions to array format Co-authored-by: HackingGate <8541644+HackingGate@users.noreply.github.com> * Add error handling for jq command Co-authored-by: HackingGate <8541644+HackingGate@users.noreply.github.com> * Clarify comments for version change detection logic Co-authored-by: HackingGate <8541644+HackingGate@users.noreply.github.com> * Implement new version detection logic per requirements Co-authored-by: HackingGate <8541644+HackingGate@users.noreply.github.com> * Fix version extraction to prevent duplicates Co-authored-by: HackingGate <8541644+HackingGate@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: HackingGate <8541644+HackingGate@users.noreply.github.com> Co-authored-by: Tong <i@hackinggate.com>
1 parent bdb29c1 commit 91a8e2f

2 files changed

Lines changed: 116 additions & 20 deletions

File tree

.github/workflows/test_typst_out_action.yml

Lines changed: 111 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,121 @@ on:
88
branches:
99
- main
1010

11+
permissions:
12+
contents: read
13+
14+
env:
15+
# Array of typst versions to test
16+
# Renovate will update these values
17+
TYPST_VERSIONS: |
18+
[
19+
"latest",
20+
"v0.14.1",
21+
"839c6f76f331dd2f30ede9affa9d734f88828d83"
22+
]
23+
1124
jobs:
25+
detect-changes:
26+
runs-on: ubuntu-latest
27+
permissions:
28+
contents: read
29+
pull-requests: read
30+
outputs:
31+
workflow-changed: ${{ steps.filter.outputs.workflow }}
32+
# Dynamically set matrix based on which typst versions changed
33+
typst-version-matrix: ${{ steps.set-matrix.outputs.typst-version-matrix }}
34+
os-matrix: ${{ steps.set-matrix.outputs.os-matrix }}
35+
steps:
36+
- name: Checkout repository
37+
uses: actions/checkout@v6
38+
with:
39+
fetch-depth: 0
40+
41+
- name: Check for workflow changes
42+
uses: dorny/paths-filter@v3
43+
id: filter
44+
with:
45+
filters: |
46+
workflow:
47+
- '.github/workflows/test_typst_out_action.yml'
48+
49+
- name: Detect changed typst versions
50+
id: set-matrix
51+
run: |
52+
# Parse the TYPST_VERSIONS array
53+
ALL_VERSIONS='${{ env.TYPST_VERSIONS }}'
54+
55+
if [ "${{ steps.filter.outputs.workflow }}" == "true" ]; then
56+
# Check if this is a PR or push event
57+
if [ "${{ github.event_name }}" == "pull_request" ]; then
58+
BASE_REF="${{ github.event.pull_request.base.sha }}"
59+
else
60+
BASE_REF="HEAD^"
61+
fi
62+
63+
# Get the diff for the workflow file
64+
DIFF=$(git diff $BASE_REF HEAD -- .github/workflows/test_typst_out_action.yml || echo "")
65+
66+
# Extract versions from diff - only ADDED lines (new versions)
67+
# Match only lines that are array elements (contain whitespace, quote, value, quote, optional comma)
68+
ADDED_VERSIONS=$(echo "$DIFF" | grep -E '^\+\s+"(latest|v[0-9]+\.[0-9]+\.[0-9]+|[0-9a-f]{40})"' || echo "")
69+
REMOVED_VERSIONS=$(echo "$DIFF" | grep -E '^-\s+"(latest|v[0-9]+\.[0-9]+\.[0-9]+|[0-9a-f]{40})"' || echo "")
70+
71+
if [ -n "$ADDED_VERSIONS" ]; then
72+
# Extract added versions - only capture the actual version string between quotes
73+
NEW_VERSIONS=$(echo "$ADDED_VERSIONS" | sed -n 's/^+\s*"\([^"]*\)".*/\1/p')
74+
75+
# Extract removed versions to filter out
76+
OLD_VERSIONS=$(echo "$REMOVED_VERSIONS" | sed -n 's/^-\s*"\([^"]*\)".*/\1/p')
77+
78+
# Filter out versions that were already present (not truly new)
79+
TRULY_NEW_VERSIONS=""
80+
for version in $NEW_VERSIONS; do
81+
# version is already without quotes from sed
82+
is_old=false
83+
for old in $OLD_VERSIONS; do
84+
if [ "$version" = "$old" ]; then
85+
is_old=true
86+
break
87+
fi
88+
done
89+
if [ "$is_old" = false ]; then
90+
if [ -z "$TRULY_NEW_VERSIONS" ]; then
91+
TRULY_NEW_VERSIONS="\"$version\""
92+
else
93+
TRULY_NEW_VERSIONS="$TRULY_NEW_VERSIONS,\"$version\""
94+
fi
95+
fi
96+
done
97+
98+
if [ -n "$TRULY_NEW_VERSIONS" ]; then
99+
# New versions detected - test only those on all platforms
100+
echo "typst-version-matrix=[$TRULY_NEW_VERSIONS]" >> $GITHUB_OUTPUT
101+
echo 'os-matrix=["ubuntu-latest", "macos-latest", "windows-latest"]' >> $GITHUB_OUTPUT
102+
else
103+
# Parsing failed - fail the job
104+
echo "::error::Failed to parse new versions from diff. Please check TYPST_VERSIONS format."
105+
exit 1
106+
fi
107+
else
108+
# Workflow changed but version array unchanged - test latest only on ubuntu-latest
109+
FIRST_VERSION=$(echo "$ALL_VERSIONS" | jq -r '.[0]' 2>/dev/null || echo "latest")
110+
echo "typst-version-matrix=[\"$FIRST_VERSION\"]" >> $GITHUB_OUTPUT
111+
echo 'os-matrix=["ubuntu-latest"]' >> $GITHUB_OUTPUT
112+
fi
113+
else
114+
# No workflow changes, minimal testing (just first version)
115+
FIRST_VERSION=$(echo "$ALL_VERSIONS" | jq -r '.[0]' 2>/dev/null || echo "latest")
116+
echo "typst-version-matrix=[\"$FIRST_VERSION\"]" >> $GITHUB_OUTPUT
117+
echo 'os-matrix=["ubuntu-latest"]' >> $GITHUB_OUTPUT
118+
fi
119+
12120
test_typst_out_action:
121+
needs: detect-changes
13122
strategy:
14123
matrix:
15-
typst_version:
16-
- latest
17-
- v0.14.2 # specify a version
18-
- 839c6f76f331dd2f30ede9affa9d734f88828d83 # specify a commit hash
19-
os: [ubuntu-latest]
124+
typst_version: ${{ fromJSON(needs.detect-changes.outputs.typst-version-matrix) }}
125+
os: ${{ fromJSON(needs.detect-changes.outputs.os-matrix) }}
20126
fail-fast: false
21127
runs-on: ${{ matrix.os }}
22128
steps:

renovate.json

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{
22
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
3-
"extends": [
4-
"config:recommended"
5-
],
3+
"extends": ["config:recommended"],
64
"git-submodules": {
75
"enabled": true
86
},
@@ -16,24 +14,16 @@
1614
"customManagers": [
1715
{
1816
"customType": "regex",
19-
"fileMatch": [
20-
"^\\.github/workflows/test_typst_out_action\\.yml$"
21-
],
22-
"matchStrings": [
23-
"- (?<currentValue>.*?) # specify a version"
24-
],
17+
"fileMatch": ["^\\.github/workflows/test_typst_out_action\\.yml$"],
18+
"matchStrings": ["\"(?<currentValue>v[0-9]+\\.[0-9]+\\.[0-9]+)\""],
2519
"datasourceTemplate": "github-releases",
2620
"versioningTemplate": "loose",
2721
"depNameTemplate": "typst/typst"
2822
},
2923
{
3024
"customType": "regex",
31-
"fileMatch": [
32-
"^\\.github/workflows/test_typst_out_action\\.yml$"
33-
],
34-
"matchStrings": [
35-
"- (?<currentDigest>.*?) # specify a commit hash"
36-
],
25+
"fileMatch": ["^\\.github/workflows/test_typst_out_action\\.yml$"],
26+
"matchStrings": ["\"(?<currentDigest>[0-9a-f]{40})\""],
3727
"depNameTemplate": "typst/typst",
3828
"packageNameTemplate": "https://github.com/typst/typst.git",
3929
"datasourceTemplate": "git-refs",

0 commit comments

Comments
 (0)