-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Create Package Script Artifact | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
workflow_dispatch: # Allows manual triggering | ||
|
||
jobs: | ||
create-artifact: | ||
runs-on: ubuntu-latest # Using macOS since the script uses macOS-specific sed | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Generate package script | ||
run: | | ||
chmod +x Scripts/artifact.sh | ||
./Scripts/artifact.sh package.sh | ||
- name: Upload package script | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: package.sh | ||
path: package.sh | ||
retention-days: 180 # Artifacts will be kept for 30 days |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#!/bin/sh | ||
|
||
# Default output location for the generated script | ||
output_script="package.sh" | ||
|
||
# Parse command line argument for output script name if provided | ||
if [ "$#" -gt 0 ]; then | ||
output_script="$1" | ||
fi | ||
|
||
echo "📝 Generating package script..." | ||
|
||
# Create the new script | ||
cat << 'EOF' > "$output_script" | ||
#!/bin/sh | ||
# Default values | ||
swift_tools_version="6.0" | ||
MINIMIZE=false | ||
# Parse flags | ||
while [ "$#" -gt 0 ]; do | ||
case "$1" in | ||
--version) | ||
swift_tools_version="$2" | ||
shift 2 | ||
;; | ||
--minimize) | ||
MINIMIZE=true | ||
shift 1 | ||
;; | ||
*) | ||
PACKAGE_DIR="$1" | ||
shift 1 | ||
;; | ||
esac | ||
done | ||
echo "⚙️ Generating package..." | ||
input_file=.package.source | ||
output_file=Package.swift | ||
cd $PACKAGE_DIR | ||
# Hardcoded PackageDSL content | ||
cat << 'PACKAGEDSL' > $input_file | ||
EOF | ||
|
||
# Add the PackageDSL content | ||
find ../PackageDSL/Sources/PackageDSL -name '*.swift' -type f -exec cat {} + | awk '!/^[[:space:]]*(\/\/.*)?$|^import /' | sed -e 's/^[[:space:]]*//;s/[[:space:]]*$//' >> "$output_script" | ||
|
||
# Continue with the rest of the script template | ||
cat << 'EOF' >> "$output_script" | ||
PACKAGEDSL | ||
find Package/Sources -mindepth 2 -type f -name '*.swift' -not -path '*/\.*' -exec cat {} + >> $input_file | ||
cat Package/Sources/*.swift >> $input_file | ||
# Collect unique import statements | ||
imports=$(awk '/^import / {imports[$0]=1} END {for (i in imports) print i}' "$input_file") | ||
if [ "$MINIMIZE" = true ]; then | ||
# Remove empty lines, lines containing only comments, and import statements | ||
awk '!/^[[:space:]]*(\/\/.*)?$|^import /' "$input_file" > "$output_file.tmp" | ||
# Remove leading and trailing whitespace from each line | ||
sed -i '' -e 's/^[[:space:]]*//;s/[[:space:]]*$//' "$output_file.tmp" | ||
# Append collected import statements at the beginning of the file | ||
echo "// swift-tools-version: $swift_tools_version" > $output_file | ||
echo "$imports" >> "$output_file" | ||
cat "$output_file.tmp" >> "$output_file" | ||
# Clean up temporary file | ||
rm "$output_file.tmp" | ||
else | ||
# Append collected import statements at the beginning of the file | ||
echo "// swift-tools-version: $swift_tools_version" > $output_file | ||
# Append collected import statements at the beginning of the file | ||
echo "$imports" >> "$output_file" | ||
cat "$input_file" >> "$output_file" | ||
fi | ||
EOF | ||
|
||
# Make the generated script executable | ||
chmod +x "$output_script" | ||
|
||
echo "✅ Generated package script at $output_script" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
#!/bin/sh | ||
|
||
# Default values | ||
swift_tools_version="5.10" | ||
swift_tools_version="6.0" | ||
MINIMIZE=false | ||
|
||
# Parse flags | ||
|