Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
228 changes: 154 additions & 74 deletions .github/workflows/cloudflare-conditional-deploy.yml

Large diffs are not rendered by default.

337 changes: 337 additions & 0 deletions .github/workflows/cloudflare-conditional-deploy.yml.old
Original file line number Diff line number Diff line change
@@ -0,0 +1,337 @@
name: Cloudflare Conditional Deploy

on:
# Previews on PRs targeting gh-pages (Codex PRs)
pull_request:
types: [opened, synchronize, reopened]
branches:
- gh-pages
# Production branch pushes (no prod steps yet; safe to keep for later)
push:
branches:
- gh-pages

jobs:
detect-and-deploy:
name: Detect changes and deploy only touched apps
runs-on: ubuntu-latest

# Crucial: Ensure the workflow has permission to write comments and deployment statuses
permissions:
contents: read
deployments: write
pull-requests: write

# Auto-cancel older runs for the same PR/branch
concurrency:
group: cf-pages-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

# --- Change Detection Step (Retained your original logic) ---
- name: Determine changed files
id: changes
shell: bash
run: |
set -euo pipefail

echo "Determining changed files..."
if [ "${{ github.event_name }}" = "pull_request" ]; then
# Use GitHub context to get base SHA for better reliability
BASE_SHA="${{ github.event.pull_request.base.sha }}"
# Fetch base branch history if not fully available
git fetch origin "${{ github.event.pull_request.base.ref }}" --depth=1 || true
DIFF=$(git diff --name-only "$BASE_SHA"...HEAD) || true
else
BEFORE="${{ github.event.before }}"
AFTER="${{ github.sha }}"
if [[ "$BEFORE" =~ ^0+$ ]]; then
DIFF=$(git ls-files) || true
else
DIFF=$(git diff --name-only "$BEFORE" "$AFTER") || true
fi
fi

echo "Changed files:"
echo "$DIFF"

# Default outputs (false)
{
echo "library=false"
echo "hbnb=false"
echo "forces=false"
echo "gui=false"
echo "datro=false"
echo "projections=false"
echo "bpvsbuckler=false"
} >> "$GITHUB_OUTPUT"

# Detect changes in each app directory
if echo "$DIFF" | grep -qE '^static/library/'; then echo "library=true" >> "$GITHUB_OUTPUT"; fi
if echo "$DIFF" | grep -qE '^static/hbnb/'; then echo "hbnb=true" >> "$GITHUB_OUTPUT"; fi
if echo "$DIFF" | grep -qE '^static/forces/'; then echo "forces=true" >> "$GITHUB_OUTPUT"; fi
if echo "$DIFF" | grep -qE '^static/gui/'; then echo "gui=true" >> "$GITHUB_OUTPUT"; fi
if echo "$DIFF" | grep -qE '^static/datro/'; then echo "datro=true" >> "$GITHUB_OUTPUT"; fi
if echo "$DIFF" | grep -qE '^static/projections/'; then echo "projections=true" >> "$GITHUB_OUTPUT"; fi
if echo "$DIFF" | grep -qE '^static/bpvsbuckler/'; then echo "bpvsbuckler=true" >> "$GITHUB_OUTPUT"; fi

- name: Debug outputs
run: |
echo "library: ${{ steps.changes.outputs.library }}"
echo "hbnb: ${{ steps.changes.outputs.hbnb }}"
echo "forces: ${{ steps.changes.outputs.forces }}"
echo "gui: ${{ steps.changes.outputs.gui }}"
echo "datro: ${{ steps.changes.outputs.datro }}"
echo "projections: ${{ steps.changes.outputs.projections }}"
echo "bpvsbuckler: ${{ steps.changes.outputs.bpvsbuckler }}"

- name: Setup Node (for builds)
uses: actions/setup-node@v4
with:
node-version: '22' # or '20'

######################################################################
# PREVIEW DEPLOYS FOR PRs — IMPORTANT: IDs MUST BE SET TO CAPTURE URLS
######################################################################

# --- Library ---
- name: Build library
if: github.event_name == 'pull_request' && steps.changes.outputs.library == 'true'
run: |
if [ -f static/library/package.json ]; then
cd static/library
npm ci
npm run build --if-present
fi

- name: Deploy library (Preview)
if: github.event_name == 'pull_request' && steps.changes.outputs.library == 'true'
uses: andykenward/[email protected]
id: deploy_library # Capture output here
with:
cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
cloudflare-account-id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
cloudflare-project-name: library
directory: static/library
github-token: ${{ secrets.GITHUB_TOKEN }}
github-environment: library(preview)
# Set `add-comment: false` to avoid comment conflicts
add-comment: false

