Skip to content

build(workflows): execute the CI via GitHub Actions #1144

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

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
87 changes: 87 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Tests and Linters Scalingo go-utils Packages

on: [push]

# # The list of permissions is explained on the GitHub doc:
# # https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs
# permissions:
# # allow read access to pull request. Use with golangci-lint `only-new-issues` option.
# pull-requests: read

jobs:
detect-modules:
name: Detect the Go modules declared in go-utils
runs-on: ubuntu-22.04
outputs:
modules: ${{ steps.set-modules.outputs.modules }}
steps:
- uses: actions/checkout@v4
with:
# We need to define the fetch-depth to 0 so that we can get the commit ID of the master branch
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version: stable
check-latest: true
- id: set-modules
run: |
echo -n "modules=" > $GITHUB_OUTPUT
for m in ./*/*go.mod; do
pushd $(dirname "$m") > /dev/null
module_path="$(go list -m -json | jq --slurp '.' | jq --compact-output --raw-output '.[].Dir')"
echo $module_path
popd > /dev/null
done | jq --raw-input --slurp 'split("\n")' | jq --compact-output 'map(select(length > 0))' >> $GITHUB_OUTPUT

linter-pull-request:
needs: detect-modules
name: golangci-lint on a PR or from a tag
runs-on: ubuntu-22.04
strategy:
matrix:
modules: ${{ fromJSON(needs.detect-modules.outputs.modules) }}
if: github.ref != 'refs/heads/master'
steps:
- uses: actions/checkout@v4
with:
# We need to define the fetch-depth to 0 so that we can get the commit ID of the master branch
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version: stable
check-latest: true
- name: Get golangci-lint configuration file
run: wget --output-document=$(pwd)/.golangci.yml https://sc-devtools.s3.eu-west-1.amazonaws.com/golang-ci/golangci.yml
- name: Get master branch commit ID
id: new-from-rev
run: echo "NEW_FROM_REV=$( git rev-parse origin/master )" >> "$GITHUB_OUTPUT"
- name: "Execute golangci-lint on a pull request"
uses: golangci/golangci-lint-action@v6
with:
working-directory: ${{ matrix.modules }}
# The `only-new-issues` flag is not working (https://github.com/golangci/golangci-lint-action/issues/531).
# 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`
# only-new-issues: false
args: "--config=$(pwd)/../.golangci.yml --new-from-rev=${{ steps.new-from-rev.outputs.NEW_FROM_REV }} --modules-download-mode=mod"


tests:
needs: detect-modules
name: Unit Tests
runs-on: ubuntu-22.04
strategy:
matrix:
modules: ${{ fromJSON(needs.detect-modules.outputs.modules) }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
check-latest: true
- name: Start MongoDB
uses: supercharge/[email protected]
with:
mongodb-version: 4.0.3
- name: Execute the tests
working-directory: ${{ matrix.modules }}
run: go test -race ./...
3 changes: 2 additions & 1 deletion cronsetup/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module github.com/Scalingo/go-utils/cronsetup

go 1.22
go 1.23.0

toolchain go1.23.7

require (
Expand Down
6 changes: 3 additions & 3 deletions difflib/difflib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ group
}
}

func ExampleGetUnifiedDiffCode() {
func ExampleGetUnifiedDiffString() {
a := `one
two
three
Expand Down Expand Up @@ -135,7 +135,7 @@ four`
// -fmt.Printf("%s,%T",a,b)
}

func ExampleGetContextDiffCode() {
func ExampleGetContextDiffString() {
a := `one
two
three
Expand Down Expand Up @@ -172,7 +172,7 @@ four`
// four
}

func ExampleGetContextDiffString() {
func ExampleGetContextDiffString_second() {
a := `one
two
three
Expand Down
3 changes: 2 additions & 1 deletion etcd/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module github.com/Scalingo/go-utils/etcd

go 1.22
go 1.23.0

toolchain go1.23.7

require (
Expand Down
4 changes: 3 additions & 1 deletion fs/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/Scalingo/go-utils/fs

go 1.20
go 1.21

toolchain go1.23.5

require github.com/spf13/afero v1.12.0

Expand Down