Skip to content

Commit c1e4b59

Browse files
authored
Fix for #3837 -- spawn Github Action jobs only for the targets that need to be tested (#3839)
* Test. * Try again. * Try again. * Forgot close parenthesis. * Add script to determine target test set. * Inline (for now). * Checkout, then run. * Add the damn parameters! * Install Dotnet and Trash. * Make call to local dotnet tool. * Set runs-on for jobs explicitly. * Fix script to output just the targets to test, and leave the rest for the main.yml file. * Fix Ubuntu build. * Remove empty .errors file so "mvn test" still works. * Try clif with empty targets. * Fix target testing set For some grammars, there are no targets that work. Add a default so Github Actions doesn't fail.
1 parent e453816 commit c1e4b59

File tree

4 files changed

+101
-3
lines changed

4 files changed

+101
-3
lines changed

.github/workflows/main.yml

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,44 @@ on:
66
pull_request:
77
branches: [ master ]
88
jobs:
9+
setup:
10+
runs-on: ubuntu-latest
11+
outputs:
12+
mymatrix: ${{ steps.step1.outputs.myoutput }}
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
- name: Install Dotnet
19+
uses: actions/[email protected]
20+
with:
21+
dotnet-version: '7.0.x'
22+
- name: Install Trash
23+
shell: bash
24+
run: |
25+
dotnet tool restore
26+
- name: Gather targets.
27+
id: step1
28+
shell: bash
29+
run: |
30+
if [ "${{github.event_name}}" == "pull_request" ]; then
31+
Before="${{github.event.pull_request.base.sha}}"
32+
After="${{github.event.pull_request.head.sha}}"
33+
else
34+
Before="${{github.event.before}}"
35+
After="${{github.event.after}}"
36+
fi
37+
bash _scripts/what-to-test.sh $Before $After >> $GITHUB_OUTPUT
38+
939
build-pwsh:
40+
needs: setup
1041
runs-on: ${{ matrix.os }}
1142
strategy:
1243
fail-fast: false
1344
matrix:
1445
os: [macos-latest, windows-latest, ubuntu-latest]
15-
language: [ CSharp, Dart, Java, JavaScript, Go, Python3, TypeScript ]
46+
language: ${{ fromJson(needs.setup.outputs.mymatrix) }}
1647
steps:
1748
- name: Info
1849
shell: bash
@@ -113,12 +144,13 @@ jobs:
113144
_scripts/test.ps1 -target ${{ matrix.language }} -pc "$Before" -cc "$After"
114145
115146
build-bash:
147+
needs: setup
116148
runs-on: ${{ matrix.os }}
117149
strategy:
118150
fail-fast: false
119151
matrix:
120152
os: [macos-latest, ubuntu-latest]
121-
language: [ Cpp, CSharp, Dart, Java, JavaScript, Go, PHP, Python3, TypeScript ]
153+
language: ${{ fromJson(needs.setup.outputs.mymatrix) }}
122154
steps:
123155
- name: Info
124156
shell: bash

_scripts/templates/Cpp/st.build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ if($compile_exit_code -ne 0){
2222
exit $compile_exit_code
2323
}
2424

25-
$(& <if(os_win)>cmake --build . --config Release<else>$(MAKE)<endif> ; $compile_exit_code = $LASTEXITCODE ) | Write-Host
25+
$(& <if(os_win)>cmake --build . --config Release<else>make<endif> ; $compile_exit_code = $LASTEXITCODE ) | Write-Host
2626
if($compile_exit_code -ne 0){
2727
Write-Host "Failed second cmake call $compile_exit_code."
2828
exit $compile_exit_code

_scripts/what-to-test.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#
2+
#set -x
3+
declare -A targets
4+
for t in "Cpp" "CSharp" "Dart" "Go" "Java" "JavaScript" "PHP" "Python3" "TypeScript"
5+
do
6+
targets[$t]=0
7+
done
8+
directories=( `git diff --name-only $1 $2 . 2> /dev/null | sed 's#\(.*\)[/][^/]*$#\1#' | sort -u | grep -v _scripts | fgrep -v .github | tr -d '\r'` )
9+
prefix=`pwd`
10+
for g in ${directories[@]}
11+
do
12+
if [ ! -d "$g" ]
13+
then
14+
continue
15+
fi
16+
pushd $g > /dev/null 2> /dev/null
17+
while true
18+
do
19+
if [ -f `pwd`/desc.xml ]
20+
then
21+
break
22+
elif [ `pwd` == "$prefix" ]
23+
then
24+
break
25+
fi
26+
cd ..
27+
done
28+
g=`pwd`
29+
g=${g##*$prefix}
30+
g=${g##/}
31+
if [ "$g" == "" ]
32+
then
33+
g="."
34+
fi
35+
if [ -f desc.xml ]
36+
then
37+
gtargets=`dotnet trxml2 -- desc.xml | fgrep -e '/desc/targets' | awk -F = '{print $2}' | sed 's/;/ /g'`
38+
for t in $gtargets
39+
do
40+
targets[$t]=`expr ${targets[$t]} + 1`
41+
done
42+
fi
43+
popd > /dev/null
44+
done
45+
46+
ttargets=""
47+
for t in "Cpp" "CSharp" "Dart" "Go" "Java" "JavaScript" "PHP" "Python3" "TypeScript"
48+
do
49+
if [ ${targets[$t]} -ne 0 ]
50+
then
51+
if [ "$ttargets" == "" ]
52+
then
53+
ttargets="\"$t\""
54+
else
55+
ttargets="$ttargets, \"$t\""
56+
fi
57+
fi
58+
done
59+
if [ "$ttargets" == "" ]
60+
then
61+
# Github Actions doesn't like a job matrix to contain an empty set.
62+
# Add Java as a default.
63+
ttargets="\"Java\""
64+
fi
65+
echo 'myoutput=[' $ttargets ']'

clif/desc.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
<desc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../_scripts/desc.xsd">
33
<targets></targets>
44
</desc>
5+

0 commit comments

Comments
 (0)