Skip to content

Commit

Permalink
with global defaults
Browse files Browse the repository at this point in the history
deploy
  • Loading branch information
trueberryless committed Nov 19, 2024
1 parent 038e20b commit 4a09eeb
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 31 deletions.
40 changes: 18 additions & 22 deletions .github/workflows/sync.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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..."
Expand Down
18 changes: 15 additions & 3 deletions repos.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
9 changes: 4 additions & 5 deletions workflow-files/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
2 changes: 1 addition & 1 deletion workflow-files/welcome-bot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: WelcomeBot

on:
pull_request_target:
branches: [main]
branches: [<%= baseBranch %>]
types: [opened]

permissions:
Expand Down

0 comments on commit 4a09eeb

Please sign in to comment.