# --- HBNB ---
- name: Build hbnb
if: github.event_name == 'pull_request' && steps.changes.outputs.hbnb == 'true'
run: |
if [ -f static/hbnb/package.json ]; then
cd static/hbnb
npm ci
npm run build --if-present
fi

- name: Deploy hbnb (Preview)
if: github.event_name == 'pull_request' && steps.changes.outputs.hbnb == 'true'
uses: andykenward/[email protected]
id: deploy_hbnb # Capture output here
with:
cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
cloudflare-account-id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
cloudflare-project-name: hbnb
directory: static/hbnb
github-token: ${{ secrets.GITHUB_TOKEN }}
github-environment: hbnb(preview)
add-comment: false

# --- Forces/CEO ---
- name: Build forces (ceo)
if: github.event_name == 'pull_request' && steps.changes.outputs.forces == 'true'
run: |
if [ -f static/forces/package.json ]; then
cd static/forces
npm ci
npm run build --if-present
fi

- name: Deploy forces/ceo (Preview)
if: github.event_name == 'pull_request' && steps.changes.outputs.forces == 'true'
uses: andykenward/[email protected]
id: deploy_forces # Capture output here
with:
cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
cloudflare-account-id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
cloudflare-project-name: ceo
directory: static/forces
github-token: ${{ secrets.GITHUB_TOKEN }}
github-environment: ceo(preview)
add-comment: false

# --- GUI ---
- name: Build gui
if: github.event_name == 'pull_request' && steps.changes.outputs.gui == 'true'
run: |
if [ -f static/gui/package.json ]; then
cd static/gui
npm ci
npm run build --if-present
fi

- name: Deploy gui (Preview)
if: github.event_name == 'pull_request' && steps.changes.outputs.gui == 'true'
uses: andykenward/[email protected]
id: deploy_gui # Capture output here
with:
cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
cloudflare-account-id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
cloudflare-project-name: gui
directory: static/gui
github-token: ${{ secrets.GITHUB_TOKEN }}
github-environment: gui(preview)
add-comment: false

# --- DATRO-HOMEPAGE (The main app) ---
- name: Build datro-homepage
if: github.event_name == 'pull_request' && steps.changes.outputs.datro == 'true'
run: |
if [ -f static/datro/package.json ]; then
cd static/datro
npm ci
npm run build --if-present
fi

- name: Deploy datro-homepage (Preview)
if: github.event_name == 'pull_request' && steps.changes.outputs.datro == 'true'
uses: andykenward/[email protected]
id: deploy_datro # Capture output here
with:
cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
cloudflare-account-id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
cloudflare-project-name: datro-homepage
directory: static/datro
github-token: ${{ secrets.GITHUB_TOKEN }}
github-environment: datro(preview)
add-comment: false

# --- Projections ---
- name: Build projections
if: github.event_name == 'pull_request' && steps.changes.outputs.projections == 'true'
run: |
if [ -f static/projections/package.json ]; then
cd static/projections
npm ci
npm run build --if-present
fi

- name: Deploy projections (Preview)
if: github.event_name == 'pull_request' && steps.changes.outputs.projections == 'true'
uses: andykenward/[email protected]
id: deploy_projections # Capture output here
with:
cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
cloudflare-account-id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
cloudflare-project-name: projections
directory: static/projections
github-token: ${{ secrets.GITHUB_TOKEN }}
github-environment: projections(preview)
add-comment: false

# --- BPVSBuckler ---
- name: Build bpvsbuckler
if: github.event_name == 'pull_request' && steps.changes.outputs.bpvsbuckler == 'true'
run: |
if [ -f static/bpvsbuckler/package.json ]; then
cd static/bpvsbuckler
npm ci
npm run build --if-present
fi

- name: Deploy bpvsbuckler (Preview)
if: github.event_name == 'pull_request' && steps.changes.outputs.bpvsbuckler == 'true'
uses: andykenward/[email protected]
id: deploy_bpvsbuckler # Capture output here
with:
cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
cloudflare-account-id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
cloudflare-project-name: bpvsbuckler
directory: static/bpvsbuckler
github-token: ${{ secrets.GITHUB_TOKEN }}
github-environment: bpvsbuckler(preview)
add-comment: false

