Signal-iOS/.github/workflows/main.yml
Evan Hahn 84ebba40a2 CI: only run precommit script for pull requests
According to [GitHub's docs][0], the `github.base_ref` property "is only
available when the event that triggers a workflow run is either
`pull_request` or `pull_request_target`.

Because of this, pushes were running the following command...

    python3 Scripts/precommit.py --ref origin/

...and getting this error:

    fatal: ambiguous argument 'origin/': unknown revision or path not in the working tree.

This has been broken for a long time, but it didn't cause CI to fail until
d7c33eb211.

After some discussion, we decided not to run these on pushes to `master`
or `release/*`.

(See also: [this GitHub issue][1] which asks for clarification.)

[0]: https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
[1]: https://github.com/github/docs/issues/13810
2022-04-04 09:57:24 -05:00

127 lines
4.4 KiB
YAML

name: CI
on:
pull_request:
push:
branches:
- master
- release/*
jobs:
build_and_test:
name: Build and Test
runs-on: macos-11
steps:
- name: Setup environment
shell: bash
run: |
# Set this if there's a code change that requires a newer Xcode than the default
REQUIRED_VERSION=13.0
CURRENT_VERSION=$(xcodebuild -version | grep "Xcode" | awk '{print $2}')
echo "Current Xcode version: $CURRENT_VERSION"
echo "Required Xcode version: $REQUIRED_VERSION"
if [[ $CURRENT_VERSION < $REQUIRED_VERSION ]]; then
# Path format pulled from https://github.com/actions/virtual-environments/blob/main/images/macos/macos-11-Readme.md#xcode
NEW_XCODE="/Applications/Xcode_$REQUIRED_VERSION.app"
echo "Updating selected Xcode to $NEW_XCODE"
sudo xcode-select -s $NEW_XCODE
CURRENT_VERSION=$(xcodebuild -version | grep "Xcode" | awk '{print $2}')
echo "$?: Current Xcode version: $CURRENT_VERSION"
fi
- name: Checkout Repo
uses: actions/checkout@v2
with:
# Check out submodules through GitHub instead of from scratch later.
# THIS STEP WILL FAIL if the current Pods commit is only available in Private.
# However, we can continue and the build will still pass.
submodules: recursive
continue-on-error: true
- name: Initialize workflow variables
id: vars
shell: bash
run: |
# check for ACCESS_TOKEN availability (work-around for inaccessible 'secrets' object for 'if'; see <https://github.community/t5/GitHub-Actions/jobs-lt-job-id-gt-if-does-not-work-with-env-secrets/m-p/38549>)
if [ -z $ACCESS_TOKEN ]; then unset HAS_ACCESS_TOKEN ; else HAS_ACCESS_TOKEN='true' ; fi
echo ::set-output name=HAS_ACCESS_TOKEN::${HAS_ACCESS_TOKEN}
env:
ACCESS_TOKEN: "${{ secrets.ACCESS_TOKEN }}"
# Checkout private pods repo iff we have an access token to read private repos
- name: Checkout Private Pods
uses: actions/checkout@v2
# if: secrets.ACCESS_TOKEN (not supported {yet?}; see <https://github.community/t5/GitHub-Actions/jobs-lt-job-id-gt-if-does-not-work-with-env-secrets/m-p/38549>)
if: steps.vars.outputs.HAS_ACCESS_TOKEN
with:
repository: signalapp/signal-pods-private
token: ${{ secrets.ACCESS_TOKEN }}
path: Pods
# We don't know which commit we'll need in this step, so fetch everything so that
# `make dependencies` doesn't end up doing it the slow way.
fetch-depth: 0
- name: Initialize Submodules
run: make dependencies
- name: Setup Ruby
uses: ruby/setup-ruby@v1 # Reads .ruby-version file by default
- name: Cache Bundle Install
uses: actions/cache@v1
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-
- name: Bundle Install
run: |
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
- name: Build and Test
run: |
function formatFailures() {
grep '<failure message' fastlane/test_output/report.junit | sed -E "s/^.*<failure message='(.*)'>(.*):([0-9]+)<\/failure>/::error file=\2,line=\3::\1/" | sed -E 's/&quot;/"/g'
exit 1
}
bundle exec fastlane scan --scheme Signal --output_types junit || formatFailures
- name: Upload build logs
uses: actions/upload-artifact@v2
if: failure()
with:
name: Logs
path: ~/Library/Logs/scan
lint:
name: Lint
runs-on: macos-11
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v2
- name: Fetch base commit
run: git fetch origin --depth 1 ${{ github.base_ref }}
- name: Install Dependencies
run: brew install clang-format python3
- name: Lint files changed in the PR
run: |
python3 Scripts/precommit.py --ref origin/${{ github.base_ref }}
# https://help.github.com/en/actions/reference/development-tools-for-github-actions#logging-commands
git diff --name-only | sed -E 's|(.*)|::error file=\1::Incorrectly formatted (Scripts/precommit.py)|'
git diff --quiet || exit 1