diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml new file mode 100755 index 0000000..d925f70 --- /dev/null +++ b/.github/workflows/run_tests.yml @@ -0,0 +1,42 @@ +name: Run tests + +on: + push: + branches: [ master, develop ] + pull_request: + branches: [ master, develop] + +# Cancel job when new commit is pushed for the same build +# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#concurrency +# https://github.com/OSGeo/gdal/pull/5460 +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} + cancel-in-progress: true + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + node: [ 16 ] + + steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node }} +# We need package-lock.json to use cache this way +# cache: 'npm' + - name: Install dependencies +# With package-lock.json we should use "npm ci" + run: npm install + - name: Run tests + run: npm run test + - name: Generate docs metadata + run: npm run metadata + - name: Generate dummy docs metadata + run: npm run dummy_docs + - name: Run build + run: npm run build diff --git a/package.json b/package.json index 9a04c4b..5dae4fe 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "start": "next start", "lint": "next lint", "docs": "node scripts/runAll.js", + "dummy_docs": "node scripts/generateDummyVersions.js", "metadata": "node scripts/generateContentMetadata.js", "docsmetadata": "node scripts/generateDocumentationMetadata.js", "apidocs": "node scripts/generateApidocs.js", diff --git a/scripts/documentationMetadataHelper.js b/scripts/documentationMetadataHelper.js index dacc22e..edf7bc5 100644 --- a/scripts/documentationMetadataHelper.js +++ b/scripts/documentationMetadataHelper.js @@ -13,8 +13,11 @@ function generateDocumentationMetadata(fullPath) { const sortedVersions = subdirectories .sort((a, b) => parseFloat(a) - parseFloat(b)); - const indexContent = `const availableVersions = ${JSON.stringify(sortedVersions)};\n\nexport default availableVersions;`; - fs.writeFileSync(path.join(fullPath, 'index.js'), indexContent); + const indexContent = ` + const availableVersions: string[] = ${JSON.stringify(sortedVersions)}; + export default availableVersions; + `; + fs.writeFileSync(path.join(fullPath, 'index.ts'), indexContent); } exports.getSubdirectories = getSubdirectories; diff --git a/scripts/generateDummyVersions.js b/scripts/generateDummyVersions.js new file mode 100644 index 0000000..dc039fa --- /dev/null +++ b/scripts/generateDummyVersions.js @@ -0,0 +1,22 @@ +const fs = require('fs'); +const path = require('path'); +const { generateDocumentationMetadata } = require('./documentationMetadataHelper'); + +// So build on GitHub Actions can work without cloning the documentation folders +const generateDummyDocs = (folder, addIndex = true) => { + if (!fs.existsSync(folder)) { + fs.mkdirSync(folder, { recursive: true }); + } + + addIndex && generateDocumentationMetadata(folder); + +}; + +generateDummyDocs('./_content/api/versions/'); +generateDummyDocs('./_content/docs/latest', false); +generateDummyDocs('./_content/docs/'); +const indexContent = ` +const allDocs = ['latest']; +export default allDocs; +`; +fs.writeFileSync(path.join('./_content/docs/latest/', 'index.js'), indexContent);