Skip to content
Open
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
50 changes: 50 additions & 0 deletions .github/scripts/generate-demo-matrix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash
# Generate a matrix of demo directories for GitHub Actions
# Usage: generate-demo-matrix.sh <platform> <event_name> [base_sha]
# Example: generate-demo-matrix.sh android pull_request abc123

set -e
shopt -s nullglob # Make globs expand to nothing if no matches

PLATFORM="$1"
EVENT_NAME="$2"
BASE_SHA="$3"

if [ -z "$PLATFORM" ] || [ -z "$EVENT_NAME" ]; then
echo "Usage: $0 <platform> <event_name> [base_sha]" >&2
exit 1
fi

DEMO_PATH="demos/${PLATFORM}"

if [ "$EVENT_NAME" = "pull_request" ]; then
if [ -z "$BASE_SHA" ]; then
echo "Error: base_sha is required for pull_request events" >&2
exit 1
fi

# Get list of changed files in demos/<platform>/ directory
changed_files=$(git diff --name-only "$BASE_SHA" HEAD -- "${DEMO_PATH}/*")

echo "Changed files:" >&2
echo "$changed_files" >&2

# Extract unique demo directories
matrix=$(echo "$changed_files" | grep -oE "${DEMO_PATH}/[^/]*/MASTG-DEMO-[^/]+" | sort -u | head -c -1 | tr '\n' ' ' | sed 's/ /","/g')

# If no changes, set empty matrix
if [ -z "$matrix" ]; then
echo '{"demo":[]}'
else
echo "{\"demo\":[\"$matrix\"]}"
fi
else
# Default behavior: include all demos for master branch
demos=(${DEMO_PATH}/*/MASTG-DEMO-*)
if [ ${#demos[@]} -eq 0 ]; then
echo '{"demo":[]}'
else
matrix=$(printf '%s\n' "${demos[@]}" | sed 's/.*/"&"/' | paste -sd, -)
echo "{\"demo\":[$matrix]}"
fi
fi
32 changes: 6 additions & 26 deletions .github/workflows/build-android-demos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ on:
- master
paths:
- 'demos/**'
- '.github/workflows/build-android-demos.yml'

jobs:
generate-matrix:
Expand All @@ -23,36 +22,17 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
with:
sparse-checkout: demos/android
sparse-checkout: |
demos/android
.github/scripts
fetch-depth: 2 # Required for git diff in PRs

- name: Generate matrix
id: set-matrix
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
# Get list of changed files in demos/android/ directory
changed_files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} HEAD -- 'demos/android/*')

echo "Changed files:"
echo "$changed_files"

# Extract unique demo directories
matrix=$(echo "$changed_files" | grep -oE 'demos/android/[^/]*/MASTG-DEMO-[^/]+' | sort -u | head -c -1 | tr '\n' ' ' | sed 's/ /","/g')

