|
| 1 | +name: Publish Swift SDK to prerelease repo |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + paths: |
| 8 | + - 'sdks/implementations/swift/**' |
| 9 | + |
| 10 | +concurrency: |
| 11 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 12 | + cancel-in-progress: false # Don't cancel publishing in progress |
| 13 | + |
| 14 | +jobs: |
| 15 | + publish: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout source repo |
| 20 | + uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + path: source |
| 23 | + |
| 24 | + - name: Read version from package.json |
| 25 | + id: version |
| 26 | + run: | |
| 27 | + VERSION=$(jq -r '.version' source/sdks/implementations/swift/package.json) |
| 28 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 29 | + echo "Swift SDK version: $VERSION" |
| 30 | +
|
| 31 | + - name: Check if tag already exists in target repo |
| 32 | + id: check-tag |
| 33 | + run: | |
| 34 | + TAG="v${{ steps.version.outputs.version }}" |
| 35 | + echo "Checking if tag $TAG exists in stack-auth/swift-sdk-prerelease..." |
| 36 | + |
| 37 | + # Use the GitHub API to check if the tag exists |
| 38 | + HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \ |
| 39 | + -H "Authorization: Bearer ${{ secrets.SWIFT_SDK_PUBLISH_TOKEN }}" \ |
| 40 | + -H "Accept: application/vnd.github+json" \ |
| 41 | + "https://api.github.com/repos/stack-auth/swift-sdk-prerelease/git/refs/tags/$TAG") |
| 42 | + |
| 43 | + if [ "$HTTP_STATUS" = "200" ]; then |
| 44 | + echo "Tag $TAG already exists, skipping publish" |
| 45 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 46 | + else |
| 47 | + echo "Tag $TAG does not exist, will publish" |
| 48 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 49 | + fi |
| 50 | +
|
| 51 | + - name: Clone target repo |
| 52 | + if: steps.check-tag.outputs.exists == 'false' |
| 53 | + run: | |
| 54 | + git clone https://x-access-token:${{ secrets.SWIFT_SDK_PUBLISH_TOKEN }}@github.com/stack-auth/swift-sdk-prerelease.git target |
| 55 | +
|
| 56 | + - name: Copy Swift SDK to target repo |
| 57 | + if: steps.check-tag.outputs.exists == 'false' |
| 58 | + run: | |
| 59 | + # Remove all files except .git from target |
| 60 | + cd target |
| 61 | + find . -maxdepth 1 -not -name '.git' -not -name '.' -exec rm -rf {} + |
| 62 | + cd .. |
| 63 | + |
| 64 | + # Copy everything from Swift SDK |
| 65 | + cp -r source/sdks/implementations/swift/* target/ |
| 66 | + cp source/sdks/implementations/swift/.gitignore target/ 2>/dev/null || true |
| 67 | + |
| 68 | + # Remove package.json (it's only for turborepo integration, not part of the Swift package) |
| 69 | + rm -f target/package.json |
| 70 | +
|
| 71 | + - name: Commit and push to target repo |
| 72 | + if: steps.check-tag.outputs.exists == 'false' |
| 73 | + run: | |
| 74 | + cd target |
| 75 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 76 | + git config user.name "github-actions[bot]" |
| 77 | + |
| 78 | + git add -A |
| 79 | + |
| 80 | + # Check if there are changes to commit |
| 81 | + if git diff --staged --quiet; then |
| 82 | + echo "No changes to commit" |
| 83 | + else |
| 84 | + git commit -m "Release v${{ steps.version.outputs.version }}" |
| 85 | + fi |
| 86 | + |
| 87 | + # Create and push tag |
| 88 | + TAG="v${{ steps.version.outputs.version }}" |
| 89 | + git tag "$TAG" |
| 90 | + git push origin main --tags |
| 91 | + |
| 92 | + echo "Successfully published Swift SDK v${{ steps.version.outputs.version }}" |
| 93 | +
|
| 94 | + - name: Summary |
| 95 | + run: | |
| 96 | + if [ "${{ steps.check-tag.outputs.exists }}" = "true" ]; then |
| 97 | + echo "::notice::Skipped publishing - tag v${{ steps.version.outputs.version }} already exists" |
| 98 | + else |
| 99 | + echo "::notice::Published Swift SDK v${{ steps.version.outputs.version }} to stack-auth/swift-sdk-prerelease" |
| 100 | + fi |
0 commit comments