Skip to content

Add checkout-pr composite action #15

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

Merged
merged 2 commits into from
Aug 22, 2023
Merged
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
25 changes: 25 additions & 0 deletions .github/actions/checkout-pr/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: 'Checkout PR'
description: >-
Checkout the exact number of PR commits + 1 (base_ref).
inputs:
jobname:
default: ${{ github.job }}
runs:
using: "composite"
steps:
- name: 'PR commits + 1'
shell: bash
run: echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}"

- name: 'Checkout PR branch and all PR commits'
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: ${{ env.PR_FETCH_DEPTH }}
lfs: true

- name: 'Fetch the other branch with enough history for a common merge-base commit'
shell: bash
run: |
git fetch origin ${{ github.event.pull_request.base.ref }}
git log -n 1
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,22 @@

Collection of shared github actions which are used in our org.

## PR Checkout

The checkout PR action will fetch only the commits that belong to the PR.
This is required for various code analysis tooling, including sonarcloud.

Example usage:

```
jobs:
golangci-lint:
runs-on: ubuntu-latest
steps:
- name: Checkout PR
uses: TykTechnologies/github-actions/.github/actions/checkout-pr@main
```

## OWASP scanner
Example usage: