diff --git a/.github/workflows/sync.yaml b/.github/workflows/sync.yaml index d7973e4..1998aff 100644 --- a/.github/workflows/sync.yaml +++ b/.github/workflows/sync.yaml @@ -97,28 +97,24 @@ jobs: # Prepare the destination directory mkdir -p "$(dirname "$dest_file")" - # Handle dynamic content replacement if "props" is specified - props=$(echo "$file_config" | jq -c '.props // empty') - if [ -n "$props" ]; then - echo "Applying dynamic replacements for $src_file..." - temp_file=$(mktemp) - cp "../$src_file" "$temp_file" - - # Replace placeholders with their respective values from props - for key in $(echo "$props" | jq -r 'keys[]'); do - value=$(echo "$props" | jq -r --arg key "$key" '.[$key]') - placeholder="<%= $key %>" - echo "Replacing $placeholder with $value in $src_file..." - sed -i "s|$placeholder|$value|g" "$temp_file" - done - - # Move the processed file to the target location - mv "$temp_file" "$dest_file" - else - # If no props, copy the file directly - cp "../$src_file" "$dest_file" - fi - done + # Merge global defaults with file-specific props + file_props=$(echo "$file_config" | jq -c '.props // {}') + merged_props=$(jq -c --argjson defaults "$global_defaults" --argjson fileProps "$file_props" '.defaults * .fileProps' <<<"{\"defaults\": $global_defaults, \"fileProps\": $file_props}") + + # Handle dynamic content replacement + temp_file=$(mktemp) + cp "../$src_file" "$temp_file" + + # Replace placeholders with their respective values + for key in $(echo "$merged_props" | jq -r 'keys[]'); do + value=$(echo "$merged_props" | jq -r --arg key "$key" '.[$key]') + placeholder="<%= $key %>" + echo "Replacing $placeholder with $value in $src_file..." + sed -i "s|$placeholder|$value|g" "$temp_file" + done + + # Move the processed file to the target location + mv "$temp_file" "$dest_file" # Commit and push changes if any echo "Checking for changes..." diff --git a/repos.json b/repos.json index 3f4fb1d..d205e69 100644 --- a/repos.json +++ b/repos.json @@ -5,16 +5,28 @@ "files": [ { "path": "workflow-files/welcome-bot.yaml", - "targetPath": ".github/workflows/welcome-bot.yaml" + "targetPath": ".github/workflows/welcome-bot.yaml", + "props": { + "baseBranch": "main" + } }, { "path": "workflow-files/release.yaml", "targetPath": ".github/workflows/release.yaml", "props": { - "branchName": "main" + "baseBranch": "main", + "organisation": "trueberryless-org", + "commitMessage": "[ci] release", + "prTitle": "[ci] release" } } ] } - ] + ], + "defaults": { + "baseBranch": "main", + "organisation": "trueberryless-org", + "commitMessage": "[ci] release", + "prTitle": "[ci] release" + } } diff --git a/workflow-files/release.yaml b/workflow-files/release.yaml index 207f9e7..ba0ea71 100644 --- a/workflow-files/release.yaml +++ b/workflow-files/release.yaml @@ -2,13 +2,12 @@ name: Release on: push: - branches: - - <%= branchName %> + branches: [<%= baseBranch %>] jobs: release: name: Release - if: ${{ github.repository_owner == 'trueberryless-org' }} + if: ${{ github.repository_owner == '<%= organisation %>' }} permissions: contents: write pull-requests: write @@ -35,7 +34,7 @@ jobs: uses: changesets/action@v1 with: version: pnpm run version - commit: "[ci] release" - title: "[ci] release" + commit: "<%= commitMessage %>" + title: "<%= prTitle %>" env: GITHUB_TOKEN: ${{ secrets.PUBLIC_GITHUB_TOKEN }} diff --git a/workflow-files/welcome-bot.yaml b/workflow-files/welcome-bot.yaml index 19b53ba..7444923 100644 --- a/workflow-files/welcome-bot.yaml +++ b/workflow-files/welcome-bot.yaml @@ -2,7 +2,7 @@ name: WelcomeBot on: pull_request_target: - branches: [main] + branches: [<%= baseBranch %>] types: [opened] permissions: