Deploy to GitHub Pages, Update notebooks index #1730
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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-22.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 }} | |
| persist-credentials: true | |
| - 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 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GH_ACTIONS_BOT_TOKEN }} | |
| run: | | |
| git config user.name 'github-actions[bot]' | |
| git config user.email '41898282+github-actions[bot]@users.noreply.github.com' | |
| git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" | |
| git add ./notebooks/README.md | |
| git commit -m "Update notebooks index readme file [skip ci]" || echo "Index file is not changed" | |
| git push origin HEAD:latest | |
| deploy_github_pages: | |
| runs-on: ubuntu-22.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 |