Skip to content

Commit

Permalink
Adding Deliverable Artifact (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
leogdion authored Feb 4, 2025
1 parent ae7bd3e commit 732841e
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 1 deletion.
26 changes: 26 additions & 0 deletions .github/workflows/artifact.yml
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
91 changes: 91 additions & 0 deletions Scripts/artifact.sh
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"
2 changes: 1 addition & 1 deletion Scripts/package.sh
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
Expand Down

0 comments on commit 732841e

Please sign in to comment.