-
Notifications
You must be signed in to change notification settings - Fork 831
61 lines (53 loc) · 2.3 KB
/
validate_notebook_metadata.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
name: Validate Notebooks Metadata
on:
pull_request:
types: [opened, synchronize]
paths:
- 'notebooks/**/*.ipynb'
concurrency:
group: ${{ github.head_ref || github.ref_name }}
cancel-in-progress: true
permissions:
contents: read
jobs:
validate_notebooks_metadata:
runs-on: ubuntu-20.04
name: Validate notebooks metadata
steps:
- name: Checkout code
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: 18
- name: Get changed notebook files
id: get_changed_notebook_files
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const { execSync } = require('child_process');
const { commits } = context.payload.pull_request;
const gitDiffCommand = `git diff --name-only --relative=notebooks --diff-filter=d HEAD~${commits} -- *.ipynb ':!notebooks/utils'`;
const changedNotebooks = execSync(gitDiffCommand).toString().split('\n').filter(Boolean);
core.exportVariable('CHANGED_NOTEBOOKS', JSON.stringify(changedNotebooks));
- name: Install Node.js dependencies
working-directory: ./selector
shell: bash
run: npm ci
- name: Validate changed notebooks metadata
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const { NotebookMetadataHandler } = await import('${{ github.workspace }}/selector/src/notebook-metadata/notebook-metadata-handler.js');
const changedNotebooks = JSON.parse(process.env.CHANGED_NOTEBOOKS);
const [error, metadataMarkdowns] = NotebookMetadataHandler.validateNotebooks(changedNotebooks);
core.summary.addHeading(`Modified Notebooks (${metadataMarkdowns.length})`, '2');
core.summary.addRaw(metadataMarkdowns.join('\n\n'));
core.summary.write();
if (error) {
core.setFailed(error);
}