# --- FINAL AGGREGATION AND COMMENT STEP ---
- name: Post Consolidated Preview Comment
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const appUrls = [
{ name: 'library', id: 'deploy_library', changed: '${{ steps.changes.outputs.library }}' },
{ name: 'hbnb', id: 'deploy_hbnb', changed: '${{ steps.changes.outputs.hbnb }}' },
{ name: 'ceo (forces)', id: 'deploy_forces', changed: '${{ steps.changes.outputs.forces }}' },
{ name: 'gui', id: 'deploy_gui', changed: '${{ steps.changes.outputs.gui }}' },
{ name: 'datro-homepage', id: 'deploy_datro', changed: '${{ steps.changes.outputs.datro }}' },
{ name: 'projections', id: 'deploy_projections', changed: '${{ steps.changes.outputs.projections }}' },
{ name: 'bpvsbuckler', id: 'deploy_bpvsbuckler', changed: '${{ steps.changes.outputs.bpvsbuckler }}' },
];

let commentBody = '## 🚀 Cloudflare Pages Preview Deployments\n\n| Application | Status | Preview URL |\n| :--- | :--- | :--- |\n';
let deployedCount = 0;

for (const app of appUrls) {
const url = process.env[`STEPS_${app.id.toUpperCase()}_OUTPUTS_DEPLOYMENT_URL`];
const isDeployed = url && url !== 'null';
const status = isDeployed ? '✅ Deployed' : (app.changed === 'true' ? '❌ Failed' : '🚫 Skipped');
const link = isDeployed ? `[${url}](${url})` : 'N/A';

commentBody += `| ${app.name} | ${status} | ${link} |\n`;
if (isDeployed) {
deployedCount++;
}
}

commentBody += `\n**Total Deployed:** ${deployedCount} applications.`;

// If we are in a PR, post the comment.
if (context.payload.pull_request) {
// Create a unique comment header to allow replacing the comment on subsequent runs
const commentIdentifier = '<!-- Cloudflare Pages Preview Comment -->';
commentBody = commentIdentifier + '\n' + commentBody;

const issue_number = context.issue.number;
const { data: comments } = await github.rest.issues.listComments({
issue_number,
owner: context.repo.owner,
repo: context.repo.repo,
});

const existingComment = comments.find(c => c.body.includes(commentIdentifier));

if (existingComment) {
await github.rest.issues.updateComment({
comment_id: existingComment.id,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
} else {
await github.rest.issues.createComment({
issue_number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
}
}
env:
# Pass outputs as environment variables (requires specific formatting)
STEPS_DEPLOY_LIBRARY_OUTPUTS_DEPLOYMENT_URL: ${{ steps.deploy_library.outputs.deployment-url }}
STEPS_DEPLOY_HBNB_OUTPUTS_DEPLOYMENT_URL: ${{ steps.deploy_hbnb.outputs.deployment-url }}
STEPS_DEPLOY_FORCES_OUTPUTS_DEPLOYMENT_URL: ${{ steps.deploy_forces.outputs.deployment-url }}
STEPS_DEPLOY_GUI_OUTPUTS_DEPLOYMENT_URL: ${{ steps.deploy_gui.outputs.deployment-url }}
STEPS_DEPLOY_DATRO_OUTPUTS_DEPLOYMENT_URL: ${{ steps.deploy_datro.outputs.deployment-url }}
STEPS_DEPLOY_PROJECTIONS_OUTPUTS_DEPLOYMENT_URL: ${{ steps.deploy_projections.outputs.deployment-url }}
STEPS_DEPLOY_BPVSBUCKLER_OUTPUTS_DEPLOYMENT_URL: ${{ steps.deploy_bpvsbuckler.outputs.deployment-url }}

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

## [0.0.1-rtw.17] - Q4/2025
Nov-13 - Trying something/ Trying something else / Trying something else else
Nov-12 - Added `cloudflare-conditional-deploy.yml` to new top level directory .github/workflow `so preview links can be generated on pull requests'
Nov-09 - DATRO was previously soley the tech. Now it's expanding as a security group, tech being one of multiple arms of the security group
Oct-28 - Added a timeline with a nice menu /static/timeline - hoping to build this feature out
Expand Down
1 change: 1 addition & 0 deletions static/datro/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Introduction

Minor Edit.
This is the DATRO homepage. Currently hosted on the URL https://datro.xyz
See the corresponding CHANGELOG.md for a log of all the latest developments.
See the corresponding COLLABORATE.md for guidance on maintaining this website.
Expand Down
1 change: 1 addition & 0 deletions view.txt

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions view2.txt

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions view3

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions view4

Large diffs are not rendered by default.

Loading