Merge pull request #194 from Lemoncode/feature/188-add-the-location-t… #76
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 Azure Functions | |
| on: | |
| push: | |
| branches: ["main"] | |
| concurrency: | |
| group: functions-prod | |
| cancel-in-progress: true | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # Checkout repository source code | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| # Setup Node.js runtime | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "22" | |
| cache: "npm" | |
| # Install all monorepo dependencies (npm workspaces) | |
| - name: Install dependencies | |
| run: npm ci | |
| # Build only the packages needed by Azure Functions (avoids building front/Next.js | |
| # which fails under Corepack/Node 22 due to SWC + packageManager conflict) | |
| - name: Build internal packages for functions | |
| run: | | |
| npm run -w db-model build | |
| npm run -w arcgis build --if-present | |
| npm run -w scraping-cuenca-mediterranea build --if-present | |
| npm run -w scraping-cuenca-cantabrico build --if-present | |
| npm run -w scraping-cuenca-catalana build --if-present | |
| npm run -w scraping-cuenca-duero build --if-present | |
| npm run -w scraping-cuenca-jucar build --if-present | |
| npm run -w scraping-cuenca-segura build --if-present | |
| npm run -w scraping-cuenca-mino-sil build --if-present | |
| npm run -w @embalse-info/db build --if-present | |
| # Build ONLY the functions workspace (TypeScript -> dist/) | |
| # This runs clean + type-check + build | |
| - name: Build functions workspace | |
| run: npm run -w functions ci | |
| # Prepare a clean deployment folder that Azure expects. | |
| # Azure Functions requires host.json at the root. | |
| # We also copy compiled dist output and the internal db package. | |
| - name: Prepare deploy folder | |
| run: | | |
| rm -rf deploy | |
| mkdir -p deploy/packages deploy/integrations | |
| # Copy required runtime files | |
| cp functions/host.json deploy/host.json | |
| cp -R functions/dist deploy/dist | |
| # Copy all workspace packages needed at runtime | |
| cp -R packages/db deploy/packages/db | |
| cp -R packages/db-model deploy/packages/db-model | |
| cp -R integrations/arcgis deploy/integrations/arcgis | |
| cp -R integrations/scraping-cuenca-mediterranea deploy/integrations/scraping-cuenca-mediterranea | |
| cp -R integrations/scraping-cuenca-cantabrico deploy/integrations/scraping-cuenca-cantabrico | |
| cp -R integrations/scraping-cuenca-catalana deploy/integrations/scraping-cuenca-catalana | |
| cp -R integrations/scraping-cuenca-duero deploy/integrations/scraping-cuenca-duero | |
| cp -R integrations/scraping-cuenca-jucar deploy/integrations/scraping-cuenca-jucar | |
| cp -R integrations/scraping-cuenca-segura deploy/integrations/scraping-cuenca-segura | |
| cp -R integrations/scraping-cuenca-mino-sil deploy/integrations/scraping-cuenca-mino-sil | |
| # Strip devDependencies and rewrite workspace refs to file: paths | |
| node -e " | |
| const fs = require('fs'); | |
| function patchPkg(p, depOverrides) { | |
| const pkg = JSON.parse(fs.readFileSync(p, 'utf8')); | |
| delete pkg.devDependencies; | |
| if (depOverrides) { | |
| pkg.dependencies = { ...pkg.dependencies, ...depOverrides }; | |
| } | |
| fs.writeFileSync(p, JSON.stringify(pkg, null, 2)); | |
| } | |
| // db: point workspace deps to file: paths | |
| patchPkg('deploy/packages/db/package.json', { | |
| 'arcgis': 'file:../../integrations/arcgis', | |
| 'db-model': 'file:../db-model', | |
| 'scraping-cuenca-mediterranea': 'file:../../integrations/scraping-cuenca-mediterranea', | |
| 'scraping-cuenca-cantabrico': 'file:../../integrations/scraping-cuenca-cantabrico', | |
| 'scraping-cuenca-catalana': 'file:../../integrations/scraping-cuenca-catalana', | |
| 'scraping-cuenca-duero': 'file:../../integrations/scraping-cuenca-duero', | |
| 'scraping-cuenca-jucar': 'file:../../integrations/scraping-cuenca-jucar', | |
| 'scraping-cuenca-segura': 'file:../../integrations/scraping-cuenca-segura', | |
| 'scraping-cuenca-mino-sil': 'file:../../integrations/scraping-cuenca-mino-sil' | |
| }); | |
| // arcgis: point db-model to file: path | |
| patchPkg('deploy/integrations/arcgis/package.json', { | |
| 'db-model': 'file:../../packages/db-model' | |
| }); | |
| // scraping-cuenca-mediterranea: point db-model to file: path | |
| patchPkg('deploy/integrations/scraping-cuenca-mediterranea/package.json', { | |
| 'db-model': 'file:../../packages/db-model' | |
| }); | |
| // scraping-cuenca-cantabrico: point db-model to file: path | |
| patchPkg('deploy/integrations/scraping-cuenca-cantabrico/package.json', { | |
| 'db-model': 'file:../../packages/db-model' | |
| }); | |
| // scraping-cuenca-catalana: point db-model to file: path | |
| patchPkg('deploy/integrations/scraping-cuenca-catalana/package.json', { | |
| 'db-model': 'file:../../packages/db-model' | |
| }); | |
| // scraping-cuenca-duero: point db-model to file: path | |
| patchPkg('deploy/integrations/scraping-cuenca-duero/package.json', { | |
| 'db-model': 'file:../../packages/db-model' | |
| }); | |
| // scraping-cuenca-jucar: point db-model to file: path | |
| patchPkg('deploy/integrations/scraping-cuenca-jucar/package.json', { | |
| 'db-model': 'file:../../packages/db-model' | |
| }); | |
| // scraping-cuenca-segura: point db-model to file: path | |
| patchPkg('deploy/integrations/scraping-cuenca-segura/package.json', { | |
| 'db-model': 'file:../../packages/db-model' | |
| }); | |
| // scraping-cuenca-mino-sil: point db-model to file: path | |
| patchPkg('deploy/integrations/scraping-cuenca-mino-sil/package.json', { | |
| 'db-model': 'file:../../packages/db-model' | |
| }); | |
| // db-model: just strip devDeps | |
| patchPkg('deploy/packages/db-model/package.json'); | |
| " | |
| # Generate a deploy-specific package.json. | |
| node -e " | |
| const fs = require('fs'); | |
| const pkg = JSON.parse(fs.readFileSync('functions/package.json','utf8')); | |
| pkg.name = 'functions-deploy'; | |
| pkg.main = 'dist/index.js'; | |
| delete pkg.devDependencies; | |
| delete pkg.scripts; | |
| pkg.dependencies = pkg.dependencies || {}; | |
| pkg.dependencies['@embalse-info/db'] = 'file:./packages/db'; | |
| fs.writeFileSync('deploy/package.json', JSON.stringify(pkg, null, 2)); | |
| " | |
| # Install only production dependencies inside deploy/ | |
| # This creates deploy/node_modules ready for Azure runtime | |
| cd deploy | |
| npm install --omit=dev --ignore-scripts | |
| # Replace symlinks with real copies so the deploy zip is self-contained | |
| find node_modules -type l | while read link; do | |
| target=$(readlink -f "$link") | |
| rm "$link" | |
| cp -R "$target" "$link" | |
| done | |
| # Deploy the prepared folder to Azure Functions | |
| - name: Deploy to Azure Functions | |
| uses: Azure/functions-action@v1.5.3 | |
| with: | |
| app-name: fn-info-embalse-prod | |
| package: deploy | |
| publish-profile: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }} | |
| sku: flexconsumption |