|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - '*' |
| 7 | + |
| 8 | +jobs: |
| 9 | + release: |
| 10 | + runs-on: macos-latest |
| 11 | + |
| 12 | + steps: |
| 13 | + - name: Checkout |
| 14 | + uses: actions/checkout@v4 |
| 15 | + with: |
| 16 | + fetch-depth: 0 |
| 17 | + |
| 18 | + - name: Setup Xcode |
| 19 | + uses: maxim-lobanov/setup-xcode@v1 |
| 20 | + with: |
| 21 | + xcode-version: latest-stable |
| 22 | + |
| 23 | + - name: Get tag name |
| 24 | + id: tag |
| 25 | + run: echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
| 26 | + |
| 27 | + - name: Build XCFramework |
| 28 | + run: | |
| 29 | + chmod +x build-xcframework.sh |
| 30 | + ./build-xcframework.sh CacheKit |
| 31 | +
|
| 32 | + - name: Calculate checksum |
| 33 | + id: checksum |
| 34 | + run: | |
| 35 | + CHECKSUM=$(shasum -a 256 build/CacheKit.xcframework.zip | cut -d' ' -f1) |
| 36 | + echo "CHECKSUM=$CHECKSUM" >> $GITHUB_OUTPUT |
| 37 | + echo "Checksum: $CHECKSUM" |
| 38 | +
|
| 39 | + - name: Create Release |
| 40 | + id: create_release |
| 41 | + uses: actions/create-release@v1 |
| 42 | + env: |
| 43 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + with: |
| 45 | + tag_name: ${{ steps.tag.outputs.TAG_NAME }} |
| 46 | + release_name: Release ${{ steps.tag.outputs.TAG_NAME }} |
| 47 | + draft: false |
| 48 | + prerelease: false |
| 49 | + |
| 50 | + - name: Upload XCFramework to Release |
| 51 | + uses: actions/upload-release-asset@v1 |
| 52 | + env: |
| 53 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 54 | + with: |
| 55 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 56 | + asset_path: build/CacheKit.xcframework.zip |
| 57 | + asset_name: CacheKit.xcframework.zip |
| 58 | + asset_content_type: application/zip |
| 59 | + |
| 60 | + - name: Update Package.swift |
| 61 | + run: | |
| 62 | + # Update Package.swift with new URL and checksum |
| 63 | + sed -i '' "s|url: \"https://github.com/BBC6BAE9/cachekit/releases/download/.*/CacheKit.xcframework.zip\"|url: \"https://github.com/BBC6BAE9/cachekit/releases/download/${{ steps.tag.outputs.TAG_NAME }}/CacheKit.xcframework.zip\"|g" Package.swift |
| 64 | + sed -i '' "s|checksum: \".*\"|checksum: \"${{ steps.checksum.outputs.CHECKSUM }}\"|g" Package.swift |
| 65 | + echo "Updated Package.swift for tag ${{ steps.tag.outputs.TAG_NAME }} with checksum ${{ steps.checksum.outputs.CHECKSUM }}" |
| 66 | +
|
| 67 | + - name: Commit updated Package.swift |
| 68 | + run: | |
| 69 | + git config --local user.email "[email protected]" |
| 70 | + git config --local user.name "GitHub Action" |
| 71 | + git add Package.swift |
| 72 | + if git diff --staged --quiet; then |
| 73 | + echo "No changes to commit" |
| 74 | + else |
| 75 | + git commit -m "Update Package.swift for release ${{ steps.tag.outputs.TAG_NAME }}" |
| 76 | + git push origin HEAD:main |
| 77 | + fi |
0 commit comments