Skip to content

Commit

Permalink
Create script to create SPM artifact bundle (#1215)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Lord authored and nicklockwood committed Jul 13, 2022
1 parent 378543f commit c58df80
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Scripts/get-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

set -e

REGEX="let swiftFormatVersion = \"([0-9]+.[0-9]+.[0-9]+)\""
while IFS= read -r line; do
if [[ $line =~ $REGEX ]]
then
echo "${BASH_REMATCH[1]}"
break
fi
done < Sources/SwiftFormat.swift
25 changes: 25 additions & 0 deletions Scripts/spm-artifact-bundle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh

set -e

ARTIFACT_BUNDLE=swiftformat.artifactbundle
INFO_TEMPLATE=Scripts/spm-macos-artifact-bundle-info.template
VERSION=$(./Scripts/get-version.sh)
BINARY_OUTPUT_DIR=$ARTIFACT_BUNDLE/swiftformat-$VERSION-macos/bin

mkdir $ARTIFACT_BUNDLE

# Copy license into bundle
cp LICENSE.md $ARTIFACT_BUNDLE

# Create bundle info.json from template, replacing version
sed 's/__VERSION__/'"${VERSION}"'/g' $INFO_TEMPLATE > "${ARTIFACT_BUNDLE}/info.json"

# Copy MacOS SwiftFormat binary into bundle
mkdir -p $BINARY_OUTPUT_DIR
cp CommandLineTool/swiftformat $BINARY_OUTPUT_DIR

# Create ZIP
zip -yr - $ARTIFACT_BUNDLE > "${ARTIFACT_BUNDLE}.zip"

rm -rf $ARTIFACT_BUNDLE
15 changes: 15 additions & 0 deletions Scripts/spm-macos-artifact-bundle-info.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"schemaVersion": "1.0",
"artifacts": {
"swiftformat": {
"version": "__VERSION__",
"type": "executable",
"variants": [
{
"path": "swiftformat-__VERSION__-macos/bin/swiftformat",
"supportedTriples": ["x86_64-apple-macosx", "arm64-apple-macosx"]
}
]
}
}
}

0 comments on commit c58df80

Please sign in to comment.