From 48c93244ad87cc9dea465d0adbd4dd78830c102c Mon Sep 17 00:00:00 2001 From: John McGuin Date: Thu, 22 Aug 2024 11:47:16 -0600 Subject: [PATCH] debug: test integrate script --- .github/workflows/publish.yml | 28 +++++++++++++++------------- scripts/build_sites.mjs | 15 ++++++++++++--- scripts/new_site.mjs | 8 ++++++++ 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 230f8cd..299e8cf 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -4,7 +4,7 @@ on: jobs: prepare: - name: Prepare Matrix Output + name: Prepare Matrix runs-on: ubuntu-latest outputs: matrix: ${{steps.matrix.outputs.matrix}} @@ -12,10 +12,8 @@ jobs: - name: Checkout uses: actions/checkout@v3 - - name: Setting SITES - run: echo "SITES=$(jq -c . < sites.json)" >> $GITHUB_ENV + - run: echo "SITES=$(jq -c . < sites.json)" >> $GITHUB_ENV - # doesn't work with "act" - name: Packages Changed id: changes with: @@ -24,12 +22,13 @@ jobs: deps: - 'package.json' sites: - - 'sites/**' + - 'sites/!(template/**)/**' packages: - 'packages/**' uses: dorny/paths-filter@v3 - name: Transform Sites Changed + id: transformed-changes run: | sites=() @@ -40,17 +39,20 @@ jobs: unique_sites=($(printf "%s\n" "${sites[@]}" | sort -u)) echo "SITES_CHANGED=${unique_sites[@]}" >> $GITHUB_ENV - echo "FILES_CHANGED=${{ steps.changes.outputs }}" >> $GITHUB_ENV - - - name: Inspect Packages Changed - run: | - echo "Outputs: ${{ toJSON(steps.changes.outputs) }}" - echo "Changes: ${{ steps.changes.outputs.changes }}" - echo "Packages Changed: ${{ steps.changes.outputs.sites_files }}" + # echo "DEPS_DID_CHANGE=${{ steps.changes.outputs.deps}}" >> $GITHUB_ENV + # echo "PACKAGES_DID_CHANGE=${{ steps.changes.outputs.packages}}" >> $GITHUB_ENV + # echo "SITES_DID_CHANGE=${{ steps.changes.outputs.sites}}" >> $GITHUB_ENV - name: Build Dynamic Matrix + if: ${{ steps.changes.outputs.sites }} id: matrix - run: node scripts/build_sites.mjs + run: | + if [[ ${{ steps.changes.outputs.packages }} == true ] || [ ${{ steps.changes.outputs.deps == true }} ]]; then + node scripts/build_matrix.mjs --all + else + node scripts/build_sites.mjs + fi + # 1. get the packages changed # 2. If the core package was changed, deploy all sites # 3. If only a certain site OR sites was changed, only deploy those sites. diff --git a/scripts/build_sites.mjs b/scripts/build_sites.mjs index b3d46c7..1bbea14 100644 --- a/scripts/build_sites.mjs +++ b/scripts/build_sites.mjs @@ -5,20 +5,29 @@ import { appendFileSync } from "node:fs"; import { argv, env, exit } from "node:process"; import * as os from "node:os"; -console.log("ENV IS", env); +const { SITES, SITES_CHANGED } = env; + try { - const SITES = env.SITES; + const [_node, _script, ...userArgs] = argv; + const doBuildAll = userArgs.some((arg) => arg === "--all"); if (!SITES) { throw new Error("Needs SITES set. Are you missing the sites.json file?"); } + const allSites = JSON.parse(SITES); + /** + * Core dependencies or a common package changed. + * Rebuild all sites. + * */ + if (DEPS_DID_CHANGE || PACKAGES_DID_CHANGE) { + } + /** * process.env.SITES is the user defined list of all sites. * * This is a key value pair where keys are the package name in the monorepo * and values are the corresponding project name for the website in Cloudflare * */ - const allSites = JSON.parse(SITES); for (const [key, value] of Object.entries(allSites)) { console.log({ key, value }); } diff --git a/scripts/new_site.mjs b/scripts/new_site.mjs index 218a6d5..53095f8 100755 --- a/scripts/new_site.mjs +++ b/scripts/new_site.mjs @@ -9,6 +9,14 @@ import { rimraf } from "rimraf"; import ora from "ora"; import Logger from "./utils/logger.mjs"; +// import { Command } from "commander"; + +// const program = new Command(); +// program +// .name("Build Matrix") +// .description("Script to build out the matrix of sites to deploy") +// .version("0.1.0") +// .option("-a, --all", "All sites"); const execP = promisify(exec);