Skip to content

Commit 2afcf0d

Browse files
committed
build(workflows): execute the CI via GitHub Actions
1 parent 624689f commit 2afcf0d

File tree

2 files changed

+84
-1
lines changed

2 files changed

+84
-1
lines changed

.github/workflows/ci.yml

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Tests and Linters Scalingo go-utils Packages
2+
3+
on: [push]
4+
5+
# # The list of permissions is explained on the GitHub doc:
6+
# # https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs
7+
# permissions:
8+
# # allow read access to pull request. Use with golangci-lint `only-new-issues` option.
9+
# pull-requests: read
10+
11+
jobs:
12+
detect-modules:
13+
name: Detect the Go modules declared in go-utils
14+
runs-on: ubuntu-22.04
15+
outputs:
16+
modules: ${{ steps.set-modules.outputs.modules }}
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
# We need to define the fetch-depth to 0 so that we can get the commit ID of the master branch
21+
fetch-depth: 0
22+
- uses: actions/setup-go@v5
23+
with:
24+
go-version: stable
25+
check-latest: true
26+
- id: set-modules
27+
run: |
28+
echo -n "modules=" > $GITHUB_OUTPUT
29+
for m in ./*/*go.mod; do
30+
pushd $(dirname "$m") > /dev/null
31+
module_path="$(go list -m -json | jq --slurp '.' | jq --compact-output --raw-output '.[].Dir')"
32+
echo $module_path
33+
popd > /dev/null
34+
done | jq --raw-input --slurp 'split("\n")' | jq --compact-output 'map(select(length > 0))' >> $GITHUB_OUTPUT
35+
36+
linter-pull-request:
37+
needs: detect-modules
38+
name: golangci-lint on a PR or from a tag
39+
runs-on: ubuntu-22.04
40+
strategy:
41+
matrix:
42+
modules: ${{ fromJSON(needs.detect-modules.outputs.modules) }}
43+
if: github.ref != 'refs/heads/master'
44+
steps:
45+
- uses: actions/checkout@v4
46+
with:
47+
# We need to define the fetch-depth to 0 so that we can get the commit ID of the master branch
48+
fetch-depth: 0
49+
- uses: actions/setup-go@v5
50+
with:
51+
go-version: stable
52+
check-latest: true
53+
- name: Get golangci-lint configuration file
54+
run: wget --output-document=$(pwd)/.golangci.yml https://sc-devtools.s3.eu-west-1.amazonaws.com/golang-ci/golangci.yml
55+
- name: Get master branch commit ID
56+
id: new-from-rev
57+
run: echo "NEW_FROM_REV=$( git rev-parse origin/master )" >> "$GITHUB_OUTPUT"
58+
- name: "Execute golangci-lint on a pull request"
59+
uses: golangci/golangci-lint-action@v6
60+
with:
61+
working-directory: ${{ matrix.modules }}
62+
# The `only-new-issues` flag is not working (https://github.com/golangci/golangci-lint-action/issues/531).
63+
# We rather decided to use the suggestion from the FAQ (https://golangci-lint.run/welcome/faq/#how-to-integrate-golangci-lint-into-large-project-with-thousands-of-issues) and use `--new-from-rev`
64+
# only-new-issues: false
65+
args: "--config=$(pwd)/../.golangci.yml --new-from-rev=${{ steps.new-from-rev.outputs.NEW_FROM_REV }} --modules-download-mode=mod"
66+
67+
68+
tests:
69+
needs: detect-modules
70+
name: Unit Tests
71+
runs-on: ubuntu-22.04
72+
strategy:
73+
matrix:
74+
modules: ${{ fromJSON(needs.detect-modules.outputs.modules) }}
75+
steps:
76+
- uses: actions/checkout@v4
77+
- uses: actions/setup-go@v5
78+
with:
79+
go-version: stable
80+
check-latest: true
81+
- name: Execute the tests
82+
working-directory: ${{ matrix.modules }}
83+
run: go test -race ./...

pagination/pagination.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func New[T any](data T, pageRequest Request, totalCount int64) Paginated[T] {
3939
CurrentPage: pageRequest.Page,
4040
PerPage: pageRequest.PerPage,
4141
PrevPage: prevPage,
42-
NextPage: nextPage,
42+
NextPage: 0,
4343
TotalPages: totalPages,
4444
TotalCount: totalCount,
4545
},

0 commit comments

Comments
 (0)