Skip to content

Commit b528783

Browse files
authored
GitHub release binary for Cocoapods (#33)
* Add build macro plugin runner * update release.yml * update podspec * add timout * test: bump to 0.0.3
1 parent efff693 commit b528783

File tree

2 files changed

+130
-11
lines changed

2 files changed

+130
-11
lines changed

.github/workflows/release.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Build and Release Macro Plugin
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
build-arm64:
9+
name: Build arm64
10+
runs-on: macos-15
11+
steps:
12+
- name: Git Checkout
13+
uses: actions/checkout@v4
14+
15+
- name: Build arm64 macro plugin
16+
run: |
17+
swift build -c release --product ReerCodableMacros
18+
cp .build/release/ReerCodableMacros-tool ./ReerCodableMacros-arm64
19+
file ./ReerCodableMacros-arm64
20+
21+
- name: Upload arm64 artifact
22+
uses: actions/upload-artifact@v4
23+
with:
24+
name: macro-plugin-arm64
25+
path: ReerCodableMacros-arm64
26+
27+
build-x86_64:
28+
name: Build x86_64
29+
runs-on: macos-15-intel
30+
steps:
31+
- name: Git Checkout
32+
uses: actions/checkout@v4
33+
34+
- name: Build x86_64 macro plugin
35+
run: |
36+
swift build -c release --product ReerCodableMacros
37+
cp .build/release/ReerCodableMacros-tool ./ReerCodableMacros-x86_64
38+
file ./ReerCodableMacros-x86_64
39+
40+
- name: Upload x86_64 artifact
41+
uses: actions/upload-artifact@v4
42+
with:
43+
name: macro-plugin-x86_64
44+
path: ReerCodableMacros-x86_64
45+
46+
create-universal-and-upload:
47+
name: Create Universal Macro Plugin and Upload
48+
needs: [build-arm64, build-x86_64]
49+
runs-on: macos-15
50+
permissions:
51+
contents: write
52+
steps:
53+
- name: Git Checkout
54+
uses: actions/checkout@v4
55+
56+
- name: Download arm64 artifact
57+
uses: actions/download-artifact@v4
58+
with:
59+
name: macro-plugin-arm64
60+
path: ./artifacts
61+
62+
- name: Download x86_64 artifact
63+
uses: actions/download-artifact@v4
64+
with:
65+
name: macro-plugin-x86_64
66+
path: ./artifacts
67+
68+
- name: Create Universal Macro Plugin
69+
run: |
70+
cd artifacts
71+
72+
# Create Universal Macro Plugin
73+
lipo -create ReerCodableMacros-arm64 ReerCodableMacros-x86_64 \
74+
-output ReerCodableMacros
75+
76+
echo "=== Universal Macro Plugin Info ==="
77+
lipo -info ReerCodableMacros
78+
file ReerCodableMacros
79+
80+
# Create zip archive
81+
zip ReerCodableMacros.zip ReerCodableMacros
82+
83+
echo "=== Zip Contents ==="
84+
unzip -l ReerCodableMacros.zip
85+
86+
- name: Upload to GitHub Release
87+
uses: softprops/action-gh-release@v2
88+
with:
89+
files: artifacts/ReerCodableMacros.zip

ReerCodable.podspec

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'ReerCodable'
11-
s.version = '1.5.0'
11+
s.version = '0.0.3'
1212
s.summary = 'Codable extensions using Swift Macro'
1313

1414
s.description = <<-DESC
@@ -30,27 +30,57 @@ Pod::Spec.new do |s|
3030

3131
s.source_files = 'Sources/ReerCodable/**/*'
3232

33-
s.preserve_paths = ["Package.swift", "Sources/ReerCodableMacros", "Tests"]
33+
s.preserve_paths = ["Package.swift", "Sources/ReerCodableMacros", "Tests", "MacroPlugin"]
3434

3535
s.pod_target_xcconfig = {
36-
'OTHER_SWIFT_FLAGS' => '-Xfrontend -load-plugin-executable -Xfrontend $(PODS_BUILD_DIR)/ReerCodable/release/ReerCodableMacros-tool#ReerCodableMacros'
36+
'OTHER_SWIFT_FLAGS' => '-Xfrontend -load-plugin-executable -Xfrontend ${PODS_BUILD_DIR}/ReerCodable/MacroPlugin/ReerCodableMacros#ReerCodableMacros'
3737
}
3838

3939
s.user_target_xcconfig = {
40-
'OTHER_SWIFT_FLAGS' => '-Xfrontend -load-plugin-executable -Xfrontend $(PODS_BUILD_DIR)/ReerCodable/release/ReerCodableMacros-tool#ReerCodableMacros'
40+
'OTHER_SWIFT_FLAGS' => '-Xfrontend -load-plugin-executable -Xfrontend ${PODS_BUILD_DIR}/ReerCodable/MacroPlugin/ReerCodableMacros#ReerCodableMacros'
4141
}
4242

43+
# Download prebuilt universal macro plugin from GitHub Release
4344
script = <<-SCRIPT
44-
env -i PATH="$PATH" "$SHELL" -l -c "swift build -c release --package-path \\"$PODS_TARGET_SRCROOT\\" --build-path \\"${PODS_BUILD_DIR}/ReerCodable\\""
45+
set -e
46+
47+
PLUGIN_DIR="${PODS_BUILD_DIR}/ReerCodable/MacroPlugin"
48+
PLUGIN_NAME="ReerCodableMacros"
49+
VERSION="#{s.version}"
50+
DOWNLOAD_URL="https://github.com/reers/ReerCodable/releases/download/${VERSION}/${PLUGIN_NAME}.zip"
51+
52+
# Check if plugin already exists
53+
if [ -x "${PLUGIN_DIR}/${PLUGIN_NAME}" ]; then
54+
echo "Macro plugin already exists, skipping download."
55+
exit 0
56+
fi
57+
58+
mkdir -p "${PLUGIN_DIR}"
59+
60+
echo "Downloading prebuilt macro plugin from ${DOWNLOAD_URL}..."
61+
62+
if curl -L -f --connect-timeout 3 --max-time 60 -o "${PLUGIN_DIR}/${PLUGIN_NAME}.zip" "${DOWNLOAD_URL}"; then
63+
unzip -o "${PLUGIN_DIR}/${PLUGIN_NAME}.zip" -d "${PLUGIN_DIR}"
64+
rm -f "${PLUGIN_DIR}/${PLUGIN_NAME}.zip"
65+
chmod +x "${PLUGIN_DIR}/${PLUGIN_NAME}"
66+
echo "Successfully downloaded prebuilt macro plugin"
67+
file "${PLUGIN_DIR}/${PLUGIN_NAME}"
68+
else
69+
echo "Warning: Failed to download prebuilt macro plugin, will build from source..."
70+
71+
# Fallback: build from source
72+
env -i PATH="$PATH" "$SHELL" -l -c "swift build -c release --package-path \\"${PODS_TARGET_SRCROOT}\\" --build-path \\"${PODS_BUILD_DIR}/ReerCodable\\" --product ReerCodableMacros"
73+
cp "${PODS_BUILD_DIR}/ReerCodable/release/ReerCodableMacros-tool" "${PLUGIN_DIR}/${PLUGIN_NAME}"
74+
chmod +x "${PLUGIN_DIR}/${PLUGIN_NAME}"
75+
echo "Built macro plugin from source"
76+
file "${PLUGIN_DIR}/${PLUGIN_NAME}"
77+
fi
4578
SCRIPT
46-
79+
4780
s.script_phase = {
48-
:name => 'Build ReerCodable macro plugin',
81+
:name => 'Download ReerCodableMacros Plugin',
4982
:script => script,
50-
:execution_position => :before_compile,
51-
:output_files => [
52-
'$(PODS_BUILD_DIR)/ReerCodable/release/ReerCodableMacros-tool'
53-
]
83+
:execution_position => :before_compile
5484
}
5585

5686
end

0 commit comments

Comments
 (0)