-
Notifications
You must be signed in to change notification settings - Fork 218
184 lines (177 loc) · 6.99 KB
/
ci.yml
File metadata and controls
184 lines (177 loc) · 6.99 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
name: Test
on:
push:
branches:
- main
pull_request:
jobs:
detect-changes:
name: Detect Changes
runs-on: ubuntu-latest
outputs:
nx-changed: ${{ steps.changes.outputs.nx }}
exla-changed: ${{ steps.changes.outputs.exla }}
torchx-changed: ${{ steps.changes.outputs.torchx }}
steps:
- uses: actions/checkout@v2
- name: Detect changes
id: changes
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
# For PRs, compare with the base branch
BASE_SHA="${{ github.event.pull_request.base.sha }}"
else
# For pushes, use the previous commit
BASE_SHA="${{ github.event.before }}"
fi
# Handle edge cases:
# - BASE_SHA is all zeros (first push to branch)
# - BASE_SHA is empty
# - BASE_SHA doesn't exist (e.g., after force push)
if [ "$BASE_SHA" = "0000000000000000000000000000000000000000" ] || \
[ -z "$BASE_SHA" ] || \
! git cat-file -e "$BASE_SHA" 2>/dev/null; then
# Fetch main branch to compare against
git fetch origin main:main --depth=1 || true
BASE_SHA="main"
fi
if git diff --name-only $BASE_SHA ${{ github.sha }} | grep -q "^nx/"; then
echo "nx=true" >> $GITHUB_OUTPUT
else
echo "nx=false" >> $GITHUB_OUTPUT
fi
if git diff --name-only $BASE_SHA ${{ github.sha }} | grep -q "^exla/"; then
echo "exla=true" >> $GITHUB_OUTPUT
else
echo "exla=false" >> $GITHUB_OUTPUT
fi
if git diff --name-only $BASE_SHA ${{ github.sha }} | grep -q "^torchx/"; then
echo "torchx=true" >> $GITHUB_OUTPUT
else
echo "torchx=false" >> $GITHUB_OUTPUT
fi
main:
name: Linux (${{ matrix.working_directory }}, ${{ matrix.elixir }}, ${{ matrix.otp }})
runs-on: ubuntu-latest
needs: detect-changes
strategy:
fail-fast: false
matrix:
working_directory: ["nx", "exla", "torchx"]
elixir: ["1.17.3", "1.18.4"]
include:
- elixir: "1.17.3"
otp: "27.3"
- elixir: "1.18.4"
otp: "28.3"
lint: true
defaults:
run:
working-directory: ${{ matrix.working_directory }}
env:
MIX_ENV: test
XLA_FLAGS: --xla_force_host_platform_device_count=4
steps:
- name: Set conditional variables
working-directory: .
run: |
if [ "${{ needs.detect-changes.outputs.nx-changed }}" = "true" ]; then
echo "should_run=true" >> $GITHUB_ENV
elif [ "${{ needs.detect-changes.outputs.exla-changed }}" = "true" ] && [ "${{ matrix.working_directory }}" = "exla" ]; then
echo "should_run=true" >> $GITHUB_ENV
elif [ "${{ needs.detect-changes.outputs.torchx-changed }}" = "true" ] && [ "${{ matrix.working_directory }}" = "torchx" ]; then
echo "should_run=true" >> $GITHUB_ENV
else
echo "should_run=false" >> $GITHUB_ENV
fi
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1
with:
otp-version: ${{ matrix.otp }}
elixir-version: ${{ matrix.elixir }}
- name: Retrieve dependencies cache
if: ${{ steps.mix-cache.outputs.cache-hit != 'true' && env.should_run == 'true' }}
env:
cache-name: cache-mix-deps
uses: actions/cache@v3
id: mix-cache # id to use in retrieve action
with:
path: ${{ github.workspace }}/${{ matrix.working_directory }}/deps
key: ${{ runner.os }}-Elixir-v${{ matrix.elixir }}-OTP-${{ matrix.otp }}-${{ hashFiles(format('{0}/{1}/mix.lock', github.workspace, matrix.working_directory)) }}-v1
- name: Install dependencies
if: ${{ steps.mix-cache.outputs.cache-hit != 'true' && env.should_run == 'true' }}
run: mix deps.get
- name: Compile and check warnings
if: ${{ env.should_run == 'true' }}
run: mix compile --warnings-as-errors
- name: Check formatting
if: ${{ matrix.lint && env.should_run == 'true' }}
run: mix format --check-formatted
- name: Run epmd for distributed tests
if: ${{ env.should_run == 'true' }}
run: epmd -daemon
- name: Run tests
if: ${{ env.should_run == 'true' }}
run: mix test
win:
name: Windows (${{ matrix.working_directory }}, ${{ matrix.elixir }}, ${{ matrix.otp }})
runs-on: windows-2022
needs: detect-changes
strategy:
fail-fast: false
matrix:
working_directory: ["nx", "torchx"]
include:
- elixir: "1.18.4"
otp: "27.3"
defaults:
run:
working-directory: ${{ matrix.working_directory }}
env:
MIX_ENV: test
XLA_FLAGS: --xla_force_host_platform_device_count=4
steps:
- name: Set conditional variables
working-directory: .
shell: pwsh
run: |
if ("${{ needs.detect-changes.outputs.nx-changed }}" -eq "true" -and "${{ matrix.working_directory }}" -eq "nx") {
echo "should_run=true" | Out-File -FilePath $env:GITHUB_ENV -Append
} elseif ("${{ needs.detect-changes.outputs.exla-changed }}" -eq "true" -and "${{ matrix.working_directory }}" -eq "exla") {
echo "should_run=true" | Out-File -FilePath $env:GITHUB_ENV -Append
} elseif ("${{ needs.detect-changes.outputs.torchx-changed }}" -eq "true" -and "${{ matrix.working_directory }}" -eq "torchx") {
echo "should_run=true" | Out-File -FilePath $env:GITHUB_ENV -Append
} else {
echo "should_run=false" | Out-File -FilePath $env:GITHUB_ENV -Append
}
- name: Configure Git
run: git config --global core.autocrlf input
working-directory: .
- uses: actions/checkout@v2
- uses: ilammy/msvc-dev-cmd@v1
with:
toolset: 14.2
vsversion: 2022
arch: x64
- uses: erlef/setup-beam@v1
with:
otp-version: ${{ matrix.otp }}
elixir-version: ${{ matrix.elixir }}
- name: Retrieve dependencies cache
if: ${{ steps.mix-cache.outputs.cache-hit != 'true' && env.should_run == 'true' }}
env:
cache-name: cache-mix-deps
uses: actions/cache@v3
id: mix-cache # id to use in retrieve action
with:
path: ${{ github.workspace }}\${{ matrix.working_directory }}\deps
key: ${{ runner.os }}-Elixir-v${{ matrix.elixir }}-OTP-${{ matrix.otp }}-${{ hashFiles(format('{0}\{1}\mix.lock', github.workspace, matrix.working_directory)) }}-v1
- name: Install dependencies
if: ${{ steps.mix-cache.outputs.cache-hit != 'true' && env.should_run == 'true' }}
run: mix deps.get
- name: Compile and check warnings
if: ${{ env.should_run == 'true' }}
run: mix compile --warnings-as-errors
- name: Run tests
if: ${{ env.should_run == 'true' }}
run: mix test