Skip to content

Commit

Permalink
Enable fork PRs CI to run codecov
Browse files Browse the repository at this point in the history
For security reasons, fork PRs don't have access to secrets if we use
`pull_request` in GH Actions CI spec, only if we use
`pull_request_target`, which has its own security implications. See
https://securitylab.github.com/research/github-actions-preventing-pwn-requests/

Codecov status reporting in CI requires a token, so for fork PRs to
be able to do so we migrated to `pull_request_target` with the caveat
that MRs have to be labelled and have the `run ci` label applied,
which can only be done by someone with triage access to the repo. PRs
originating from the original repo shouldn't require a label.

This should give us a good compromise in terms of security.
  • Loading branch information
p4checo committed May 17, 2024
1 parent 3f11627 commit ee99bcd
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- master
tags:
- '[0-9]+\.[0-9]+\.[0-9]+'
pull_request:
pull_request_target: # forks don't have access to secrets if we use `pull_request`, which is required for codecov
branches:
- master

Expand All @@ -24,6 +24,10 @@ jobs:
env-details:
name: Environment details
runs-on: macos-14
if: |
github.event_name == 'push' ||
!github.event.pull_request.head.repo.fork ||
(github.event.pull_request.head.repo.fork && contains(github.event.pull_request.labels.*.name, 'run ci'))
steps:
- name: xcode version
run: xcodebuild -version -sdk
Expand All @@ -39,6 +43,10 @@ jobs:
build-test:
name: Build and Test
runs-on: macos-14
if: |
github.event_name == 'push' ||
!github.event.pull_request.head.repo.fork ||
(github.event.pull_request.head.repo.fork && contains(github.event.pull_request.labels.*.name, 'run ci'))
env:
WORKSPACE: Alicerce.xcworkspace
SCHEME: Alicerce
Expand Down Expand Up @@ -133,6 +141,10 @@ jobs:
swiftpm:
name: SwiftPM Build
runs-on: macos-14
if: |
github.event_name == 'push' ||
!github.event.pull_request.head.repo.fork ||
(github.event.pull_request.head.repo.fork && contains(github.event.pull_request.labels.*.name, 'run ci'))
env:
WORKSPACE: Alicerce.xcworkspace
SCHEME: "Alicerce (SPM)"
Expand Down Expand Up @@ -203,6 +215,10 @@ jobs:
cocoapods:
name: CocoaPods Verification
runs-on: macos-14
if: |
github.event_name == 'push' ||
!github.event.pull_request.head.repo.fork ||
(github.event.pull_request.head.repo.fork && contains(github.event.pull_request.labels.*.name, 'run ci'))
steps:
- name: git checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -232,6 +248,10 @@ jobs:
carthage:
name: Carthage Verification
runs-on: macos-14
if: |
github.event_name == 'push' ||
!github.event.pull_request.head.repo.fork ||
(github.event.pull_request.head.repo.fork && contains(github.event.pull_request.labels.*.name, 'run ci'))
env:
# Use Xcode 15.3 (latest) for Carthage to avoid iOS device/simulator version mismatches
DEVELOPER_DIR: "/Applications/Xcode_15.3.app/Contents/Developer"
Expand Down

0 comments on commit ee99bcd

Please sign in to comment.