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

Update GitHub Action CI for Forks #220

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Build
on: [pull_request, workflow_dispatch]
on: [pull_request]
concurrency:
group: build-${{ github.event.number }}
cancel-in-progress: true
Expand All @@ -10,6 +10,9 @@ jobs:
steps:
- name: Check out repository
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hey Jax, thanks for doing this! Can you tell me how this allows CI to run as expected on forks? Just high level explanation would be fine!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ref Line

github.event references where we want to run CI (context docs) in our case we want to run CI on the pull_request. For PRs we want to run CI on the pull request's head branch name head.ref vs the base branch name (PR workflow events docs). So this line github.event.pull_request.head.ref is essentially saying: run CI on the branch the PR was opened from.

Repository Line

github.event.pull_request.head is the same as above so it's saying for the repository use the PRs head vs main. Then repo.full_name pulls the full path of the repo the fork is on vs attempting to pull the branch name from our path where it wouldn't exist (reference docs here).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you Jax!

- name: Use Xcode 14
run: sudo xcode-select -switch /Applications/Xcode_14.3.app
- name: Run pod lib lint
Expand All @@ -20,10 +23,13 @@ jobs:
steps:
- name: Check out repository
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: Use Xcode 14
run: sudo xcode-select -switch /Applications/Xcode_14.3.app
- name: Use current branch
run: sed -i '' 's/branch = .*/branch = \"'"$GITHUB_HEAD_REF"'\";/' SampleApps/SPMTest/SPMTest.xcodeproj/project.pbxproj
run: sed -i '' 's/branch = .*/branch = \"'"${GITHUB_HEAD_REF//\//\/}"'\";/' SampleApps/SPMTest/SPMTest.xcodeproj/project.pbxproj
- name: Run swift package resolve
run: cd SampleApps/SPMTest && swift package resolve
- name: Build & archive SPMTest
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Tests
on: [pull_request, workflow_dispatch]
on: [pull_request]
concurrency:
group: tests-${{ github.event.number }}
cancel-in-progress: true
Expand All @@ -10,6 +10,9 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: Use Xcode 14
run: sudo xcode-select -switch /Applications/Xcode_14.3.app
- name: Run Unit Tests
Expand Down
Loading