Skip to content

Deploy to GitHub Pages, Update notebooks index #32

Deploy to GitHub Pages, Update notebooks index

Deploy to GitHub Pages, Update notebooks index #32

name: Deploy to GitHub Pages
on:
push:
branches:
- 'main'
workflow_dispatch:
concurrency:
group: 'pages'
cancel-in-progress: true
jobs:
build_assets:
runs-on: ubuntu-20.04
outputs:
should_deploy: ${{ steps.check_deploy.outputs.should_deploy }}
steps:
- name: Checkout code
uses: actions/checkout@v4
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@v4
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@v7
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
- name: Check if deploy needed
id: check_deploy
uses: actions/github-script@v7
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@v3
with:
path: ./selector/dist/openvino_notebooks
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@v4