From f1db1d4a69351a4552a9374aab8118bb2e24dd8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Fr=C3=B6lich?= Date: Sat, 13 Jul 2024 13:51:57 +0200 Subject: [PATCH 1/4] ci: add docker builds --- .github/workflows/release.yaml | 24 +++++++++++++++++++++++- Dockerfile | 11 +++++++++++ Makefile | 6 ++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 Dockerfile diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 570d6c4..148bb9b 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -30,4 +30,26 @@ jobs: version: '~> v2' args: release --clean env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + docker: + runs-on: ubuntu-latest + steps: + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Build and push + uses: docker/build-push-action@v6 + with: + push: true + tags: tobiasfrolich/starscraper:${{ github.ref_name }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4154369 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM golang:alpine + +RUN apk add make + +WORKDIR /app + +COPY . /app + +RUN make build-docker + +ENTRYPOINT ["./starscraper"] \ No newline at end of file diff --git a/Makefile b/Makefile index 5500d41..eb75a9a 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,12 @@ build: @echo "GOPATH=${GOPATH}" go build -ldflags "-X github.com/tobifroe/starscraper/version.GitCommit=${GIT_COMMIT}${GIT_DIRTY} -X github.com/tobifroe/starscraper/version.BuildDate=${BUILD_DATE}" -o bin/${BIN_NAME} +build-docker: + @echo "building ${BIN_NAME} ${VERSION}" + @echo "GOPATH=${GOPATH}" + go build -ldflags "-X github.com/tobifroe/starscraper/version.GitCommit=${GIT_COMMIT}${GIT_DIRTY} -X github.com/tobifroe/starscraper/version.BuildDate=${BUILD_DATE}" -o ${BIN_NAME} + + get-deps: go mod download From 2e089a3ceb2f5d338b57a5d4265226d01d196fb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Fr=C3=B6lich?= Date: Sat, 13 Jul 2024 13:53:44 +0200 Subject: [PATCH 2/4] ci: add lint step --- .github/workflows/test.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index ca4b454..fd87e48 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -14,7 +14,10 @@ jobs: uses: actions/setup-go@v5 with: go-version: '1.22' - + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: v6.0.1 - name: Test run: make test From 69c07a22fb149ff09f3cd6009879222d55790f19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Fr=C3=B6lich?= Date: Sat, 13 Jul 2024 13:55:35 +0200 Subject: [PATCH 3/4] fix: golangci-lint version --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index fd87e48..d843dff 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -17,7 +17,7 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v6 with: - version: v6.0.1 + version: v1.59 - name: Test run: make test From 77a4049e6b7a2183fcaef401663b2e03a6d6d333 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Fr=C3=B6lich?= Date: Sat, 13 Jul 2024 14:00:03 +0200 Subject: [PATCH 4/4] fix: make linter happy --- cmd/scrape.go | 11 ++++++++--- util/util.go | 13 +++++++++---- util/util_test.go | 5 ++++- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/cmd/scrape.go b/cmd/scrape.go index bd6f539..22aa63d 100644 --- a/cmd/scrape.go +++ b/cmd/scrape.go @@ -34,7 +34,12 @@ func init() { scrapeCmd.Flags().String("output", "output.csv", "Output file") scrapeCmd.Flags().BoolP("verbose", "v", false, "Verbose output") - scrapeCmd.MarkFlagRequired("repo") - scrapeCmd.MarkFlagRequired("owner") - + err := scrapeCmd.MarkFlagRequired("repo") + if err != nil { + panic(err) + } + err = scrapeCmd.MarkFlagRequired("owner") + if err != nil { + panic(err) + } } diff --git a/util/util.go b/util/util.go index 9dfb4ff..c73600e 100644 --- a/util/util.go +++ b/util/util.go @@ -27,18 +27,23 @@ func WriteToCSV(users []types.User, output string) { defer writer.Flush() headers := []string{"email", "name", "login"} - writer.Write(headers) + err = writer.Write(headers) + if err != nil { + panic(err) + } for _, row := range users { s := []string{ row.Email, row.Name, row.Login, } - writer.Write(s) + err = writer.Write(s) + if err != nil { + panic(err) + } } } -// TODO implement/document client secret parsing, Write to Docs mode func WriteToGoogleDocs(sheetFlag *string, allUsers []types.User) { - return + // TODO implement/document client secret parsing, Write to Docs mode } diff --git a/util/util_test.go b/util/util_test.go index 758c25d..ae152fa 100644 --- a/util/util_test.go +++ b/util/util_test.go @@ -46,7 +46,10 @@ func TestWriteToCSV(t *testing.T) { } // Validate CSV format - file.Seek(0, 0) + _, err = file.Seek(0, 0) + if err != nil { + panic(err) + } var buf bytes.Buffer _, _ = buf.ReadFrom(file) csvContent := buf.String()