diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..83a7952 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,89 @@ +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 + 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 zip archive + zip ReerCodableMacros.zip ReerCodableMacros + + echo "=== Zip Contents ===" + unzip -l ReerCodableMacros.zip + + - name: Upload to GitHub Release + uses: softprops/action-gh-release@v2 + with: + files: artifacts/ReerCodableMacros.zip diff --git a/ReerCodable.podspec b/ReerCodable.podspec index 996f7b7..83d32e0 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.3' s.summary = 'Codable extensions using Swift Macro' s.description = <<-DESC @@ -30,27 +30,57 @@ 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_BUILD_DIR}/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_BUILD_DIR}/ReerCodable/MacroPlugin/ReerCodableMacros#ReerCodableMacros' } + # Download prebuilt universal macro plugin from GitHub Release script = <<-SCRIPT - env -i PATH="$PATH" "$SHELL" -l -c "swift build -c release --package-path \\"$PODS_TARGET_SRCROOT\\" --build-path \\"${PODS_BUILD_DIR}/ReerCodable\\"" + set -e + + 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}..." + + 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}" + 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 + 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 SCRIPT - + s.script_phase = { - :name => 'Build ReerCodable macro plugin', + :name => 'Download ReerCodableMacros Plugin', :script => script, - :execution_position => :before_compile, - :output_files => [ - '$(PODS_BUILD_DIR)/ReerCodable/release/ReerCodableMacros-tool' - ] + :execution_position => :before_compile } end