Skip to content

Check TypeScript projects #419

Check TypeScript projects

Check TypeScript projects #419

name: Check TypeScript projects
on:
workflow_dispatch:
schedule:
- cron: '5 4 * * 1'
push:
branches:
- main
paths:
- '.github/workflows/check-typescript-projects.yml'
- 'projects/**/*'
- '.nvmrc'
- 'package.json'
- 'package-lock.json'
pull_request:
branches:
- main
paths:
- '.github/workflows/check-typescript-projects.yml'
- 'projects/**/*'
- '.nvmrc'
- 'package.json'
- 'package-lock.json'
jobs:
build_maxgraph_dev_package:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
repository: 'maxGraph/maxGraph'
- name: Setup node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: Install dependencies
run: npm install
- name: Build package
working-directory: packages/core
run: npm pack
- name: Upload npm package
uses: actions/upload-artifact@v4
with:
name: maxgraph-npm-package
path: |
packages/core/maxgraph-core-*.tgz
build_projects:
runs-on: ubuntu-22.04
needs: [build_maxgraph_dev_package]
strategy:
# don't cancel running jobs even if one fails
fail-fast: false
matrix:
project:
- lit-ts
- parcel-ts
- rollup-ts
- rsbuild-ts
- sveltekit-ts
- vitejs-ts
npm-package: ['release', 'development']
steps:
- name: Download the maxgraph npm package
if: ${{ matrix.npm-package == 'development' }}
id: 'download'
uses: actions/download-artifact@v4
with:
name: maxgraph-npm-package
path: ${{github.workspace}}/../maxgraph-npm-package
- uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: Install dependencies
uses: bahmutov/npm-install@v1
with:
install-command: npm ci --prefer-offline --audit false --ignore-scripts
- name: Install maxgraph development npm package
if: ${{ matrix.npm-package == 'development' }}
# use wildcard as the file contains the version, and we don't know it
run: npm install ${{steps.download.outputs.download-path}}/maxgraph-core*.tgz
- name: Build project
run: npm run build -w projects/_shared -w projects/${{matrix.project}}
- name: Upload project archive
if: ${{ matrix.npm-package == 'release' }}
uses: actions/upload-artifact@v4
with:
name: ${{matrix.project}}
path: ${{github.workspace}}/projects/${{matrix.project}}/dist
# bundle everything in a single bundle + create home page
create_all-in-one_artifact:
runs-on: ubuntu-22.04
needs: 'build_projects'
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: tmp
- name: Display structure of downloaded files after removing maxgraph-npm-package
run: |
rm -rf maxgraph-npm-package
ls -lhR
working-directory: tmp
- name: Build the final directories layout
run: |
mkdir -p build
cp -R tmp/* build
- name: List projects that will be referenced in the home page
id: list_projects
run: |
# for the ls option, see https://serverfault.com/a/1095912
echo "projects_path=$(ls -xw0 build/)" >> $GITHUB_OUTPUT
- name: Create the home page
uses: actions/github-script@v7
env:
PROJECTS_PATH: ${{ steps.list_projects.outputs.projects_path }}
with:
script: |
const {PROJECTS_PATH} = process.env;
const projectsListing = PROJECTS_PATH.split(' ').filter(name => name.trim() !== '').map(name => `<li><a href="${name}/" target="_blank">${name}</a></li>`).join('\n');
let htmlContent = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Examples of maxGraph projects</title>
</head>
<body>
<h1>Examples of <code>maxGraph</code> projects</h1>
<p>
Projects built using the <a href="https://github.com/maxGraph/maxGraph/releases/latest" target="_blank">latest released version</a> of <code>maxGraph</code>
<ul>
${projectsListing}
</ul>
</body>
</html>
`
console.info('Generated page', htmlContent);
// Create the file
require('fs').writeFileSync('build/index.html', htmlContent);
- name: Display the final structure of files
run: |
ls -lhR build
- name: Upload artifact not for GitHub Pages
if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') != 'true'
uses: actions/upload-artifact@v4
with:
name: all-typescript-projects-${{github.sha}}
path: build
- name: Upload artifact for GitHub Pages
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
uses: actions/upload-pages-artifact@v3
with:
path: build
deploy_gh_pages:
needs: create_all-in-one_artifact
if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch' ) && github.event.ref == 'refs/heads/main'
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
contents: read
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source
# Deploy to the github-pages environment
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-22.04
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4