Skip to content

Commit

Permalink
MOB-45857 (#69)
Browse files Browse the repository at this point in the history
* Клонируем репозиторий вместо загрузки

* Убрал лишнее при клонировании

* Убрал кэш, т.к. не нужен

* Trigger Build

* Trigger Build

---------

Co-authored-by: Timur Shafigullin <hometim55@gmail.com>
Co-authored-by: v.barabanov <v.barabanov@Brbnkn-MBPro-2.local>
  • Loading branch information
3 people authored Feb 27, 2025
1 parent d04cf03 commit 50bcf64
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 62 deletions.
14 changes: 7 additions & 7 deletions Example/.analyticsGen.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
HR-Mobile:
sha: b2f2b9ab6168e7335aee4316e4379d2d299b0a3b
version: 0.5.5
Shared:
sha: b2f2b9ab6168e7335aee4316e4379d2d299b0a3b
version: 0.5.5
sha: 40a1900a6733c3e64d1b82e1492df7b3daef711c
version: 0.6.0
Applicant:
sha: b2f2b9ab6168e7335aee4316e4379d2d299b0a3b
version: 0.5.5
sha: 40a1900a6733c3e64d1b82e1492df7b3daef711c
version: 0.6.0
Shared:
sha: 40a1900a6733c3e64d1b82e1492df7b3daef711c
version: 0.6.0
10 changes: 6 additions & 4 deletions Example/.analyticsGen.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source:
gitHub:
remoteRepo:
owner: hhru
repo: hh-mobile-analytics
ref:
Expand Down Expand Up @@ -29,25 +29,27 @@ source:
value: ^PORTFOLIO-\d+$
branch_regex: PORTFOLIO-\d+
- type: last_merged
branch: develop
merge_commit_count: 100
branch_regex: PORTFOLIO-\d+
- type: last_tag
- type: last_commit
branch: master
accessToken:
env: GITHUB_API_TOKEN
env: GIT_REMOTE_API_TOKEN
keychain:
service: GitHub Token
service: Forgejo Token
key: hh
platform: iOS
targets:
- name: Applicant
path: schemas/applicant
destination: Features/Applicant/Foundation/ApplicantAnalyticsEvents/Sources/Generated/AnalyticsGen
- name: HR-Mobile
path: schemas/hr-mobile
destination: Features/Employer/Foundation/EmployerAnalyticsEvents/Sources/Generated/AnalyticsGen
- name: Shared
path: schemas/shared
destination: Features/Shared/Foundation/AnalyticsEvents/Sources/Generated/AnalyticsGen
template:
internal:
options:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import AnalyticsGenTools
import ZIPFoundation

struct ForgejoRemoteRepoProvider: RemoteRepoProvider {

// MARK: - Instance Properties

let baseURL: URL
let httpService: HTTPService

Expand All @@ -20,55 +19,27 @@ struct ForgejoRemoteRepoProvider: RemoteRepoProvider {
// MARK: - RemoteRepoProvider

func fetchRepo(owner: String, repo: String, ref: String, token: String, key: String) -> Promise<URL> {
let downloadURL = baseURL
.appendingPathComponent("repos")
.appendingPathComponent(owner)
.appendingPathComponent(repo)
.appendingPathComponent("archive")
.appendingPathComponent("\(ref).zip")

return Promise { seal in
httpService
.downloadRequest(
route: HTTPRoute(
method: .get,
url: downloadURL,
headers: [.authorization(bearerToken: token)]
)
)
.responseData { httpResponse in
switch httpResponse.result {
case .success(let data):
let fileManager = FileManager.default

let archiveFileURL = fileManager
.temporaryDirectory
.appendingPathComponent("remote-schemas-\(key).zip")

let destinationPathURL = fileManager
.temporaryDirectory
.appendingPathComponent("remote-schema-\(key)")

do {
try data.write(to: archiveFileURL)
try? fileManager.removeItem(at: destinationPathURL)
try fileManager.createDirectory(at: destinationPathURL, withIntermediateDirectories: true)
try fileManager.unzipItem(at: archiveFileURL, to: destinationPathURL)

let repoPathURL = try fileManager.contentsOfDirectory(
at: destinationPathURL,
includingPropertiesForKeys: nil
)

seal.fulfill(repoPathURL[0])
} catch {
seal.reject(error)
}

case .failure(let error):
seal.reject(error)
}
}
perform(on: .global()) {
Log.debug("Checking out source code from Forgejo...")

let host = try baseURL.host.throwing()
let gitRepositoryURL = "git@\(host):\(owner)/\(repo).git"

let repositoryPathURL = FileManager.default.temporaryDirectory.appendingPathComponent("\(repo)-\(key)")
let repositoryPath = repositoryPathURL.path

if FileManager.default.directoryExists(atPath: repositoryPath) {
Log.debug("Cleaning repository directory...")
try FileManager.default.removeItem(atPath: repositoryPath)
}

Log.debug("Cloning repository...")
try shell("git clone --depth 1 \(gitRepositoryURL) \(repositoryPath)")

Log.debug("Checking out \(ref) branch...")
try shell("cd \(repositoryPath) && git checkout \(ref)")

return repositoryPathURL
}
}

Expand Down
10 changes: 10 additions & 0 deletions Sources/AnalyticsGenTools/Extensions/FileManager+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Foundation

extension FileManager {

public func directoryExists(atPath path: String) -> Bool {
var isDirectory: ObjCBool = true
let exists = FileManager.default.fileExists(atPath: path, isDirectory: &isDirectory)
return exists && isDirectory.boolValue
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ extension Optional {
public var isNil: Bool {
self == nil
}

public func throwing() throws -> Wrapped {
if let wrapped = self {
return wrapped
} else {
throw MessageError("Failed to unwrap optional value.")
}
}
}

extension Optional where Wrapped: Collection {
Expand Down
2 changes: 2 additions & 0 deletions Sources/AnalyticsGenTools/Shared/Shell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public func shell(_ command: String) throws -> String {
task.executableURL = URL(fileURLWithPath: "/bin/zsh")
task.standardInput = nil

Log.debug("shell(\(command))")

try task.run()

let data = pipe.fileHandleForReading.readDataToEndOfFile()
Expand Down

0 comments on commit 50bcf64

Please sign in to comment.