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
37 changes: 20 additions & 17 deletions .github/scripts/validate-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ npm i -g ajv-cli

echo "### Validating JSON Schema" >> $GITHUB_STEP_SUMMARY

# Capture output without exiting on failure
AJV_OUTPUT=$(ajv validate -s "$SCHEMA_FILE" -d "$CONFIG_FILE" --all-errors 2>&1 || true)

if [[ "$AJV_OUTPUT" != *"valid"* ]]; then
# Capture output and fail on non-zero exit
if ! AJV_OUTPUT=$(ajv validate -s "$SCHEMA_FILE" -d "$CONFIG_FILE" --all-errors 2>&1); then
echo "$AJV_OUTPUT" # Show in logs

echo "::error file=$CONFIG_FILE,title=Schema Validation Failed::${AJV_OUTPUT//$'\n'/ }"
Expand All @@ -43,23 +41,28 @@ fi
echo "✅ Schema validation passed" >> $GITHUB_STEP_SUMMARY

# 2. Check version was incremented
PR_VERSION=$(jq -r '.version' $CONFIG_FILE)
MAIN_VERSION=$(git show origin/$MAIN_BRANCH:$CONFIG_FILE | jq -r '.version')

echo "### Version Check" >> $GITHUB_STEP_SUMMARY
echo "Main: v$MAIN_VERSION → PR: v$PR_VERSION" >> $GITHUB_STEP_SUMMARY

if [ "$PR_VERSION" -le "$MAIN_VERSION" ]; then
echo "::error file=$CONFIG_FILE,title=Version Not Incremented::Version must be incremented. Main=$MAIN_VERSION, PR=$PR_VERSION"
if git diff --name-only origin/$MAIN_BRANCH...HEAD | grep -Fx "$CONFIG_FILE" >/dev/null; then
PR_VERSION=$(jq -r '.version' $CONFIG_FILE)
MAIN_VERSION=$(git show origin/$MAIN_BRANCH:$CONFIG_FILE | jq -r '.version')

echo "❌ **Version not incremented!**" >> $GITHUB_STEP_SUMMARY
echo "Main: v$MAIN_VERSION → PR: v$PR_VERSION" >> $GITHUB_STEP_SUMMARY

echo "VALIDATION_ERROR=version" >> $GITHUB_ENV
echo "ERROR_MESSAGE=Version must be incremented! Main branch has version $MAIN_VERSION, your PR has version $PR_VERSION" >> $GITHUB_ENV
exit 1
fi
if [ "$PR_VERSION" -le "$MAIN_VERSION" ]; then
echo "::error file=$CONFIG_FILE,title=Version Not Incremented::Version must be incremented. Main=$MAIN_VERSION, PR=$PR_VERSION"

echo "✅ Version correctly incremented" >> $GITHUB_STEP_SUMMARY
echo "❌ **Version not incremented!**" >> $GITHUB_STEP_SUMMARY

echo "VALIDATION_ERROR=version" >> $GITHUB_ENV
echo "ERROR_MESSAGE=Version must be incremented! Main branch has version $MAIN_VERSION, your PR has version $PR_VERSION" >> $GITHUB_ENV
exit 1
fi

echo "✅ Version correctly incremented" >> $GITHUB_STEP_SUMMARY
else
echo "Config file unchanged in this PR; skipping version check." >> $GITHUB_STEP_SUMMARY
fi

# 3. Check all rule references exist
echo "### Rule Reference Check" >> $GITHUB_STEP_SUMMARY
Expand Down Expand Up @@ -98,4 +101,4 @@ fi

echo "✅ All rule references are valid" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### ✅ All validations passed!" >> $GITHUB_STEP_SUMMARY
echo "### ✅ All validations passed!" >> $GITHUB_STEP_SUMMARY
112 changes: 91 additions & 21 deletions .github/workflows/macos-PR-to-staging.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,102 @@
name: PR to staging (macOS)

on:
push:
paths:
- 'live/macos-config/macos-config.json'
pull_request:
types:
- opened
paths:
- 'live/macos-config/macos-config.json'
- 'schemas/macos/schema.json'

env:
CONFIG_FILE: 'live/macos-config/macos-config.json'
SCHEMA_FILE: 'schemas/macos/schema.json'

