Last active
December 11, 2022 16:52
-
-
Save alexnikol/70b9126bba846a2dfa811193c7006176 to your computer and use it in GitHub Desktop.
GitHub Actions workflow build, tests, send test coverage to code climate and show tests result convenient way in report page, Appstore deployment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Name which will be visible in Github Actions tab in repository | |
name: CI iOS | |
# Trigger which will run this workflow. (any pull request in main page) | |
on: | |
pull_request: | |
branches: [ main ] | |
jobs: | |
build-and-test: | |
runs-on: macos-12 | |
timeout-minutes: 30 | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Select Xcode | |
run: sudo xcode-select -switch /Applications/Xcode_13.4.1.app | |
- name: Xcode version | |
run: /usr/bin/xcodebuild -version | |
- name: Build and Test | |
run: xcodebuild clean build test -workspace PodcatsAppiOS/PodcatsAppiOS.xcworkspace -scheme "CI_iOS" CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO -sdk iphonesimulator -destination "platform=iOS Simulator,name=iPhone 13,OS=15.5" ONLY_ACTIVE_ARCH=YES -resultBundlePath CIiOSResults -derivedDataPath /tmp/XcodeDerivedDataWithCoverage | |
# 3rd party script for showing result in Github Actions screen | |
- uses: kishikawakatsumi/xcresulttool@v1 | |
with: | |
path: CIiOSResults.xcresult | |
if: success() || failure() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy Podcats iOS | |
on: | |
push: | |
branches: [ deploy/deploy_podcast_iphone_ios ] | |
jobs: | |
deploy: | |
runs-on: macos-12 | |
timeout-minutes: 30 | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Select Xcode | |
run: sudo xcode-select -switch /Applications/Xcode_13.4.1.app | |
- name: Xcode version | |
run: /usr/bin/xcodebuild -version | |
# secrets.SECRET_KEY saved in secrets sections of repository used for decryption provision file | |
- name: Install provisioning profile | |
run: | | |
gpg --quiet --batch --yes --decrypt --passphrase="${{ secrets.SECRET_KEY }}" --output .github/secrets/Podcats_iOS.mobileprovision .github/secrets/Podcats_iOS.mobileprovision.gpg | |
mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles | |
cp .github/secrets/Podcats_iOS.mobileprovision ~/Library/MobileDevice/Provisioning\ Profiles/ | |
# secrets.SECRET_KEY saved in secrets sections of repository used for decryption keychain certificate | |
- name: Install keychain certificate | |
run: | | |
gpg --quiet --batch --yes --decrypt --passphrase="${{ secrets.SECRET_KEY }}" --output .github/secrets/com.podcats.app.product.iOS.p12 .github/secrets/com.podcats.app.product.iOS.p12.gpg | |
security create-keychain -p "" build.keychain | |
security import .github/secrets/com.podcats.app.product.iOS.p12 -t agg -k ~/Library/Keychains/build.keychain -P "" -A | |
security list-keychains -s ~/Library/Keychains/build.keychain | |
security default-keychain -s ~/Library/Keychains/build.keychain | |
security unlock-keychain -p "" ~/Library/Keychains/build.keychain | |
security set-key-partition-list -S apple-tool:,apple: -s -k "" ~/Library/Keychains/build.keychain | |
# Auto increment for build number. It will change info.plist value | |
- name: Set build number | |
run: | | |
buildNumber=$(($GITHUB_RUN_NUMBER + 1)) | |
echo $buildNumber | |
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" PodcatsAppiOS/PodcatsAppiOS/Info.plist | |
# Archiving project, make sure to change paramters to yours like -workspace, --scheme, etc | |
- name: Archive | |
run: | | |
xcodebuild clean archive \ | |
-sdk iphoneos \ | |
-workspace PodcatsAppiOS/PodcatsAppiOS.xcworkspace \ | |
-configuration "Release" \ | |
-scheme "Podcats" \ | |
-derivedDataPath "DerivedData" \ | |
-archivePath "DerivedData/Archive/Podcats.xcarchive" \ | |
# Export ipa file | |
- name: Export | |
run: | | |
xcodebuild -exportArchive \ | |
-archivePath DerivedData/Archive/Podcats.xcarchive \ | |
-exportOptionsPlist .github/secrets/exportOptions.plist \ | |
-exportPath DerivedData/ipa \ | |
# Deploy build to Testflight. secrets.APPLEID_USERNAME and secrets.APPLEID_PASSWORD are secrets from secrets section in repo | |
- name: Deploy | |
run: | | |
xcrun altool \ | |
--upload-app \ | |
--type ios \ | |
--file "DerivedData/ipa/Podcats.ipa" \ | |
--username "${{ secrets.APPLEID_USERNAME }}" \ | |
--password "${{ secrets.APPLEID_PASSWORD }}" \ | |
--verbose \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Converts SomeDistribution.p12 -> SomeDistribution.p12.gpg | |
gpg --symmetric --cipher-algo AES256 SomeDistribution.p12 | |
# Converts Some.mobileprovision -> Some.mobileprovision.gpg | |
gpg --symmetric --cipher-algo AES256 Some.mobileprovision |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Main | |
on: | |
push: | |
branches: [ main ] | |
jobs: | |
test-and-gather-test-coverage: | |
runs-on: macos-12 | |
timeout-minutes: 30 | |
steps: | |
- uses: actions/checkout@v2 | |
# command line tools for converation Xcode reports to Cobertura reports | |
- name: Slather install | |
run: sudo gem install slather | |
- name: Select Xcode | |
run: sudo xcode-select -switch /Applications/Xcode_13.4.1.app | |
- name: Xcode version | |
run: /usr/bin/xcodebuild -version | |
# run build and test xcodeproject, make sure to set derivedDataPath like here. Slather will look for this path | |
- name: CI_iOS Build and Test | |
run: | | |
xcodebuild clean build test \ | |
-workspace PodcatsAppiOS/PodcatsAppiOS.xcworkspace \ | |
-scheme "CI_iOS" \ | |
CODE_SIGN_IDENTITY="" \ | |
CODE_SIGNING_REQUIRED=NO \ | |
-sdk iphonesimulator \ | |
-destination "platform=iOS Simulator,name=iPhone 13,OS=15.5" \ | |
ONLY_ACTIVE_ARCH=YES \ | |
-resultBundlePath CIiOSResults \ | |
-derivedDataPath /tmp/XcodeDerivedDataWithCoverageCIiOS \ | |
# 3rd party tool for publishing code coverage report (In Cobertura) to Codeclimate server | |
- name: Publish code coverage | |
uses: paambaati/codeclimate-action@v3.2.0 | |
env: | |
# Secret ID from codeclimate saved in repository secrets section | |
CC_TEST_REPORTER_ID: "${{ secrets.CC_TEST_REPORTER_ID }}" | |
with: | |
debug: true | |
# Make sure to change all paramters like --scheme, --workspace to yours | |
coverageCommand: | | |
slather coverage -x --scheme "CI_iOS" --workspace "PodcatsAppiOS/PodcatsAppiOS.xcworkspace" --output-directory "slather_reports/CI_iOS" -b "/tmp/XcodeDerivedDataWithCoverageCIiOS" "PodcatsAppiOS/PodcatsAppiOS.xcodeproj" | |
coverageLocations: | | |
${{github.workspace}}/slather_reports/CI_iOS/cobertura.xml:cobertura |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment