-
Notifications
You must be signed in to change notification settings - Fork 816
118 lines (105 loc) · 4.41 KB
/
gh_pages_deploy.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
name: Deploy to GitHub Pages, Update notebooks index
on:
push:
branches:
- 'latest'
workflow_run:
workflows: [treon_nightly]
branches:
- 'latest'
types:
- completed
workflow_dispatch:
concurrency:
group: 'pages'
cancel-in-progress: true
permissions:
contents: read
jobs:
build_assets:
runs-on: ubuntu-20.04
permissions:
contents: write
outputs:
should_deploy: ${{ steps.check_deploy.outputs.should_deploy }}
steps:
- name: Checkout code
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
with:
fetch-depth: 0
token: ${{ secrets.GH_ACTIONS_BOT_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: 18
- name: Install Node.js dependencies
working-directory: ./selector
shell: bash
run: npm ci
- name: Validate all 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 [error, metadataMarkdowns] = NotebookMetadataHandler.validateAll();
core.summary.addHeading(`Validated Notebooks (${metadataMarkdowns.length})`, '2');
core.summary.addRaw(metadataMarkdowns.join('\n\n'));
core.summary.write();
if (error) {
core.setFailed(error);
}
- name: Build static for GitHub Pages
working-directory: ./selector
shell: bash
run: npm run build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check if deploy needed
id: check_deploy
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const { readFile } = require('fs/promises');
const { checksumFileName } = await import('${{ github.workspace }}/selector/src/shared/build-checksum.js');
const { owner, repo } = context.repo;
const { data: { html_url }} = await github.rest.repos.getPages({ owner, repo });
const deployedChecksum = await fetch(`${html_url}/${checksumFileName}`).then((res) => res.status === 200 ? res.text() : null);
const currentChecksum = await readFile(`${{ github.workspace }}/selector/dist/openvino_notebooks/${checksumFileName}`, { encoding: 'utf8'});
const isManualDeploy = context.eventName === 'workflow_dispatch';
const shouldDeploy = isManualDeploy || currentChecksum !== deployedChecksum;
core.setOutput('should_deploy', shouldDeploy);
- name: Upload pages artifact
if: ${{ steps.check_deploy.outputs.should_deploy == 'true' }}
uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3.0.1
with:
path: ./selector/dist/openvino_notebooks
- name: Generate new notebooks index
if: ${{ steps.check_deploy.outputs.should_deploy == 'true' }}
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const { generateNotebooksIndex } = await import('${{ github.workspace }}/selector/src/shared/generate-notebooks-index.js');
generateNotebooksIndex(`${{ github.workspace }}/selector/dist/openvino_notebooks/notebooks-metadata-map.json`);
- name: Commit notebooks index
if: ${{ steps.check_deploy.outputs.should_deploy == 'true' }}
shell: bash
run: |
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
git add ./notebooks/README.md
git commit -m "Update notebooks index readme file [skip ci]" || echo "Index file is not changed"
git push
deploy_github_pages:
runs-on: ubuntu-20.04
needs: build_assets
if: ${{ needs.build_assets.outputs.should_deploy == 'true' }}
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5