diff --git a/.github/workflows/ios_lib.merge_request.yml b/.github/workflows/ios_lib.merge_request.yml new file mode 100644 index 0000000..b258bb1 --- /dev/null +++ b/.github/workflows/ios_lib.merge_request.yml @@ -0,0 +1,40 @@ +name: ios merge request + +on: + workflow_call: + inputs: + xcodeproj_path: + required: false + type: string + scheme_name: + required: false + type: string + +jobs: + check: + runs-on: macos-11 + steps: + - uses: actions/checkout@v2 + + - name: Set up ruby env + uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.7.2 + + - name: Bundle install + run: bundle install + + - name: tests lint + env: + XCODEPROJ_PATH: ${{ inputs.xcodeproj_path }} + SCHEME_NAME: ${{ inputs.scheme_name }} + run: bundle exec fastlane check + + swiftlint: + runs-on: ubuntu-latest + container: ghcr.io/realm/swiftlint:0.47.0 + steps: + - uses: actions/checkout@v3 + - run: swiftlint --quiet + + diff --git a/.github/workflows/ios_lib.publish.yml b/.github/workflows/ios_lib.publish.yml new file mode 100644 index 0000000..aa7ac68 --- /dev/null +++ b/.github/workflows/ios_lib.publish.yml @@ -0,0 +1,61 @@ +name: deploy_to_cocoapods + +on: + workflow_call: + secrets: + cocapods_trunk_token: + required: true + inputs: + xcodeproj_path: + required: false + type: string + scheme_name: + required: false + type: string + bump_type: + required: true + type: string + +jobs: + build: + + runs-on: macos-11 + + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.ref }} + + - name: Bundle install + run: | + brew install grep + bundle install + + - name: Release + id: release + run: | + git config user.name github-actions + git config user.email github-actions@github.com + bundle exec fastlane release type:${{ inputs.bump_type }} + NEW_CHANGES=$(cat fastlane/new_changes.txt) + echo "NEW_CHANGES<> $GITHUB_ENV + echo "$NEW_CHANGES" >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + BUMPED_VERSION=$(cat fastlane/version.txt) + echo "::set-output name=bumped_version::$BUMPED_VERSION" + env: + COCOAPODS_TRUNK_TOKEN: ${{ secrets.cocapods_trunk_token }} + XCODEPROJ_PATH: ${{ inputs.xcodeproj_path }} + SCHEME_NAME: ${{ inputs.scheme_name }} + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + tag_name: ${{ steps.release.outputs.bumped_version }} + release_name: ${{ steps.release.outputs.bumped_version }} + body: ${{ env.NEW_CHANGES }} + draft: false + prerelease: false \ No newline at end of file diff --git a/README.md b/README.md index e86aa7e..e21ae9f 100644 --- a/README.md +++ b/README.md @@ -74,4 +74,78 @@ jobs: java_version: '8' ``` -by default java is 11 \ No newline at end of file +by default java is 11 + +## iOS library workflow + +### Setup + +1. `./Gemfile` in the root repository: + +``` +source "https://rubygems.org" + +gem "cocoapods", "~> 1.11.3" +gem 'fastlane', '~> 2.204.3' +gem 'fastlane-plugin-changelog' +gem 'rubocop', '~> 0.93.1' # if exists +gem 'rubocop-require_tools' + +plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile') +eval_gemfile(plugins_path) if File.exist?(plugins_path) +``` + +2`fastlane/Fastfile` + +```ruby +import_from_git( + url: "https://github.com/tinkoff-mobile-tech/workflows.git", + path: "fastlane/Fastfile" +) +``` + +### setup merge request workflow + +```yaml +name: merge request + +on: + pull_request: + branches: + - 'master' + +jobs: + check: + uses: tinkoff-mobile-tech/workflows/.github/workflows/ios_lib.merge_request.yml@v1 + with: + xcodeproj_path: "TinkoffID.xcodeproj" + scheme_name: "TinkoffID-Package" +``` + +it calls `lint_fastfile`, `pod_lib_lint`, `swift package generate-xcodeproj`, `xcodebuild clean build`. + +### setup publications + +```yaml +name: publish + +on: + workflow_dispatch: + inputs: + bump_type: + default: "patch" + required: true + type: string + +jobs: + publish: + uses: tinkoff-mobile-tech/workflows/.github/workflows/ios_lib.publish.yml@v1 + with: + xcodeproj_path: "TinkoffID.xcodeproj" + scheme_name: "TinkoffID-Package" + bump_type: ${{ inputs.bump_type }} + secrets: + cocapods_trunk_token: ${{ secrets.COCOAPODS_TRUNK_TOKEN }} +``` + +it pushes to cocapods trunk. diff --git a/fastlane/Fastfile b/fastlane/Fastfile new file mode 100644 index 0000000..a59b612 --- /dev/null +++ b/fastlane/Fastfile @@ -0,0 +1,104 @@ +lane :release do |options| + # Checking bump type + bump_type = resolve_bump_type(options) + + # Checking that everything is alright + check + root_path = File.join(Dir.pwd, "..") + podspec_names = Dir.glob('*.podspec', base: root_path).select { |f| File.expand_path(f) } + # Bumping podspec version + for podspec_name in podspec_names + version = version_bump_podspec(path: podspec_name, bump_type: bump_type) + end + + add_files = extend_bump_version(version: version) + + text = read_changelog + changelog = File.open('new_changes.txt', "w") + changelog.puts(text) + changelog.close + + version_file = File.open('version.txt', "w") + version_file.puts(version) + version_file.close + + # Stamping changelog + stamp_changelog(section_identifier: version) + + # Creating release commit and tag + git_commit(path: ["CHANGELOG.md"] + podspec_names + add_files, message: "Release #{version}", skip_git_hooks: true) + add_git_tag(tag: version) + + # Pushing to remote repo + push_to_git_remote(tags: true) + + # Pushing podspec to Cocoapods repo + for podspec_name in podspec_names + push_podspec(podspec_name) + end +end + +lane :extend_bump_version do |options| + [] +end + +lane :check do + # Linting ruby files + lint_fastfile + + # Linting podspec + pod_lib_lint(allow_warnings: true) + + # Buidling Swift package + if(File.exist?('Package.swift')) + build_swift_package + end +end + +lane :build_swift_package do + project_name = ENV['XCODEPROJ_PATH'] + scheme_name = ENV['SCHEME_NAME'] + config_file_name = "Config.xcconfig" + + # Creating configuration file + sh("echo SWIFT_ACTIVE_COMPILATION_CONDITIONS=''> #{config_file_name}") + + # Generating xcode project + sh("swift package generate-xcodeproj --xcconfig-overrides #{config_file_name}") + + # Building generated xcode project + sh("xcodebuild clean build -project ../#{project_name} -sdk iphoneos -scheme '#{scheme_name}'") + + # Cleaning up + sh("rm -f #{config_file_name}") + sh("rm -rf ../#{project_name}") +end + +lane :lint_fastfile do + Dir.chdir("..") do + error_callback = lambda do |result| + UI.user_error!("rubocop execution failed: #{result}") + end + + if(File.exist?('.rubocop.yml')) + sh('bundle exec rubocop -c .rubocop.yml', error_callback: error_callback) + end + end +end + +def push_podspec(podspec_name) + pod_push( + path: podspec_name, + allow_warnings: true, + skip_tests: true + ) +end + +def resolve_bump_type(options) + valid_bump_types = ['patch', 'minor', 'major'] + bump_type = valid_bump_types.include?(options[:type]) ? options[:type] : nil + + UI.abort_with_message!("Bump type is not specified or incorrect! You can use `type: #{valid_bump_types.join('/')}` to specify it.") unless bump_type + + return bump_type +end