-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaction.yml
143 lines (130 loc) · 4.68 KB
/
action.yml
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
name: kaggle Action
author: Rowe Wilson Frederisk Holme
description: Use kaggle to implement simple CI, which supports GPU.
inputs:
username:
description: kaggle username
required: true
key:
description: kaggle key
required: true
# id:
# description: The URL slug of your kernel
# id_no:
# description: The kernel's numeric ID
title:
description: The title of the kernel
required: true
code_file:
description: The path to your kernel source code
required: true
language:
description: The language your kernel is written in
default: python
kernel_type:
description: The type of kernel
default: script
# is_private:
# description: Whether or not the kernel should be private
enable_gpu:
description: Whether or not the kernel should run on a GPU
default: enable
enable_internet:
description: Whether or not the kernel should be able to access the internet
default: enable
# dataset_sources:
# description: A list of dataset sources
# competition_sources:
# description: A list of competition sources
# kernel_sources:
# description: A list of kernel sources
outputs:
automatic_releases_tag:
description: The release tag this action just processed
value: ""
upload_url:
description: The URL for uploading additional assets to the release
value: ""
runs:
using: composite
steps:
- name: Install kaggle CLI tools
shell: pwsh
run: python -m pip install --upgrade kaggle --user
- name: Setup kaggle.json
shell: pwsh
run: |
[String]$kaggleInfo = ConvertTo-Json -InputObject @{
'username' = '${{ inputs.username }}';
'key' = '${{ inputs.key }}'
};
[String]$kaggleFile = [System.IO.Path]::Combine('~', '.kaggle', 'kaggle.json');
New-Item -Path $kaggleFile -Type File -Value $kaggleInfo -Force | Out-Null;
if ($IsLinux -or $IsMacOS) {
chmod 600 $kaggleFile;
}
- name: Setup test
shell: pwsh
run: |
# location
Set-Location -Path '${{ github.action_path }}' | Out-Null;
[String]$actionPath = '${{ github.action_path }}';
# kaggle init
kaggle kernels init -p $actionPath;
# process metadata json
[String]$jsonPath = [System.IO.Path]::Combine($actionPath, 'kernel-metadata.json');
[Hashtable]$metadata = Get-Content -Path $jsonPath -Raw | ConvertFrom-Json -AsHashtable;
# $metadata[''] = '$#{{ inputs. }}';
$metadata['id'] = $metadata['id'].Split('/')[0] + '/' + '${{ inputs.title }}';
$metadata['title'] = '${{ inputs.title }}';
$metadata['code_file'] = '${{ github.workspace }}' + '/' + '${{ inputs.code_file }}';
$metadata['language'] = '${{ inputs.language }}';
$metadata['kernel_type'] = '${{ inputs.kernel_type }}';
$metadata['enable_gpu'] = '${{ inputs.enable_gpu }}' -eq 'enable';
$metadata['enable_internet'] = '${{ inputs.enable_internet }}' -eq 'enable';
ConvertTo-Json -InputObject $metadata | Set-Content -Path $jsonPath | Out-Null;
#kaggle push
kaggle kernels push;
- name: Check status
shell: pwsh
run: |
# location
Set-Location -Path '${{ github.action_path }}' | Out-Null;
[String]$kernelName = '${{ inputs.title }}';
# check status
try {
while ($true) {
[String]$status = (kaggle kernels status $kernelName 2>&1) -join ' ';
# error
if ($status -like '*error*') {
throw [System.Management.Automation.ApplicationFailedException]::new('FAIL: Test(s) failed.');
}
# cancel
elseif ($status -like '*cancel*') {
throw [OperationCanceledException]::new('FAIL: Test(s) failed. The kaggle kernel has been canceled.');
}
#complete
elseif ($status -like '*complete*') {
Write-Host -Object 'SUCCESS: Kaggle Integration Tests!' -ForegroundColor Green | Out-Null;
break;
}
# running
else {
Start-Sleep -Seconds 3 | Out-Null;
}
}
}
catch [System.Management.Automation.ApplicationFailedException], [OperationCanceledException] {
# write log
kaggle kernels output $kernelName;
[String]$fullMessage = (Get-Content -Path ($kernelName + '.log') -Raw | ConvertFrom-Json -AsHashtable | ForEach-Object -Process { $_['data'] }) -join '';
Write-Host -Object @"
::group::Full log
$fullMessage
::endgroup::
"@ | Out-Null;
throw;
}
branding:
icon: activity
color: green