jobs:
validate:
name: Validate Config
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-node@v4
with:
node-version: '20'

- name: Validate JSON and check version
id: validate
run: ./.github/scripts/validate-config.sh "$CONFIG_FILE" "$SCHEMA_FILE" main

- name: Comment PR with error details
if: failure()
uses: actions/github-script@v7
with:
script: |
const errorType = process.env.VALIDATION_ERROR;
const errorMessage = process.env.ERROR_MESSAGE;

let title = '### ❌ Validation Failed\n\n';
let body = '';

switch(errorType) {
case 'schema':
body = `**JSON Schema Validation Error**\n\n`;
body += 'Your JSON file does not match the required schema:\n\n';
body += '```\n' + errorMessage + '\n```\n\n';
body += '**How to fix:**\n';
body += '1. Check the error message above\n';
body += `2. Validate locally: \`ajv validate -s ${process.env.SCHEMA_FILE} -d ${process.env.CONFIG_FILE}\`\n`;
break;

case 'version':
body = `**Version Not Incremented**\n\n`;
body += '⚠️ ' + errorMessage + '\n\n';
body += '**How to fix:**\n';
body += 'Increment the version number in the JSON config file\n';
break;

case 'rules':
body = `**Invalid Rule References**\n\n`;
body += 'Some messages reference rule IDs that don\'t exist:\n\n';
body += '```\n' + errorMessage + '\n```\n\n';
body += '**How to fix:**\n';
body += '1. Check the rule IDs in your matchingRules/exclusionRules\n';
body += '2. Ensure all referenced rules exist in the rules array\n';
break;
}

await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: title + body
});

publish:
name: Publish to Staging
needs: validate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: jakejarvis/s3-sync-action@7ed8b112447abb09f1da74f3466e4194fc7a6311
if: github.event_name == 'push'
with:
args: --acl public-read --follow-symlinks
env:
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
SOURCE_DIR: 'live/macos-config'
DEST_DIR: 'remotemessaging/config/staging'
- uses: github-actions-up-and-running/pr-comment@f1f8ab2bf00dce6880a369ce08758a60c61d6c0b
if: github.event.action == 'opened'
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
message: 'Your PR is hosted at https://staticcdn.duckduckgo.com/remotemessaging/config/staging/macos-config.json'
- uses: actions/checkout@v4

- name: Sync to S3 staging
uses: jakejarvis/s3-sync-action@7ed8b112447abb09f1da74f3466e4194fc7a6311
with:
args: --acl public-read --follow-symlinks
env:
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
SOURCE_DIR: 'live/macos-config'
DEST_DIR: 'remotemessaging/config/staging'

- name: Comment on PR with staging URL
uses: github-actions-up-and-running/pr-comment@f1f8ab2bf00dce6880a369ce08758a60c61d6c0b
if: github.event.action == 'opened'
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
message: |
✅ Config validation passed!

Your PR config is hosted at:
https://staticcdn.duckduckgo.com/remotemessaging/config/staging/macos-config.json
6 changes: 5 additions & 1 deletion schemas/ios/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,11 @@
"duckPlayerEnabled": { "$ref": "#/definitions/SingleValueBooleanAttribute" },
"messageShown": { "$ref": "#/definitions/SingleValueStringArrayAttribute" },
"isCurrentFreemiumPIRUser": { "$ref": "#/definitions/SingleValueBooleanAttribute" },
"allFeatureFlagsEnabled": { "$ref": "#/definitions/SingleValueStringArrayAttribute" }
"allFeatureFlagsEnabled": { "$ref": "#/definitions/SingleValueStringArrayAttribute" },
"subscriptionFreeTrialActive": { "$ref": "#/definitions/SingleValueBooleanAttribute" },
"syncEnabled": { "$ref": "#/definitions/SingleValueBooleanAttribute" },
"shouldShowWinBackOfferUrgencyMessage": { "$ref": "#/definitions/SingleValueBooleanAttribute" },
"daysSinceDuckAiUsed": { "$ref": "#/definitions/NumericRangeAttribute" }
},
"additionalProperties": false
}
Expand Down
8 changes: 8 additions & 0 deletions schemas/macos/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Install

* `brew install node`
* `npm install -g ajv-cli`

## Run

* `ajv validate -s schema.json -d ../../live/macos-config/macos-config.json`
Loading