Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add binary target to package definition #210

Merged
merged 10 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
PREFIX?=/usr/local

TEMPORARY_FOLDER=./tmp_portable_licenseplist
TEMPORARY_FOLDER=./tmp_licenseplist

build:
VERSION_STRING=$(shell ./Tools/get-version)
LICENSE_PATH="$(shell pwd)/LICENSE"

ARTIFACT_BUNDLE_PATH=$(TEMPORARY_FOLDER)/LicensePlistBinary.artifactbundle

clean:
rm -rf "$(TEMPORARY_FOLDER)"
swift package clean

build: clean
swift build --disable-sandbox -c release

build_portable:
build_portable: clean
swift build --disable-sandbox -c release --arch x86_64 --arch arm64

test:
Expand All @@ -14,9 +23,6 @@ test:
lint:
swiftlint

clean:
swift package clean

xcode:
swift package generate-xcodeproj

Expand All @@ -30,3 +36,10 @@ portable_zip: build_portable
cp -f "LICENSE" "$(TEMPORARY_FOLDER)"
(cd $(TEMPORARY_FOLDER); zip -r - LICENSE license-plist) > "./portable_licenseplist.zip"
rm -r "$(TEMPORARY_FOLDER)"

spm_artifactbundle_macos: build
mkdir -p "$(ARTIFACT_BUNDLE_PATH)/license-plist-$(VERSION_STRING)-macos/bin"
sed 's/__VERSION__/$(VERSION_STRING)/g' Tools/info-macos.json.template > "$(ARTIFACT_BUNDLE_PATH)/info.json"
cp -f ".build/release/license-plist" "$(ARTIFACT_BUNDLE_PATH)/license-plist-$(VERSION_STRING)-macos/bin"
cp -f "$(LICENSE_PATH)" "$(ARTIFACT_BUNDLE_PATH)"
(cd "$(TEMPORARY_FOLDER)"; zip -yr - "LicensePlistBinary.artifactbundle") > "./LicensePlistBinary-macos.artifactbundle.zip"
5 changes: 5 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,10 @@ let package = Package(
"XcodeProjects",
]
),
.binaryTarget(
name: "LicensePlistBinary",
url: "https://github.com/mono0926/LicensePlist/releases/download/3.24.1/LicensePlistBinary-macos.artifactbundle.zip",
checksum: "a9609355bc9a72f6e610a96cfaa3e828329564d6eda9b08cfcabc75a90af7275"
)
]
)
5 changes: 5 additions & 0 deletions Tools/get-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

set -euo pipefail

cat Sources/LicensePlistCore/Consts.swift | grep "version =" | awk -F '"' '{print $2}' | xargs
15 changes: 15 additions & 0 deletions Tools/info-macos.json.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"schemaVersion": "1.0",
"artifacts": {
"license-plist": {
"version": "__VERSION__",
"type": "executable",
"variants": [
{
"path": "license-plist-__VERSION__-macos/bin/license-plist",
"supportedTriples": ["x86_64-apple-macosx", "arm64-apple-macosx"]
}
]
}
}
}
15 changes: 15 additions & 0 deletions Tools/update-artifact-bundle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

set -euo pipefail

readonly version="$1"
readonly artifactbundle="LicensePlistBinary-macos.artifactbundle.zip"
readonly checksum="$(shasum -a 256 "$artifactbundle" | cut -d " " -f1 | xargs)"

sed -i '' \
"s/.*\/releases\/download\/.*/ url: \"https:\/\/github.com\/mono0926\/LicensePlist\/releases\/download\/$version\/LicensePlistBinary-macos\.artifactbundle\.zip\",/g" \
Package.swift

sed -i '' \
"s/.*checksum.*/ checksum: \"$checksum\"/g" \
Package.swift
20 changes: 20 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ echo "Token: '${token}'"
filename="${tag}.tar.gz"
echo "Filename: '${filename}'"

# Prepare artifact bundle
binary_artifact="LicensePlistBinary-macos.artifactbundle.zip"
make spm_artifactbundle_macos
./Tools/update-artifact-bundle.sh "${tag}"

# Push updated binary target definition
git add Package.swift
git commit -m "release ${tag}"
git push origin HEAD

# Push tag
git tag $tag
git push origin $tag
Expand Down Expand Up @@ -66,6 +76,16 @@ github-release upload \

rm $lib_name.zip

# Upload artifact bundle
github-release upload \
--user mono0926 \
--repo LicensePlist \
--tag $tag \
--name $binary_artifact \
--file $binary_artifact

rm $binary_artifact

# CocoaPods
make portable_zip
portable_zip_name="portable_licenseplist.zip"
Expand Down