diff --git a/.github/workflows/preflight-pull-request-check.yml b/.github/workflows/preflight-pull-request-check.yml new file mode 100644 index 0000000..5307842 --- /dev/null +++ b/.github/workflows/preflight-pull-request-check.yml @@ -0,0 +1,40 @@ +name: Preflight Code Checks + +on: pull_request + +jobs: + Preflight-Code-Checks: + runs-on: self-hosted + steps: + - uses: actions/checkout@v3 + - name: Check for Changes + id: repo-fetch-changes + run: | + echo "-> Source: ${{ github.head_ref }} (${{ github.event.pull_request.head.sha }})" + echo "-> Target: ${{ github.base_ref }} (${{ github.event.pull_request.base.sha }})" + # Fetching base ref + git fetch --prune --no-tags --depth=1 origin +refs/heads/${{ github.base_ref }}:refs/heads/${{ github.base_ref }} + + against=${{ github.event.pull_request.base.sha }} + EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) + + echo "changed_files<<$EOF" >> $GITHUB_ENV + + changed_files=$(git --no-pager diff-index --cached --diff-filter=ACMR --name-only --relative $against -- '*.swift') + + echo "$changed_files" >> $GITHUB_ENV + echo "$EOF" >> $GITHUB_ENV + - name: Code Format Validation + if: env.changed_files != '' + run: | + modified_file_list="${{ github.workspace }}/modified_file_list" + + echo "${{ env.changed_files }}" > $modified_file_list + + swiftformat --filelist "$modified_file_list" --lint --config ${{ github.workspace }}/.swiftformat --swiftversion 5 --reporter github-actions-log + - name: Linting Code + if: env.changed_files != '' + run: | + modified_files=$(cat "${{ github.workspace }}/modified_file_list") + + swiftlint lint --config ${{ github.workspace }}/.swiftlint --reporter "github-actions-logging" $modified_files diff --git a/Examples/GopherExample/GopherExample/DownloadQueue.swift b/Examples/GopherExample/GopherExample/DownloadQueue.swift index 18a8f7f..a44c5ad 100644 --- a/Examples/GopherExample/GopherExample/DownloadQueue.swift +++ b/Examples/GopherExample/GopherExample/DownloadQueue.swift @@ -11,7 +11,7 @@ final class DownloadQueue { enum Error: Swift.Error { - case empty + case Empty } var count: Int @@ -21,7 +21,7 @@ final class DownloadQueue private var queue: [DownloadItem] = [] - func add(url: URL, download_location: URL? = nil) + func add(url: URL, download_location _: URL? = nil) { queue.append(DownloadItem(url: url)) } @@ -33,7 +33,8 @@ final class DownloadQueue func clear() { - queue.forEach { item in + queue.forEach + { item in switch item.status { case .in_progress: @@ -154,7 +155,7 @@ extension DownloadQueue return url } - static private func imageFromFileSystem(for request: URLRequest) throws -> UIImage? + private static func imageFromFileSystem(for request: URLRequest) throws -> UIImage? { guard let url = fileName(for: request) else @@ -167,7 +168,7 @@ extension DownloadQueue return UIImage(data: data) } - static private func fileName(for urlRequest: URLRequest) -> URL? + private static func fileName(for urlRequest: URLRequest) -> URL? { guard let fileName = urlRequest.url?.absoluteString.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed), let applicationSupport = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first diff --git a/Examples/GopherExample/GopherExample/MovieInfoProvider.swift b/Examples/GopherExample/GopherExample/MovieInfoProvider.swift index 1891d29..5321555 100644 --- a/Examples/GopherExample/GopherExample/MovieInfoProvider.swift +++ b/Examples/GopherExample/GopherExample/MovieInfoProvider.swift @@ -24,9 +24,11 @@ extension MovieInfoProvider { func popular() async throws { + _ = URL(string: "https://road.to.nowhere")! let result: MovieResult = try await service.invoke(resource: .popular) - DispatchQueue.main.async { + DispatchQueue.main.async + { self.movies = result.results } } diff --git a/Examples/GopherExample/GopherExample/NetworkService.swift b/Examples/GopherExample/GopherExample/NetworkService.swift index a333568..582f404 100644 --- a/Examples/GopherExample/GopherExample/NetworkService.swift +++ b/Examples/GopherExample/GopherExample/NetworkService.swift @@ -16,7 +16,7 @@ final class NetworkService init(service: Gopher) { self.service = service - self.download_queue = DownloadQueue() + download_queue = DownloadQueue() } func invoke(resource: TheMovieDatabase, @@ -44,13 +44,13 @@ extension NetworkService private enum Header { - static let api_key = "api_key" + static let api_key = "api_key" static let language = "language" } - case auth_temp_token - case auth_new_session - case authenticate + case Auth_temp_token + case Auth_new_session + case Authenticate case popular case popular_persons case topRated @@ -139,7 +139,7 @@ extension NetworkService } } - static private func prepare_endpoint(with identifier: String = DefaultValue.empty_string, + private static func prepare_endpoint(with identifier: String = DefaultValue.empty_string, resource: String) -> String { let endpoint: String