Skip to content

Commit 36ecf91

Browse files
Merge pull request #82 from dotnet/u/xiaoyun/addworkflow
add workflow to run newly-added notebooks before merging
2 parents fa9be24 + 57e7883 commit 36ecf91

File tree

5 files changed

+119
-0
lines changed

5 files changed

+119
-0
lines changed

.config/dotnet-tools.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"dotnet-repl": {
6+
"version": "0.1.204",
7+
"commands": [
8+
"dotnet-repl"
9+
]
10+
}
11+
}
12+
}

.github/workflows/run_notebooks.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# This is a basic workflow to help you get started with Actions
2+
3+
name: CI
4+
5+
# Controls when the workflow will run
6+
on:
7+
pull_request:
8+
branches: [ "main" ]
9+
10+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
11+
jobs:
12+
# This workflow contains a single job called "test_notebooks"
13+
test_notebooks:
14+
# The type of runner that the job will run on
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
19+
- uses: actions/checkout@v3
20+
# fetch main branch
21+
- run: git fetch origin main:main
22+
- name: Setup .NET
23+
uses: actions/setup-dotnet@v3
24+
with:
25+
global-json-file: global.json
26+
27+
- name: Restore tool
28+
run: dotnet tool restore
29+
30+
- name: Perform a Pester test from the .tools/run_all_notebooks.ps1
31+
shell: pwsh
32+
run: |
33+
Invoke-Pester .tools/run_all_notebooks.ps1 -Passthru
34+
continue-on-error: true
35+
36+
- name: Upload output as artifact
37+
uses: actions/upload-artifact@v2
38+
with:
39+
name: output
40+
path: output

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,5 @@ MigrationBackup/
348348

349349
# Ionide (cross platform F# VS Code tools) working folder
350350
.ionide/
351+
352+
output

.tools/run_all_notebooks.ps1

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# cd to the directory of this script
2+
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
3+
$rootPath = Split-Path -Parent $scriptPath
4+
$outputFolder = "$rootPath/output"
5+
if (Test-Path $outputFolder) {
6+
Remove-Item $outputFolder -Recurse -Force
7+
}
8+
New-Item -ItemType Directory -Path $outputFolder
9+
10+
Set-Location $rootPath
11+
12+
# list all newly added notebooks by comparing with the main branch
13+
# $mainBranch = "main"
14+
# $notebooks = git diff --name-only $mainBranch | Where-Object { $_ -like "*.ipynb" }
15+
$notebooks = Get-ChildItem -Path $rootPath -Recurse -Include *.ipynb | Where-Object { $_.FullName -notlike "*output*" }
16+
17+
# skip notebooks that are known to fail
18+
$notebooks_to_skip = @(
19+
"14-Methods and Members.ipynb",
20+
"02-Code Cells.ipynb"
21+
)
22+
23+
$notebooks = $notebooks | Where-Object { $notebooks_to_skip -notcontains $_.Name }
24+
# list all notebooks and print out
25+
foreach ($notebook in $notebooks) {
26+
Write-Host $notebook
27+
}
28+
29+
# for each notebook, run it using dotnet perl. Check the exit code and print out the result
30+
# if the exit code is not 0, exit the script with exit code 1
31+
$failNotebooks = @()
32+
$exitCode = 0
33+
foreach ($notebook in $notebooks) {
34+
Write-Host "Running $notebook"
35+
# get notebook name with extension
36+
$name = Split-Path -Leaf $notebook
37+
Write-Host "Name: $name"
38+
$notebookFolder = Split-Path -Parent $notebook
39+
$outputPath = "$outputFolder\$notebookFolder"
40+
Set-Location $notebookFolder
41+
$result = dotnet repl --run $name --exit-after-run
42+
Write-Host $result
43+
if ($LASTEXITCODE -ne 0) {
44+
Write-Host "Failed to run $notebook"
45+
$failNotebooks += $notebook
46+
$exitCode = 1
47+
}
48+
else{
49+
Write-Host "Successfully ran $notebook"
50+
}
51+
Set-Location $rootPath
52+
}
53+
54+
Write-Host "Failed notebooks:"
55+
foreach ($notebook in $failNotebooks) {
56+
Write-Host $notebook
57+
}
58+
59+
exit $exitCode

global.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"sdk": {
3+
"version": "7.0.100",
4+
"rollForward": "latestFeature"
5+
}
6+
}

0 commit comments

Comments
 (0)