-
Notifications
You must be signed in to change notification settings - Fork 9
90 lines (84 loc) · 2.72 KB
/
push_pr.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: Push/PR pipeline
on:
pull_request:
push:
branches:
- main
jobs:
rebase:
name: Branch needs rebase
runs-on: ubuntu-latest
if: github.event.pull_request
steps:
- uses: actions/checkout@v4
with:
# This job might fail for PRs with more than 50 commits. I take that as a feature.
fetch-depth: 50
- name: Check if PR is up to date with target branch
run: |
main=origin/${{ github.base_ref }}
git fetch origin ${{ github.base_ref }}
echo "Getting current HEAD"
target_head=$(git show-ref -s $main)
echo "Getting $main"
merge_base=$(git merge-base HEAD $main)
echo "Checking if current branch is up to date"
if [[ ${target_head} != ${merge_base} ]]; then
echo "Branch ${{ github.head_ref }} is not up to date with $main (${merge_base} != ${target_head}), please rebase"
exit 1
fi
echo "${target_head} = ${merge_base}"
exit 0
test:
name: Run tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: '1.19'
- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run tests
# CLI autodetects whether it is running on GHA or not. If we let GHA set this to true, as it normally does,
# tests cases where GITHUB_ACTIONS is expected to be unset would fail.
run: GITHUB_ACTIONS=false go test -race ./...
static-analysis:
name: Static analysis and linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: '1.19'
- uses: newrelic/newrelic-infra-checkers@v1
with:
# Use full list of linters, rather than the (default) limited set.
golangci-lint-config: golangci-lint
- name: Semgrep
uses: returntocorp/semgrep-action@v1
with:
auditOn: push
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
continue-on-error: ${{ github.event_name != 'pull_request' }}
with:
# to remove findings from commit history
skip-cache: true
codespell:
name: Codespell
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- name: Codespell test
uses: codespell-project/actions-codespell@master
with:
ignore_words_file: ./.codespellignore
skip: go.mod,go.sum