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
44 changes: 41 additions & 3 deletions .github/workflows/deploy-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ jobs:
- name: Install dependencies
run: yarn --prefer-offline

- name: Check build-all label
if: contains(github.event.pull_request.labels.*.name, 'build-all')
run: echo "BUILD_ALL=true" >> $GITHUB_ENV

- name: Include netsec
if: contains(github.event.pull_request.labels.*.name, 'netsec')
run: |
Expand All @@ -138,7 +142,7 @@ jobs:
else
echo "PRODUCTS_INCLUDE=cdss,threat-vault,dns-security,iot,expedition,cloudngfw,cdl,panos,terraform,ansible,splunk,aiops-ngfw-bpa,email-dlp,dlp,prisma-airs" >> $GITHUB_ENV
fi

- name: Include cloud
if: contains(github.event.pull_request.labels.*.name, 'cloud')
run: |
Expand All @@ -148,7 +152,7 @@ jobs:
else
echo "PRODUCTS_INCLUDE=prisma-cloud,compute" >> $GITHUB_ENV
fi

- name: Include sase
if: contains(github.event.pull_request.labels.*.name, 'sase')
run: |
Expand All @@ -158,7 +162,7 @@ jobs:
else
echo "PRODUCTS_INCLUDE=sase,access,sdwan,scm" >> $GITHUB_ENV
fi

- name: Include contributing
if: contains(github.event.pull_request.labels.*.name, 'contributing')
run: |
Expand All @@ -169,10 +173,44 @@ jobs:
echo "PRODUCTS_INCLUDE=contributing" >> $GITHUB_ENV
fi

- name: Determine changed products
if: env.BUILD_ALL != 'true' && !contains(github.event.pull_request.labels.*.name, 'netsec') && !contains(github.event.pull_request.labels.*.name, 'cloud') && !contains(github.event.pull_request.labels.*.name, 'sase') && !contains(github.event.pull_request.labels.*.name, 'contributing')
id: products
run: |
PRODUCTS=$(node scripts/get-changed-products.js)
if [ -n "$PRODUCTS" ]; then
echo "PRODUCTS_INCLUDE=$PRODUCTS" >> $GITHUB_ENV
fi
env:
BASE_REF: ${{ github.event.pull_request.base.sha }}
HEAD_REF: ${{ github.event.pull_request.head.sha }}

- name: Set default products
if: env.BUILD_ALL != 'true' && env.PRODUCTS_INCLUDE == ''
run: echo "PRODUCTS_INCLUDE=contributing" >> $GITHUB_ENV

- name: Output final PRODUCTS_INCLUDE
run: |
echo "Building the following products: $PRODUCTS_INCLUDE"

- name: Inform about selective build
if: github.event.action == 'opened'
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const products = process.env.PRODUCTS_INCLUDE || 'contributing';
const body = [
`Selective build for **${products}**.`,
'',
'Add the **build-all** label to build the entire site.',
'Add group labels like **netsec**, **cloud**, **sase**, or **contributing** to build specific docs.',
].join('\n');
await github.rest.issues.createComment({
...context.issue,
body,
});

- name: Build site
run: yarn build-github

Expand Down
66 changes: 66 additions & 0 deletions scripts/get-changed-products.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const { execSync } = require("child_process");
const fs = require("fs");
const path = require("path");

const base = process.env.BASE_REF || "origin/master";
const head = process.env.HEAD_REF || "HEAD";

function getChangedFiles() {
try {
const output = execSync(`git diff --name-only ${base} ${head}`, {
encoding: "utf8",
});
return output.trim().split("\n").filter(Boolean);
} catch (err) {
console.error("Failed to get changed files", err);
return [];
}
}

function resolveProducts(files) {
const products = new Set();
for (const file of files) {
const match = file.match(/^products\/([^\/]+)/);
if (match) products.add(match[1]);
}
return products;
}

function readSidebars(product) {
const sidebarFiles = [
path.join("products", product, "sidebars.ts"),
path.join("products", product, "sidebars.js"),
];
for (const file of sidebarFiles) {
if (fs.existsSync(file)) {
try {
return fs.readFileSync(file, "utf8");
} catch (_) {
return "";
}
}
}
return "";
}

function addSidebarDeps(product, products) {
const content = readSidebars(product);
if (!content) return;
const regex = /['"`]([a-z-]+)\/docs\//g;
let match;
while ((match = regex.exec(content))) {
const dep = match[1];
if (!products.has(dep)) {
products.add(dep);
addSidebarDeps(dep, products);
}
}
}

const changedFiles = getChangedFiles();
const products = resolveProducts(changedFiles);
for (const p of Array.from(products)) {
addSidebarDeps(p, products);
}

console.log(Array.from(products).join(","));