Skip to content

Commit

Permalink
feat(swift): initial generation (#2370)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fluf22 committed Jan 11, 2024
1 parent 4b30c39 commit 147035c
Show file tree
Hide file tree
Showing 73 changed files with 4,720 additions and 25 deletions.
27 changes: 27 additions & 0 deletions .github/actions/setup/action.yml
Expand Up @@ -76,6 +76,7 @@ runs:
echo "PYTHON_VERSION=$(cat config/.python-version)" >> $GITHUB_OUTPUT
echo "RUBY_VERSION=$(cat config/.ruby-version)" >> $GITHUB_OUTPUT
echo "CSHARP_VERSION=$(cat config/.csharp-version)" >> $GITHUB_OUTPUT
echo "SWIFT_VERSION=$(cat config/.swift-version)" >> $GITHUB_OUTPUT
# JavaScript client deps
- name: Get yarn js-client cache directory path
Expand Down Expand Up @@ -178,3 +179,29 @@ runs:
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ steps.versions.outputs.CSHARP_VERSION }}

# Swift deps
- name: Install swift
if: ${{ inputs.language == 'swift' }}
uses: swift-actions/setup-swift@v1
with:
swift-version: ${{ steps.versions.outputs.SWIFT_VERSION }}

- name: Set up Homebrew
if: ${{ inputs.language == 'swift' }}
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master

- name: Cache Homebrew Bundler RubyGems
if: ${{ inputs.language == 'swift' }}
id: cache
uses: actions/cache@v3
with:
path: ${{ steps.set-up-homebrew.outputs.gems-path }}
key: ${{ runner.os }}-rubygems-${{ steps.set-up-homebrew.outputs.gems-hash }}
restore-keys: ${{ runner.os }}-rubygems-

- name: Install swift-format
if: ${{ inputs.language == 'swift' && steps.cache.outputs.cache-hit != 'true' }}
shell: bash
run: brew install swift-format
4 changes: 2 additions & 2 deletions .github/workflows/check.yml
Expand Up @@ -299,8 +299,8 @@ jobs:
path: clients-javascript.zip

client_gen:
timeout-minutes: 15
runs-on: ubuntu-22.04
timeout-minutes: 20
runs-on: ${{ matrix.client.language == 'swift' && 'macos-12' || 'ubuntu-22.04' }}
needs:
- setup
- specs
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-title.yml
Expand Up @@ -16,4 +16,4 @@ jobs:
- name: Pull Request title rules
uses: Slashgear/action-check-pr-title@v4.3.0
with:
regexp: '^(docs|chore)|((?:feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)\((?:clients|generators|playground|javascript|php|java|go|kotlin|dart|python|ruby|scala|csharp|cts|specs|scripts|ci|templates|deps)\)): .+'
regexp: '^(docs|chore)|((?:feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)\((?:clients|generators|playground|javascript|php|java|go|kotlin|dart|python|ruby|scala|csharp|swift|cts|specs|scripts|ci|templates|deps)\)): .+'
50 changes: 36 additions & 14 deletions Dockerfile
Expand Up @@ -4,12 +4,12 @@ ARG NODE_VERSION
ARG PHP_VERSION
ARG PYTHON_VERSION
ARG CSHARP_VERSION
ARG SWIFT_VERSION

FROM dart:${DART_VERSION} AS dart-builder
FROM mcr.microsoft.com/dotnet/sdk:${CSHARP_VERSION} AS csharp-builder
FROM golang:${GO_VERSION}-bullseye AS go-builder
FROM python:${PYTHON_VERSION}-bullseye AS python-builder
FROM php:${PHP_VERSION}-bullseye AS builder
FROM swift:${SWIFT_VERSION}-jammy AS builder

ENV DOCKER=true

Expand All @@ -18,25 +18,29 @@ SHELL ["/bin/bash", "--login", "-c"]

# Global (and librairies for ruby)
RUN apt-get update && apt-get install -y --no-install-recommends \
curl zip unzip git openssh-server \
build-essential bison zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
curl zip unzip git openssh-server ca-certificates \
build-essential bison zlib1g-dev libyaml-dev libssl-dev openssl libgdbm-dev libreadline-dev libncurses5-dev libffi-dev

# JavaScript
COPY .nvmrc .nvmrc
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash && source ~/.profile \
&& nvm install \
&& npm install -g yarn
RUN mkdir -p /etc/apt/keyrings \
&& curl -sL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | tee /etc/apt/keyrings/nodesource.gpg >/dev/null \
&& NODE_MAJOR=$(echo $NODE_VERSION | sed -E -n 's/v?([0-9]+)\..*/\1/p') \
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_MAJOR}.x jammy main" | tee /etc/apt/sources.list.d/nodesource.list \
&& apt-get update && apt-get install -y --no-install-recommends nodejs
RUN npm install -g yarn

