From 70d62b4fa86dc111671eb08236ee605b770ec6e9 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sun, 28 Dec 2025 09:40:49 +0800 Subject: [PATCH 1/5] Add build macro plugin runner --- .github/workflows/release.yml | 114 ++++++++++++++++++++++++++++++++++ ReerCodable.podspec | 46 +++++++++----- 2 files changed, 145 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..969a646 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,114 @@ +name: Build and Release Macro Plugin + +on: + release: + types: [published] + +jobs: + build-arm64: + name: Build arm64 + runs-on: macos-15 + steps: + - name: Git Checkout + uses: actions/checkout@v4 + + - name: Build arm64 macro plugin + run: | + swift build -c release --product ReerCodableMacros + cp .build/release/ReerCodableMacros-tool ./ReerCodableMacros-arm64 + file ./ReerCodableMacros-arm64 + + - name: Upload arm64 artifact + uses: actions/upload-artifact@v4 + with: + name: macro-plugin-arm64 + path: ReerCodableMacros-arm64 + + build-x86_64: + name: Build x86_64 + runs-on: macos-15-intel + steps: + - name: Git Checkout + uses: actions/checkout@v4 + + - name: Build x86_64 macro plugin + run: | + swift build -c release --product ReerCodableMacros + cp .build/release/ReerCodableMacros-tool ./ReerCodableMacros-x86_64 + file ./ReerCodableMacros-x86_64 + + - name: Upload x86_64 artifact + uses: actions/upload-artifact@v4 + with: + name: macro-plugin-x86_64 + path: ReerCodableMacros-x86_64 + + create-universal-and-upload: + name: Create Universal Macro Plugin and Upload + needs: [build-arm64, build-x86_64] + runs-on: macos-15 + permissions: + contents: write + steps: + - name: Git Checkout + uses: actions/checkout@v4 + + - name: Download arm64 artifact + uses: actions/download-artifact@v4 + with: + name: macro-plugin-arm64 + path: ./artifacts + + - name: Download x86_64 artifact + uses: actions/download-artifact@v4 + with: + name: macro-plugin-x86_64 + path: ./artifacts + + - name: Create Universal Macro Plugin and Artifact Bundle + run: | + cd artifacts + + # Create Universal Macro Plugin + lipo -create ReerCodableMacros-arm64 ReerCodableMacros-x86_64 \ + -output ReerCodableMacros + + echo "=== Universal Macro Plugin Info ===" + lipo -info ReerCodableMacros + file ReerCodableMacros + + # Create artifact bundle structure + mkdir -p ReerCodableMacros.artifactbundle/macos/bin + cp ReerCodableMacros ReerCodableMacros.artifactbundle/macos/bin/ + + # Create info.json + cat > ReerCodableMacros.artifactbundle/info.json << EOF + { + "schemaVersion": "1.0", + "artifacts": { + "ReerCodableMacros": { + "version": "${{ github.ref_name }}", + "type": "executable", + "variants": [ + { + "path": "macos/bin/ReerCodableMacros", + "supportedTriples": ["x86_64-apple-macosx", "arm64-apple-macosx"] + } + ] + } + } + } + EOF + + # Create zip archive + zip -r ReerCodableMacros.artifactbundle.zip ReerCodableMacros.artifactbundle + + echo "=== Artifact Bundle Contents ===" + unzip -l ReerCodableMacros.artifactbundle.zip + + - name: Upload to GitHub Release + uses: softprops/action-gh-release@v2 + with: + files: | + artifacts/ReerCodableMacros + artifacts/ReerCodableMacros.artifactbundle.zip diff --git a/ReerCodable.podspec b/ReerCodable.podspec index 996f7b7..c77f779 100644 --- a/ReerCodable.podspec +++ b/ReerCodable.podspec @@ -30,27 +30,43 @@ Pod::Spec.new do |s| s.source_files = 'Sources/ReerCodable/**/*' - s.preserve_paths = ["Package.swift", "Sources/ReerCodableMacros", "Tests"] + s.preserve_paths = ["Package.swift", "Sources/ReerCodableMacros", "Tests", "MacroPlugin"] s.pod_target_xcconfig = { - 'OTHER_SWIFT_FLAGS' => '-Xfrontend -load-plugin-executable -Xfrontend $(PODS_BUILD_DIR)/ReerCodable/release/ReerCodableMacros-tool#ReerCodableMacros' + 'OTHER_SWIFT_FLAGS' => '-Xfrontend -load-plugin-executable -Xfrontend ${PODS_ROOT}/ReerCodable/MacroPlugin/ReerCodableMacros#ReerCodableMacros' } s.user_target_xcconfig = { - 'OTHER_SWIFT_FLAGS' => '-Xfrontend -load-plugin-executable -Xfrontend $(PODS_BUILD_DIR)/ReerCodable/release/ReerCodableMacros-tool#ReerCodableMacros' + 'OTHER_SWIFT_FLAGS' => '-Xfrontend -load-plugin-executable -Xfrontend ${PODS_ROOT}/ReerCodable/MacroPlugin/ReerCodableMacros#ReerCodableMacros' } - script = <<-SCRIPT - env -i PATH="$PATH" "$SHELL" -l -c "swift build -c release --package-path \\"$PODS_TARGET_SRCROOT\\" --build-path \\"${PODS_BUILD_DIR}/ReerCodable\\"" - SCRIPT - - s.script_phase = { - :name => 'Build ReerCodable macro plugin', - :script => script, - :execution_position => :before_compile, - :output_files => [ - '$(PODS_BUILD_DIR)/ReerCodable/release/ReerCodableMacros-tool' - ] - } + # Download prebuilt universal macro plugin from GitHub Release + s.prepare_command = <<-CMD + set -e + + PLUGIN_DIR="MacroPlugin" + PLUGIN_NAME="ReerCodableMacros" + VERSION="#{s.version}" + DOWNLOAD_URL="https://github.com/reers/ReerCodable/releases/download/${VERSION}/${PLUGIN_NAME}" + + mkdir -p "${PLUGIN_DIR}" + + echo "Downloading prebuilt macro plugin from ${DOWNLOAD_URL}..." + + if curl -L -f -o "${PLUGIN_DIR}/${PLUGIN_NAME}" "${DOWNLOAD_URL}"; then + chmod +x "${PLUGIN_DIR}/${PLUGIN_NAME}" + echo "Successfully downloaded prebuilt macro plugin" + file "${PLUGIN_DIR}/${PLUGIN_NAME}" + else + echo "Warning: Failed to download prebuilt macro plugin, will build from source..." + + # Fallback: build from source + swift build -c release --package-path "." --product ReerCodableMacros + cp ".build/release/ReerCodableMacros-tool" "${PLUGIN_DIR}/${PLUGIN_NAME}" + chmod +x "${PLUGIN_DIR}/${PLUGIN_NAME}" + echo "Built macro plugin from source" + file "${PLUGIN_DIR}/${PLUGIN_NAME}" + fi + CMD end From 61880d94b451a37e25ea22e3b60bf1c1964fcc14 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sun, 28 Dec 2025 10:04:05 +0800 Subject: [PATCH 2/5] update release.yml --- .github/workflows/release.yml | 35 +++++------------------------------ ReerCodable.podspec | 6 ++++-- 2 files changed, 9 insertions(+), 32 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 969a646..83a7952 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -65,7 +65,7 @@ jobs: name: macro-plugin-x86_64 path: ./artifacts - - name: Create Universal Macro Plugin and Artifact Bundle + - name: Create Universal Macro Plugin run: | cd artifacts @@ -77,38 +77,13 @@ jobs: lipo -info ReerCodableMacros file ReerCodableMacros - # Create artifact bundle structure - mkdir -p ReerCodableMacros.artifactbundle/macos/bin - cp ReerCodableMacros ReerCodableMacros.artifactbundle/macos/bin/ - - # Create info.json - cat > ReerCodableMacros.artifactbundle/info.json << EOF - { - "schemaVersion": "1.0", - "artifacts": { - "ReerCodableMacros": { - "version": "${{ github.ref_name }}", - "type": "executable", - "variants": [ - { - "path": "macos/bin/ReerCodableMacros", - "supportedTriples": ["x86_64-apple-macosx", "arm64-apple-macosx"] - } - ] - } - } - } - EOF - # Create zip archive - zip -r ReerCodableMacros.artifactbundle.zip ReerCodableMacros.artifactbundle + zip ReerCodableMacros.zip ReerCodableMacros - echo "=== Artifact Bundle Contents ===" - unzip -l ReerCodableMacros.artifactbundle.zip + echo "=== Zip Contents ===" + unzip -l ReerCodableMacros.zip - name: Upload to GitHub Release uses: softprops/action-gh-release@v2 with: - files: | - artifacts/ReerCodableMacros - artifacts/ReerCodableMacros.artifactbundle.zip + files: artifacts/ReerCodableMacros.zip diff --git a/ReerCodable.podspec b/ReerCodable.podspec index c77f779..8e4906d 100644 --- a/ReerCodable.podspec +++ b/ReerCodable.podspec @@ -47,13 +47,15 @@ Pod::Spec.new do |s| PLUGIN_DIR="MacroPlugin" PLUGIN_NAME="ReerCodableMacros" VERSION="#{s.version}" - DOWNLOAD_URL="https://github.com/reers/ReerCodable/releases/download/${VERSION}/${PLUGIN_NAME}" + DOWNLOAD_URL="https://github.com/reers/ReerCodable/releases/download/${VERSION}/${PLUGIN_NAME}.zip" mkdir -p "${PLUGIN_DIR}" echo "Downloading prebuilt macro plugin from ${DOWNLOAD_URL}..." - if curl -L -f -o "${PLUGIN_DIR}/${PLUGIN_NAME}" "${DOWNLOAD_URL}"; then + if curl -L -f -o "${PLUGIN_DIR}/${PLUGIN_NAME}.zip" "${DOWNLOAD_URL}"; then + unzip -o "${PLUGIN_DIR}/${PLUGIN_NAME}.zip" -d "${PLUGIN_DIR}" + rm -f "${PLUGIN_DIR}/${PLUGIN_NAME}.zip" chmod +x "${PLUGIN_DIR}/${PLUGIN_NAME}" echo "Successfully downloaded prebuilt macro plugin" file "${PLUGIN_DIR}/${PLUGIN_NAME}" From acea576eb66cec0cfda38b846ac728cc894e6c25 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sun, 28 Dec 2025 18:05:30 +0800 Subject: [PATCH 3/5] update podspec --- ReerCodable.podspec | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/ReerCodable.podspec b/ReerCodable.podspec index 8e4906d..9c1afcf 100644 --- a/ReerCodable.podspec +++ b/ReerCodable.podspec @@ -33,22 +33,28 @@ Pod::Spec.new do |s| s.preserve_paths = ["Package.swift", "Sources/ReerCodableMacros", "Tests", "MacroPlugin"] s.pod_target_xcconfig = { - 'OTHER_SWIFT_FLAGS' => '-Xfrontend -load-plugin-executable -Xfrontend ${PODS_ROOT}/ReerCodable/MacroPlugin/ReerCodableMacros#ReerCodableMacros' + 'OTHER_SWIFT_FLAGS' => '-Xfrontend -load-plugin-executable -Xfrontend ${PODS_BUILD_DIR}/ReerCodable/MacroPlugin/ReerCodableMacros#ReerCodableMacros' } s.user_target_xcconfig = { - 'OTHER_SWIFT_FLAGS' => '-Xfrontend -load-plugin-executable -Xfrontend ${PODS_ROOT}/ReerCodable/MacroPlugin/ReerCodableMacros#ReerCodableMacros' + 'OTHER_SWIFT_FLAGS' => '-Xfrontend -load-plugin-executable -Xfrontend ${PODS_BUILD_DIR}/ReerCodable/MacroPlugin/ReerCodableMacros#ReerCodableMacros' } # Download prebuilt universal macro plugin from GitHub Release - s.prepare_command = <<-CMD + script = <<-SCRIPT set -e - - PLUGIN_DIR="MacroPlugin" + + PLUGIN_DIR="${PODS_BUILD_DIR}/ReerCodable/MacroPlugin" PLUGIN_NAME="ReerCodableMacros" VERSION="#{s.version}" DOWNLOAD_URL="https://github.com/reers/ReerCodable/releases/download/${VERSION}/${PLUGIN_NAME}.zip" + # Check if plugin already exists + if [ -x "${PLUGIN_DIR}/${PLUGIN_NAME}" ]; then + echo "Macro plugin already exists, skipping download." + exit 0 + fi + mkdir -p "${PLUGIN_DIR}" echo "Downloading prebuilt macro plugin from ${DOWNLOAD_URL}..." @@ -63,12 +69,18 @@ Pod::Spec.new do |s| echo "Warning: Failed to download prebuilt macro plugin, will build from source..." # Fallback: build from source - swift build -c release --package-path "." --product ReerCodableMacros - cp ".build/release/ReerCodableMacros-tool" "${PLUGIN_DIR}/${PLUGIN_NAME}" + env -i PATH="$PATH" "$SHELL" -l -c "swift build -c release --package-path \\"${PODS_TARGET_SRCROOT}\\" --build-path \\"${PODS_BUILD_DIR}/ReerCodable\\" --product ReerCodableMacros" + cp "${PODS_BUILD_DIR}/ReerCodable/release/ReerCodableMacros-tool" "${PLUGIN_DIR}/${PLUGIN_NAME}" chmod +x "${PLUGIN_DIR}/${PLUGIN_NAME}" echo "Built macro plugin from source" file "${PLUGIN_DIR}/${PLUGIN_NAME}" fi - CMD + SCRIPT + + s.script_phase = { + :name => 'Download ReerCodableMacros Plugin', + :script => script, + :execution_position => :before_compile + } end From 2ab762858f0334db44815a251511e38302c09ab4 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sun, 28 Dec 2025 18:13:23 +0800 Subject: [PATCH 4/5] add timout --- ReerCodable.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ReerCodable.podspec b/ReerCodable.podspec index 9c1afcf..4aa5ebf 100644 --- a/ReerCodable.podspec +++ b/ReerCodable.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'ReerCodable' - s.version = '1.5.0' + s.version = '0.0.2' s.summary = 'Codable extensions using Swift Macro' s.description = <<-DESC @@ -59,7 +59,7 @@ Pod::Spec.new do |s| echo "Downloading prebuilt macro plugin from ${DOWNLOAD_URL}..." - if curl -L -f -o "${PLUGIN_DIR}/${PLUGIN_NAME}.zip" "${DOWNLOAD_URL}"; then + if curl -L -f --connect-timeout 3 --max-time 60 -o "${PLUGIN_DIR}/${PLUGIN_NAME}.zip" "${DOWNLOAD_URL}"; then unzip -o "${PLUGIN_DIR}/${PLUGIN_NAME}.zip" -d "${PLUGIN_DIR}" rm -f "${PLUGIN_DIR}/${PLUGIN_NAME}.zip" chmod +x "${PLUGIN_DIR}/${PLUGIN_NAME}" From 83a5c769048d08a9a3710b6dce95105e894dde92 Mon Sep 17 00:00:00 2001 From: Phoenix Date: Mon, 29 Dec 2025 11:39:22 +0800 Subject: [PATCH 5/5] test: bump to 0.0.3 --- ReerCodable.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ReerCodable.podspec b/ReerCodable.podspec index 4aa5ebf..83d32e0 100644 --- a/ReerCodable.podspec +++ b/ReerCodable.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'ReerCodable' - s.version = '0.0.2' + s.version = '0.0.3' s.summary = 'Codable extensions using Swift Macro' s.description = <<-DESC