Skip to content

Instantly share code, notes, and snippets.

@paulz
Last active April 4, 2023 02:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulz/467d8eca5b08a59798c7cf7b76185d71 to your computer and use it in GitHub Desktop.
Save paulz/467d8eca5b08a59798c7cf7b76185d71 to your computer and use it in GitHub Desktop.
GitHub Actions workflows
name: test on Simulator
on:
workflow_dispatch:
schedule:
# At every 10th minute past every hour from 9 through 13.
# which is 1 am PST
- cron: '*/10 9-13 * * *' # https://crontab.guru/#*/10_9-13_*_*_*
pull_request:
branches:
- main
push:
branches:
- "**"
- "!experiment/**"
defaults:
run:
shell: zsh --login --errexit --pipefail {0}
env:
NSUnbufferedIO: YES # display xcodebuild output in the correct order for github action log
jobs:
build-and-test:
name: Build and Test
runs-on: self-hosted
timeout-minutes: 15
env:
resultBundlePath: test-results/tests-${{ github.run_number }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Ruby Gems
run: |
bundle config set --local path '/tmp/gem-bundle/${{ runner.name }}'
bundle install
- name: Resolve Package Dependencies
run: scripts/resolve-swift-package-dependencies.zsh /tmp/spm-clone/${{ runner.name }}
- name: Clear ProfileData
run: rm -rf /tmp/ci-derived-data/${{ runner.name }}/Build/ProfileData || true
- name: Build
run: >
./scripts/xcbuild-retry-clean.zsh
-scheme MyApp
-destination name=ipad-${{ runner.name }}
-clonedSourcePackagesDirPath /tmp/spm-clone/${{ runner.name }}
-derivedDataPath /tmp/ci-derived-data/${{ runner.name }}
build-for-testing | xcpretty --color
- name: Test
id: app-tests
run: >
xcodebuild
-project MyApp.xcodeproj
-scheme MyApp
-destination name=ipad-${{ runner.name }}
-resultBundlePath $resultBundlePath
-clonedSourcePackagesDirPath /tmp/spm-clone/${{ runner.name }}
-derivedDataPath /tmp/ci-derived-data/${{ runner.name }}
test-without-building | xcpretty --color
- name: Report Test Coverage
if: github.event_name != 'push' || github.ref == 'refs/heads/main'
run: ./scripts/ci/slather-coverage.zsh MyAppBinaryName MyAppScheme /tmp/ci-derived-data/${{ runner.name }}
env:
GIT_BRANCH: ${{ steps.get_branch.outputs.branch }}
CI_PULL_REQUEST: ${{ github.event.number }}
COVERAGE_ACCESS_TOKEN: ${{ github.token }}
IS_PARALLEL: true
- name: Upload Cobertura XML and HTML results
if: always()
uses: actions/upload-artifact@v3
with:
name: coverage-reports
path: html
- name: Archive results # due to: https://github.com/actions/upload-artifact/issues/243
if: always()
run: zip -FSry test-results.zip test-results || true
- name: Upload test results
if: always()
uses: actions/upload-artifact@v3
with:
name: consumer-test-results
path: consumer-results.zip
code-quality:
needs: [build-and-test]
name: Code Quality
runs-on: self-hosted
if: github.event_name != 'push' || github.ref == 'refs/heads/main'
timeout-minutes: 2
steps:
- name: Checkout for Coveralls
uses: actions/checkout@v3
- name: Coveralls Finish parallel runs
uses: coverallsapp/github-action@v1.2.2
with:
github-token: ${{ github.token }}
parallel-finished: true
- name: SwiftLint
run: swiftlint lint --strict
- name: Check formatting
run: swiftformat --lint .
#!/bin/zsh
if [[ $# -eq 1 ]]
then
echo Using Clone folder: $1
else
cat << EndOfUsage
Resolve Swift Packages Dependencies with one clean retry
Usage:
$ZSH_ARGZERO directory
directory is where to clone dependent Swift Packages
EndOfUsage
exit 1
fi
xcodebuild -resolvePackageDependencies -clonedSourcePackagesDirPath $1
if [[ $? == 0 ]]
then
echo Resolved Swift Packages Dependencies on the first try
else
echo Removing clone folder: $1
rm -rf $1
echo ::notice:: Retrying package resolution
xcodebuild -resolvePackageDependencies -clonedSourcePackagesDirPath $1
fi
#!/bin/zsh
# Uses slather gem on CI to
# 1. upload coverage report to coveralls
# 2. generate HTML coverage reports in html folder for artifacts
# 3. generate XML cobertura report in html folder for 5monkeys/cobertura-action
#
# $1 - app binary name
# $2 - xcode scheme
# $3 - derived data path or use ~/Library/Developer/Xcode/DerivedData if not specified
#
# Environment variables for Coverall upload:
# CI_PULL_REQUEST - github pull request
# GITHUB_REF - github source reference
# COVERAGE_ACCESS_TOKEN - Coverall access token
app=(--binary-basename $1)
scheme=$2
ddp=${3:-$HOME/Library/Developer/Xcode/DerivedData}
slather_coverage() {
bundle exec slather coverage $@ $app --scheme $scheme --build-directory $ddp
}
slather_coverage --html --output-directory html/$1
slather_coverage --cobertura-xml --output-directory html/$1
test -v GITHUB_REF && GIT_BRANCH=${GITHUB_REF#refs/heads/}
slather_coverage --github --coveralls --verbose
#!/bin/zsh
#
# Try incremental build and if fails retry clean
#
args=($@)
xcodebuild -project MyApp.xcodeproj $args
if [[ $? != 0 ]]
then
xcodebuild -project MyApp.xcodeproj clean $args
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment