From d190b9d9b09c453c9843be3fddd034584bc1b544 Mon Sep 17 00:00:00 2001 From: Tanner Miller Date: Tue, 12 Sep 2023 11:03:28 -0400 Subject: [PATCH 1/9] first try --- .github/CODEOWNERS | 1 + .github/workflows/tests.yaml | 35 +++++++++++++++++++++++++++++++++++ .travis.yml | 17 ----------------- Dockerfile | 16 ---------------- sort/sort.go | 17 +++++++++++++++-- 5 files changed, 51 insertions(+), 35 deletions(-) create mode 100644 .github/CODEOWNERS create mode 100644 .github/workflows/tests.yaml delete mode 100644 .travis.yml delete mode 100644 Dockerfile diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..e9d2163 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +@Workiva/skreams diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 0000000..47dae03 --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,35 @@ +name: "Tests" + +on: + pull_request: + push: + branches: + - 'master' + tags: + - '*' + +env: + GOLANG_VERSION: "1.16" + GOPATH: /runner/_work/go-datastructures/go-datastructures/go + +jobs: + Tests: + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@v3.3.0 + with: + path: go/src/github.com/Workiva/go-datastructures + + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: ${{ env.GOLANG_VERSION }} + cache-dependency-path: /runner/_work/go-datastructures/go-datastructures/go/src/github.com/Workiva/go-datastructures/go.sum + + - name: Run Tests + timeout-minutes: 10 + run: | + cd $GOPATH/src/github.com/Workiva/go-datastructures + go test ./... + diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index c4cb4f4..0000000 --- a/.travis.yml +++ /dev/null @@ -1,17 +0,0 @@ -language: go - -go: - - tip - -before_install: go get golang.org/x/tools/cmd/cover - -install: -- go mod vendor - -script: go test -race -v -cover ./... - -env: -- GOMAXPROCS=8 GORACE="halt_on_error=1" - -notifications: - email: false diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 2e315f1..0000000 --- a/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -FROM golang:1.16-alpine3.13 AS build-go - -ARG GIT_SSH_KEY -ARG KNOWN_HOSTS_CONTENT -WORKDIR /go/src/github.com/Workiva/go-datastructures/ -ADD . /go/src/github.com/Workiva/go-datastructures/ - -ARG GOPATH=/go/ -ENV PATH $GOPATH/bin:$PATH -RUN echo "Starting the script section" && \ - go mod vendor && \ - echo "script section completed" - -ARG BUILD_ARTIFACTS_DEPENDENCIES=/go/src/github.com/Workiva/go-datastructures/go.mod - -FROM scratch diff --git a/sort/sort.go b/sort/sort.go index 3b949d5..0d7ce59 100644 --- a/sort/sort.go +++ b/sort/sort.go @@ -27,8 +27,11 @@ func MultithreadedSortComparators(comparators Comparators) Comparators { var wg sync.WaitGroup numCPU := int64(runtime.NumCPU()) - if numCPU%2 == 1 { // single core machine - numCPU++ + if numCPU == 1 { // single core machine + numCPU = 2 + } else { + // otherwise this algo only works with a power of two + numCPU = int64(prevPowerOfTwo(uint64(numCPU))) } chunks := chunk(toBeSorted, numCPU) @@ -70,3 +73,13 @@ func chunk(comparators Comparators, numParts int64) []Comparators { } return parts } + +func prevPowerOfTwo(x uint64) uint64 { + x = x | (x >> 1) + x = x | (x >> 2) + x = x | (x >> 4) + x = x | (x >> 8) + x = x | (x >> 16) + x = x | (x >> 32) + return x - (x >> 1) +} From fb276da77993e716ea059248e5140891238306f7 Mon Sep 17 00:00:00 2001 From: Tanner Miller Date: Tue, 12 Sep 2023 11:06:30 -0400 Subject: [PATCH 2/9] basic perms --- .github/workflows/tests.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 47dae03..b14f42a 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -8,6 +8,9 @@ on: tags: - '*' +permissions: + contents: read + env: GOLANG_VERSION: "1.16" GOPATH: /runner/_work/go-datastructures/go-datastructures/go From 04ff6f1628a52e6c01518f4995f841db25c04ebc Mon Sep 17 00:00:00 2001 From: Tanner Miller Date: Tue, 12 Sep 2023 11:08:33 -0400 Subject: [PATCH 3/9] next perms --- .github/workflows/tests.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index b14f42a..7dafcd6 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -9,7 +9,8 @@ on: - '*' permissions: - contents: read + contents: read + id-token: write env: GOLANG_VERSION: "1.16" From d975331f426eff517fed7bf9a1eb78a0f350c600 Mon Sep 17 00:00:00 2001 From: Tanner Miller Date: Tue, 12 Sep 2023 11:09:53 -0400 Subject: [PATCH 4/9] what next --- .github/workflows/tests.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 7dafcd6..d394618 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -9,6 +9,7 @@ on: - '*' permissions: + pull-requests: write contents: read id-token: write From e05837fab70a6dd3c6360feb952d4168196f51e2 Mon Sep 17 00:00:00 2001 From: Tanner Miller Date: Tue, 12 Sep 2023 11:12:01 -0400 Subject: [PATCH 5/9] dont cache go --- .github/workflows/tests.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index d394618..e70d50e 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -30,7 +30,6 @@ jobs: uses: actions/setup-go@v4 with: go-version: ${{ env.GOLANG_VERSION }} - cache-dependency-path: /runner/_work/go-datastructures/go-datastructures/go/src/github.com/Workiva/go-datastructures/go.sum - name: Run Tests timeout-minutes: 10 From c241ea24b3deac46c17f4654685f615a1c6c25f9 Mon Sep 17 00:00:00 2001 From: Tanner Miller Date: Tue, 12 Sep 2023 11:16:40 -0400 Subject: [PATCH 6/9] only run go version --- .github/workflows/tests.yaml | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index e70d50e..90ea25d 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -21,19 +21,12 @@ jobs: Tests: runs-on: ubuntu-latest steps: - - name: Checkout Repo - uses: actions/checkout@v3.3.0 + - uses: actions/checkout@v3.3.0 with: path: go/src/github.com/Workiva/go-datastructures - - name: Setup Go - uses: actions/setup-go@v4 + - uses: actions/setup-go@v4 with: go-version: ${{ env.GOLANG_VERSION }} - - name: Run Tests - timeout-minutes: 10 - run: | - cd $GOPATH/src/github.com/Workiva/go-datastructures - go test ./... - + - run: go version From 88b1345c9e78250599289c5e1f4ac789d6823af8 Mon Sep 17 00:00:00 2001 From: Tanner Miller Date: Tue, 12 Sep 2023 11:18:33 -0400 Subject: [PATCH 7/9] Ignore GOPATH --- .github/workflows/tests.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 90ea25d..54a22eb 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -15,7 +15,6 @@ permissions: env: GOLANG_VERSION: "1.16" - GOPATH: /runner/_work/go-datastructures/go-datastructures/go jobs: Tests: From d29185a9fbb313ba88b028596d0d7230249a4bef Mon Sep 17 00:00:00 2001 From: Tanner Miller Date: Tue, 12 Sep 2023 11:22:21 -0400 Subject: [PATCH 8/9] try tests again --- .github/workflows/tests.yaml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 54a22eb..64cffc0 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -20,12 +20,18 @@ jobs: Tests: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3.3.0 + - name: Checkout Repo + uses: actions/checkout@v3.3.0 with: path: go/src/github.com/Workiva/go-datastructures - - uses: actions/setup-go@v4 + - name: Setup Go + uses: actions/setup-go@v4 with: go-version: ${{ env.GOLANG_VERSION }} - - run: go version + - name: Run Tests + timeout-minutes: 10 + run: | + cd go/src/github.com/Workiva/go-datastructures + go test ./... From 25e2959e6c2a3d746aa87cd0424266685d603e82 Mon Sep 17 00:00:00 2001 From: Tanner Miller Date: Tue, 12 Sep 2023 11:32:06 -0400 Subject: [PATCH 9/9] re-add Dockerfile --- Dockerfile | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2e315f1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM golang:1.16-alpine3.13 AS build-go + +ARG GIT_SSH_KEY +ARG KNOWN_HOSTS_CONTENT +WORKDIR /go/src/github.com/Workiva/go-datastructures/ +ADD . /go/src/github.com/Workiva/go-datastructures/ + +ARG GOPATH=/go/ +ENV PATH $GOPATH/bin:$PATH +RUN echo "Starting the script section" && \ + go mod vendor && \ + echo "script section completed" + +ARG BUILD_ARTIFACTS_DEPENDENCIES=/go/src/github.com/Workiva/go-datastructures/go.mod + +FROM scratch