Skip to content

Commit

Permalink
debug: test deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmcguin committed Aug 22, 2024
1 parent 5008872 commit d984634
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 78 deletions.
43 changes: 18 additions & 25 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# - 'sites/!(template/**)/**'
on:
push:
branches: [main, dynamic-matrix]
Expand All @@ -25,7 +24,7 @@ jobs:
deps:
- 'package.json'
sites:
- 'sites/**'
- 'sites/!(template/**)/**'
packages:
- 'packages/**'
uses: dorny/paths-filter@v3
Expand All @@ -52,10 +51,10 @@ jobs:
id: matrix
run: |
if [[ ${{ steps.changes.outputs.packages }} == true ]] || [[ ${{ steps.changes.outputs.deps }} == true ]]; then
node ./scripts/build_sites.mjs --all
node ./scripts/build_matrix.mjs --all
echo "continue=true" >> $GITHUB_OUTPUT
elif [[ ${{ steps.changes.outputs.sites }} == true ]]; then
node ./scripts/build_sites.mjs
node ./scripts/build_matrix.mjs
echo "continue=true" >> $GITHUB_OUTPUT
else
# successful step, but do not continue with a deployment
Expand All @@ -75,25 +74,19 @@ jobs:
deployments: write

steps:
- name: Debug
run: |
echo "preparing to deploy:"
echo "Package: ${{ matrix.project }}"
echo "Project: ${{ matrix.package }}"
- name: Checkout
uses: actions/checkout@v3

# - name: Checkout
# uses: actions/checkout@v3
#
# - name: Install Dependencies
# run: npm ci --omit=dev
#
# - name: Build
# run: npm run build -w ./sites/${{ matrix.package }}
#
# - name: Publish to Cloudflare Pages
# uses: cloudflare/pages-action@v1
# with:
# apiToken: ${{ secrets.DEPLOY_TOKEN }}
# accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
# projectName: ${{ matrix.project }}
# directory: ./sites/${{ matrix.package }}/dist
- name: Install Dependencies
run: npm ci --omit=dev

- name: Build
run: npm run build -w ./sites/${{ matrix.package }}

- name: Publish to Cloudflare Pages
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.DEPLOY_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: ${{ matrix.project }}
directory: ./sites/${{ matrix.package }}/dist
54 changes: 54 additions & 0 deletions scripts/build_matrix.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* This script is used to build out the matrix that is the input
* to the publish job.
* */
import { appendFileSync } from "node:fs";
import { argv, env, exit } from "node:process";
import * as os from "node:os";

const { SITES, SITES_CHANGED } = env;

try {
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);
if (doBuildAll) {
deploy(allSites);
exit(0);
} else {
if (!SITES_CHANGED || SITES_CHANGED === "") {
throw new Error("SITES_CHANGED is not set");
}

deploy(reduceSites(allSites, SITES_CHANGED));
exit(0);
}
} catch (error) {
console.error("Error building sites", error);
exit(1);
}

function deploy(sites) {
let matrix = { include: [] };
for (const [key, value] of Object.entries(sites)) {
matrix.include.push({ package: key, project: value });
}
appendFileSync(
process.env.GITHUB_OUTPUT,
`matrix=${JSON.stringify(matrix)}${os.EOL}`
);
}

function reduceSites(allSites, sitesChanged) {
return Object.entries(allSites).reduce((accum, [pkg, project]) => {
if (sitesChanged.includes(pkg)) {
accum["package"] = pkg;
accum["project"] = project;
}
return accum;
}, {});
}
53 changes: 0 additions & 53 deletions scripts/build_sites.mjs

This file was deleted.

0 comments on commit d984634

Please sign in to comment.