# Python
COPY --from=python-builder /usr/local/bin/ /usr/local/bin/
COPY --from=python-builder /usr/local/lib/ /usr/local/lib/
RUN echo "export PATH=$PATH:/usr/local/bin/python" >> ~/.profile \
&& echo "export PATH=$PATH:/usr/local/bin/pip" >> ~/.profile \
RUN curl -L "https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz" -o python.tgz \
&& tar -xvf python.tgz && cd Python-$PYTHON_VERSION \
&& ./configure --enable-optimizations \
&& make install \
&& cd .. && rm -rf Python-$PYTHON_VERSION python.tgz \
&& ln -s /usr/local/bin/pip3 /usr/bin/pip \
&& ln -s /usr/local/bin/python3 /usr/bin/python \
&& pip install --upgrade pip pipx && pipx ensurepath \
&& pipx install poetry


# Go
COPY --from=go-builder /usr/local/go/ /usr/local/go/
RUN echo "export PATH=$PATH:/usr/local/go/bin:/root/go/bin" >> ~/.profile
Expand All @@ -50,6 +54,10 @@ RUN echo "export PATH=/usr/lib/dart/bin:/root/.pub-cache/bin:$PATH" >> ~/.profil

# PHP
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
RUN apt-get update && apt-get install -y --no-install-recommends \
php${PHP_VERSION}-cli php${PHP_VERSION}-curl php${PHP_VERSION}-mbstring php${PHP_VERSION}-xml php${PHP_VERSION}-zip \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# SDKMAN
RUN curl -s "https://get.sdkman.io" | bash
Expand All @@ -73,6 +81,20 @@ RUN curl -L -o ruby.tar.gz https://github.com/postmodern/ruby-install/releases/d
COPY --from=csharp-builder /usr/share/dotnet /usr/share/dotnet
RUN echo "export PATH=$PATH:/usr/share/dotnet" >> ~/.profile && source ~/.profile

# Swift
RUN git clone https://github.com/apple/swift-format.git \
&& cd swift-format \
&& git checkout "release/$SWIFT_VERSION" \
&& swift build -c release \
&& swift test --parallel \
&& mv .build/release/swift-format /usr/bin \
&& cd .. \
&& rm -rf swift-format

# Clean up
RUN apt-get clean \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /app

CMD bash
100 changes: 100 additions & 0 deletions clients/algoliasearch-client-swift/.gitignore
@@ -0,0 +1,100 @@
# Created by https://www.toptal.com/developers/gitignore/api/xcode,swift
# Edit at https://www.toptal.com/developers/gitignore?templates=xcode,swift

### Swift ###
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## User settings
xcuserdata/

## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout

## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
build/
DerivedData/
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3

## Obj-C/Swift specific
*.hmap

## App packaging
*.ipa
*.dSYM.zip
*.dSYM

## Playgrounds
timeline.xctimeline
playground.xcworkspace

# Swift Package Manager
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
# Package.pins
Package.resolved
# *.xcodeproj
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
# hence it is not needed unless you have added a package configuration file to your project
.swiftpm

.build/

# CocoaPods
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
# Pods/
# Add this line if you want to avoid checking in source code from the Xcode workspace
# *.xcworkspace

# Carthage
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build/

# Accio dependency management
Dependencies/
.accio/

# fastlane
# It is recommended to not store the screenshots in the git repo.
# Instead, use fastlane to re-generate the screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control

fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots/**/*.png
fastlane/test_output

# Code Injection
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/

### Xcode ###

## Xcode 8 and earlier

### Xcode Patch ###
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcodeproj/xcshareddata/
!*.xcworkspace/contents.xcworkspacedata
/*.gcno
**/xcshareddata/WorkspaceSettings.xcsettings

# End of https://www.toptal.com/developers/gitignore/api/xcode,swift
43 changes: 43 additions & 0 deletions clients/algoliasearch-client-swift/.swiftformat
@@ -0,0 +1,43 @@
# For rules on SwiftFormat, please refer to https://github.com/nicklockwood/SwiftFormat/blob/master/Rules.md
#
# file options

# uncomment below to exclude files, folders
#--exclude path/to/test1.swift,Snapshots,Build

# format options

--allman false
--binarygrouping 4,8
--commas always
--comments indent
--decimalgrouping 3,6
--elseposition same-line
--empty void
--exponentcase lowercase
--exponentgrouping disabled
--fractiongrouping disabled
--header ignore
--hexgrouping 4,8
--hexliteralcase uppercase
--ifdef indent
--indent 4
--indentcase false
--importgrouping testable-bottom
--linebreaks lf
--maxwidth none
--octalgrouping 4,8
--operatorfunc spaced
--patternlet hoist
--ranges spaced
--self remove
--semicolons inline
--stripunusedargs always
--swiftversion 5.4
--trimwhitespace always
--wraparguments preserve
--wrapcollections preserve

# rules

--enable isEmpty
2 changes: 2 additions & 0 deletions clients/algoliasearch-client-swift/Cartfile
@@ -0,0 +1,2 @@
github "Flight-School/AnyCodable" ~> 0.6
github "apple/swift-log" ~> 1.4
21 changes: 21 additions & 0 deletions clients/algoliasearch-client-swift/LICENSE
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Algolia

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

0 comments on commit 147035c

Please sign in to comment.