Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alfmob 33 implemented ci cd #7

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
81 changes: 19 additions & 62 deletions Alfie/.github/workflows/alfie.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,13 @@ jobs:
- name: Checkout Code
uses: actions/checkout@v3

- name: Install SwiftLint
run: brew install swiftlint

- name: Run Code Linting
run: swiftlint

- name: Run Static Code Analysis
run: |
xcodebuild analyze \
-scheme Alfie \
-destination "${{ env.IOS_DESTINATION }}"
- name: Install Fastlane
run: gem install fastlane

- name: Run Unit Tests
run: |
xcodebuild test \
-scheme Alfie \
-destination "${{ env.IOS_DESTINATION }}"
- name: Run Linting, Analysis, and Tests
run: fastlane validate_branch
env:
IOS_DESTINATION: ${{ env.IOS_DESTINATION }}

testflight-build:
p4checo marked this conversation as resolved.
Show resolved Hide resolved
needs: branch-validation
Expand All @@ -47,55 +37,22 @@ jobs:

- name: Set up SSH for Bitbucket
run: |
mkdir -p ~/.ssh
echo "${{ secrets.BITBUCKET_SSH_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -t rsa bitbucket.org >> ~/.ssh/known_hosts
mkdir -p ~/.ssh
echo "${{ secrets.BITBUCKET_SSH_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -t rsa bitbucket.org >> ~/.ssh/known_hosts

- name: Install Fastlane
run: |
brew install fastlane
gem install bundler
bundle install --path vendor/bundle
run: gem install fastlane

- name: Run Fastlane Match
run: |
bundle exec fastlane match appstore
- name: Deploy to TestFlight
run: fastlane beta
env:
MATCH_GIT_URL: ${{ secrets.MATCH_GIT_URL }}
MATCH_GIT_BRANCH: ${{ secrets.MATCH_GIT_BRANCH }}
MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
ASC_KEY_ID: ${{ secrets.ASC_KEY_ID }}
ASC_ISSUER_ID: ${{ secrets.ASC_ISSUER_ID }}
ASC_API_KEY_FILEPATH: ${{ secrets.API_KEY_PATH }}

- name: Increment Build Number
run: agvtool next-version -all

- name: Configure Git User
run: |
git config --global user.name "${{ secrets.GIT_USER_NAME }}"
git config --global user.email "${{ secrets.GIT_EMAIL }}"

- name: Commit and Push Build Number
env:
GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }}
run: |
git add .
git commit -m "Increment build to $(agvtool what-version -terse)"
git push origin HEAD

- name: Build and Archive
run: |
xcodebuild clean archive \
-scheme Alfie \
-archivePath $PWD/build/App.xcarchive

- name: Export IPA
run: |
xcodebuild -exportArchive -archivePath $PWD/build/App.xcarchive \
-exportOptionsPlist ExportOptions.plist -exportPath $PWD/build

- name: Deploy to TestFlight
run: |
fastlane pilot upload -i $PWD/build/App.ipa
ASC_API_KEY: ${{ secrets.APP_STORE_CONNECT_API_KEY }}
MATCH_GIT_URL: ${{ secrets.MATCH_GIT_URL }}
MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
GIT_USER_NAME: ${{ secrets.GIT_USER_NAME }}
GIT_EMAIL: ${{ secrets.GIT_EMAIL }}
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
2 changes: 0 additions & 2 deletions Alfie/fastlane/Appfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
app_identifier("com.mindera.alfie.debug") # The bundle identifier of your app
apple_id("[email protected]") # Your Apple Developer Portal username

itc_team_id("116567802") # App Store Connect Team ID
team_id("74L475LDQT") # Developer Portal Team ID

Expand Down
40 changes: 34 additions & 6 deletions Alfie/fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,41 @@
# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane

default_platform(:ios)

platform :ios do
desc "Push a new beta build to TestFlight"
desc "Validate branch with linting, analysis, and tests"
lane :validate_branch do
sh("swiftlint") # Runs SwiftLint
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a swiftlint fastlane action. I have mixed feelings about bundling swiftlint executable in the project, but I tend to prefer it being povided externally (e.g. via brew, SPM plugin, ...)

sh("xcodebuild analyze -scheme Alfie -destination '#{ENV['IOS_DESTINATION']}'")
sh("xcodebuild test -scheme Alfie -destination '#{ENV['IOS_DESTINATION']}'")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps use run_tests action (aka scan) ?

https://docs.fastlane.tools/getting-started/ios/running-tests/

We can also set SCAN_DESTINATION and any other env var once which then gets passed automatically to each fastlane action. Take a look here for scan's parameters, for instance.

end

desc "Deploy to TestFlight using Git tags"
lane :beta do
increment_build_number(xcodeproj: "Alfie.xcodeproj")
build_app(scheme: "Alfie")
upload_to_testflight
api_key = app_store_connect_api_key(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to store the api_key, as this action stores it on the environment for subsequent actions to use (such as upload_to_testflight, match, etc)

key_id: ENV['ASC_KEY_ID'],
issuer_id: ENV['ASC_ISSUER_ID'],
key_filepath: ENV['ASC_API_KEY']
)

match(type: "appstore", readonly: false, api_key: api_key)

increment_build_number
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are incrementing the build number, but how is it updated after each build?

Shouldn't we get the last tag's value, extract the BN, then increment and set it on the Xcode project instead?


version = get_version_number(xcodeproj: "Alfie.xcodeproj")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can and probably should store the Xcode project's path on an env var, which avoids duplication and possible errors.

build_number = get_build_number(xcodeproj: "Alfie.xcodeproj")
sh("git config user.name '#{ENV['GIT_USER_NAME']}'")
sh("git config user.email '#{ENV['GIT_EMAIL']}'")
sh("git tag v#{version}-#{build_number}")
sh("git push origin --tags")

build_app(
scheme: "Alfie",
export_options: { method: "app-store" },
api_key: api_key
)

upload_to_testflight(api_key: api_key)
end
end