# If no changes, set empty matrix
if [ -z "$matrix" ]; then
echo "matrix={\"demo\":[]}" >> $GITHUB_OUTPUT
else
echo "matrix={\"demo\":[\"$matrix\"]}" >> $GITHUB_OUTPUT
fi
else
# Default behavior: include all demos for master branch
matrix=$(echo demos/android/*/MASTG-DEMO-* | sed 's/ /","/g')
echo "matrix={\"demo\":[\"$matrix\"]}" >> $GITHUB_OUTPUT
fi
echo "Print matrix: $matrix"
- name: Print matrix
run: echo "${{ steps.set-matrix.outputs.matrix }}"
matrix=$(.github/scripts/generate-demo-matrix.sh android "${{ github.event_name }}" "${{ github.event.pull_request.base.sha }}")
echo "matrix=$matrix" >> $GITHUB_OUTPUT
echo "Generated matrix: $matrix"

build-base-app:
runs-on: ubuntu-latest
Expand Down
31 changes: 7 additions & 24 deletions .github/workflows/build-ios-demos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
- master
paths:
- 'demos/**'
- '.github/workflows/build-ios-demos.yml'

jobs:
generate-matrix:
runs-on: ubuntu-latest
Expand All @@ -22,34 +22,17 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
with:
sparse-checkout: demos/ios
sparse-checkout: |
demos/ios
.github/scripts
fetch-depth: 2 # Required for git diff in PRs

- name: Generate matrix
id: set-matrix
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
# Get list of changed files in demos/ios/ directory
changed_files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} HEAD -- 'demos/ios/*')

echo "Changed files:"
echo "$changed_files"

# Extract unique demo directories
matrix=$(echo "$changed_files" | grep -oE 'demos/ios/[^/]*/MASTG-DEMO-[^/]+' | sort -u | head -c -1 | tr '\n' ' ' | sed 's/ /","/g')

# If no changes, set empty matrix
if [ -z "$matrix" ]; then
echo "matrix={\"demo\":[]}" >> $GITHUB_OUTPUT
else
echo "matrix={\"demo\":[\"$matrix\"]}" >> $GITHUB_OUTPUT
fi
else
# Default behavior: include all demos for master branch
matrix=$(echo demos/ios/*/MASTG-DEMO-* | sed 's/ /","/g')
echo "matrix={\"demo\":[\"$matrix\"]}" >> $GITHUB_OUTPUT
fi
echo "Print matrix: $matrix"
matrix=$(.github/scripts/generate-demo-matrix.sh ios "${{ github.event_name }}" "${{ github.event.pull_request.base.sha }}")
echo "matrix=$matrix" >> $GITHUB_OUTPUT
echo "Generated matrix: $matrix"

build:
needs: generate-matrix
Expand Down
56 changes: 28 additions & 28 deletions .github/workflows/check-duplicate-ids.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,83 +13,83 @@ on:
jobs:
check-duplicates:
runs-on: ubuntu-latest

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

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Get new files in PR
id: get-new-files
run: |
# Get the base branch ref from the PR event
BASE_REF="${{ github.event.pull_request.base.ref }}"
echo "Base branch is: $BASE_REF"

# Fetch the base branch to ensure it's available locally
git fetch origin $BASE_REF

# Create a file with the list of new files in this PR
git diff --name-status --diff-filter=A origin/$BASE_REF..HEAD | grep -E "^A\s+(apps/|best-practices/|demos/|tests-beta/|tools/|techniques/)" | cut -f2 > new_files_in_pr.txt || echo "No new files matching the pattern"

echo "New files in PR:"
cat new_files_in_pr.txt

# Ensure the file exists even if empty
touch new_files_in_pr.txt

- name: Check for duplicate file IDs
id: check-duplicates
run: |
python .github/scripts/check_duplicate_ids.py

- name: Delete previous comments and comment on PR if duplicates found
if: always()
uses: actions/github-script@v6
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');

// Helper function to format a notification message
const formatDuplicateMessage = (duplicate, isReviewComment = true) => {
// Extract the ID prefix for a more specific message
let idType = duplicate.file_id.split('-').slice(0, 2).join('-');

// Choose the appropriate header style based on comment type
const headerPrefix = isReviewComment ? '###' : '##';

return `
${headerPrefix} ⚠️ Duplicate \`${idType}\` ID Detected

${isReviewComment ? 'This file' : `File \`${duplicate.file_path}\``} has the ID \`${duplicate.file_id}\` which already exists in \`${duplicate.existing_path}\`.

**IMPORTANT:** Please use the next available ID: \`${duplicate.suggested_id}\`
`;
};

// Step 1: Try to clean up existing comments
try {
const comments = await github.rest.pulls.listReviewComments({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});

// Filter for comments from this action
const ourComments = comments.data.filter(comment =>
comment.body.includes('⚠️ Duplicate') &&
const ourComments = comments.data.filter(comment =>
comment.body.includes('⚠️ Duplicate') &&
comment.body.includes('ID Detected')
);

console.log(`Found ${ourComments.length} previous comments from this action.`);

// Delete the comments
for (const comment of ourComments) {
try {
Expand All @@ -107,18 +107,18 @@ jobs:
console.log(`Error handling existing comments: ${error.message}`);
// Continue with the workflow regardless of errors with existing comments
}

// Step 2: Check if we need to post new notifications
const hasDuplicatesOutput = '${{ steps.check-duplicates.outputs.has_duplicates }}';

if (hasDuplicatesOutput !== 'true' || !fs.existsSync('duplicate_files.json')) {
console.log('No duplicates to report.');
return;
}

// Step 3: Post notifications for each duplicate
const duplicatesData = JSON.parse(fs.readFileSync('duplicate_files.json', 'utf8'));

for (const duplicate of duplicatesData) {
// First try posting a review comment (preferred method)
try {
Expand All @@ -135,7 +135,7 @@ jobs:
console.log(`Successfully posted review comment for ${duplicate.file_path}`);
} catch (error) {
console.log(`Error posting review comment: ${error.message}`);

// Fallback: post a comment on the PR thread instead of as a review comment
try {
await github.rest.issues.createComment({
Expand All @@ -149,4 +149,4 @@ jobs:
console.log(`Error posting fallback PR thread comment: ${fallbackError.message}`);
}
}
}
}
12 changes: 0 additions & 12 deletions .github/workflows/check-website-build.yml

This file was deleted.

27 changes: 27 additions & 0 deletions .github/workflows/main-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Main Branch Checks

on:
workflow_dispatch:
push:
branches:
- master

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
spell-check:
name: Spell Check (Full)
uses: ./.github/workflows/reusable-spell-checker.yml
secrets: inherit

url-check:
name: URL Check (Full)
uses: ./.github/workflows/reusable-url-checker.yml
secrets: inherit

markdown-lint:
name: Markdown Lint
uses: ./.github/workflows/reusable-markdown-linter.yml
secrets: inherit
36 changes: 36 additions & 0 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: PR Checks

on:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
spell-check:
name: Spell Check (Changed Files)
uses: ./.github/workflows/reusable-spell-checker.yml
secrets: inherit
with:
check_modified_files_only: true
pr_number: ${{ github.event.pull_request.number }}

url-check:
name: URL Check (Changed Files)
uses: ./.github/workflows/reusable-url-checker.yml
secrets: inherit
with:
check_modified_files_only: true

markdown-lint:
name: Markdown Lint
uses: ./.github/workflows/reusable-markdown-linter.yml
secrets: inherit

website-build:
name: Website Build Check
uses: ./.github/workflows/reusable-website-build-checker.yml
secrets: inherit
with:
pr_number: ${{ github.event.pull_request.number }}
Loading
Loading