Skip to content

Commit

Permalink
Fix ioutil deprecation (#5)
Browse files Browse the repository at this point in the history
* Update Makefile

Signed-off-by: gitworkflows <118260833+gitworkflows@users.noreply.github.com>

* Update finder.go

Signed-off-by: gitworkflows <118260833+gitworkflows@users.noreply.github.com>

* Update classifier.go

Signed-off-by: gitworkflows <118260833+gitworkflows@users.noreply.github.com>

* Update find.go

Signed-off-by: gitworkflows <118260833+gitworkflows@users.noreply.github.com>

* Update pipeline.yaml (#3)

* Update pipeline.yaml

Signed-off-by: gitworkflows <118260833+gitworkflows@users.noreply.github.com>

* Update pipeline.yaml

Signed-off-by: gitworkflows <118260833+gitworkflows@users.noreply.github.com>

* Update Makefile

Signed-off-by: gitworkflows <118260833+gitworkflows@users.noreply.github.com>

* Update pipeline.yaml

Signed-off-by: gitworkflows <118260833+gitworkflows@users.noreply.github.com>

---------

Signed-off-by: gitworkflows <118260833+gitworkflows@users.noreply.github.com>

* Gitworkflows patch 1 (#4)

* Update pipeline.yaml

Signed-off-by: gitworkflows <118260833+gitworkflows@users.noreply.github.com>

* Update pipeline.yaml

Signed-off-by: gitworkflows <118260833+gitworkflows@users.noreply.github.com>

* Update Makefile

Signed-off-by: gitworkflows <118260833+gitworkflows@users.noreply.github.com>

* Update pipeline.yaml

Signed-off-by: gitworkflows <118260833+gitworkflows@users.noreply.github.com>

---------

Signed-off-by: gitworkflows <118260833+gitworkflows@users.noreply.github.com>

---------

Signed-off-by: gitworkflows <118260833+gitworkflows@users.noreply.github.com>
  • Loading branch information
gitworkflows authored Sep 23, 2024
1 parent 896a939 commit 1dce744
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 61 deletions.
82 changes: 51 additions & 31 deletions .github/workflows/pipeline.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: 'app-pipeline'

on:
push:
pull_request:

jobs:
test:
strategy:
Expand All @@ -10,16 +12,17 @@ jobs:
platform: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout code
uses: actions/checkout@v2

- uses: actions/setup-go@v1
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

- uses: actions/checkout@v1

- name: Cache go dependencies
id: unit-cache-go-dependencies
uses: actions/cache@v1
- name: Cache Go dependencies
id: cache-go-dependencies
uses: actions/cache@v2
with:
path: |
~/go/pkg/mod
Expand All @@ -28,11 +31,11 @@ jobs:
restore-keys: |
${{ runner.os }}-go-${{ matrix.go-version }}-
- name: Install go dependencies
if: steps.unit-cache-go-dependencies.outputs.cache-hit != 'true'
- name: Install Go dependencies
if: steps.cache-go-dependencies.outputs.cache-hit != 'true'
run: make bootstrap

- name: Run Static Analyses
- name: Run Static Analysis
run: make lint

- name: Run Tests
Expand All @@ -41,15 +44,17 @@ jobs:
build-artifacts:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v1
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.18.x'

- uses: actions/checkout@v1

- name: Cache go dependencies
- name: Cache Go dependencies
id: package-cache-go-dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: |
~/go/pkg/mod
Expand All @@ -65,53 +70,68 @@ jobs:
- name: Build snapshot artifacts
run: make ci-build-snapshot-packages

- uses: actions/upload-artifact@master
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: artifacts
path: dist


test-linux-artifacts:
needs: [ build-artifacts ]
needs: build-artifacts
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/download-artifact@master
- name: Checkout code
uses: actions/checkout@v2

- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: artifacts
path: dist
- name: Test linux run

- name: Test Linux run
run: make ci-test-linux-run
- name: Test docker run

- name: Test Docker run
run: make ci-plugs-out-test

test-mac-artifacts:
needs: [ build-artifacts ]
needs: build-artifacts
runs-on: macos-latest
steps:
- uses: actions/checkout@master
- uses: actions/download-artifact@master
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.20' # Specify the Go version you need

- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: artifacts
path: dist
- name: Test darwin run

- name: Test Darwin run
run: make ci-test-mac-run

release:
needs: [ test, build-artifacts, test-linux-artifacts, test-mac-artifacts ]
needs: [test, build-artifacts, test-linux-artifacts, test-mac-artifacts]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout code
uses: actions/checkout@v2

- uses: actions/setup-go@v1
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.18.x'

- uses: actions/checkout@v1

- name: Cache go dependencies
- name: Cache Go dependencies
id: release-cache-go-dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: |
~/go/pkg/mod
Expand Down
35 changes: 11 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ TMP = ./.tmp
RESULTS = $(TMP)/results
ASSETS = assets
DBASSET = $(ASSETS)/licenses.db
# note: go tools requires an absolute path
BIN = $(abspath $(TMP)/bin)
COVER_REPORT = $(RESULTS)/cover.report
COVER_TOTAL = $(RESULTS)/cover.total
LINTCMD = $(BIN)/golangci-lint run --tests=false --config .golangci.yaml

BOLD := $(shell tput -T linux bold)
PURPLE := $(shell tput -T linux setaf 5)
GREEN := $(shell tput -T linux setaf 2)
Expand All @@ -15,7 +15,6 @@ RED := $(shell tput -T linux setaf 1)
RESET := $(shell tput -T linux sgr0)
TITLE := $(BOLD)$(PURPLE)
SUCCESS := $(BOLD)$(GREEN)
# the quality gate lower threshold for unit test total % coverage (by function statements)
COVERAGE_THRESHOLD := 34

RELEASE_CMD=$(BIN)/goreleaser --rm-dist
Expand Down Expand Up @@ -44,25 +43,18 @@ help:

bootstrap: ## Download and install all project dependencies (+ prep tooling in the ./.tmp dir)
$(call title,Downloading dependencies)
# prep temp dirs
mkdir -p $(TMP) || exit 1
mkdir -p $(RESULTS) || exit 1
mkdir -p $(BIN) || exit 1
# download install project dependencies + tooling
@mkdir -p $(TMP) $(RESULTS) $(BIN) || exit 1
go mod download || exit 1
cat tools.go | grep _ | awk -F'"' '{print $$2}' | xargs -tI % env GOBIN=$(BIN) go install % || exit 1
# install golangci-lint
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(BIN) v1.47.2 || exit 1
# install pkger
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(BIN) v1.50.1 || exit 1
cd $(TMP) && curl -sLO https://github.com/markbates/pkger/releases/download/v0.17.0/pkger_0.17.0_$(shell uname)_x86_64.tar.gz && \
tar -xzvf pkger_0.17.0_$(shell uname)_x86_64.tar.gz pkger && \
mv pkger $(BIN) || exit 1
# install goreleaser
GOBIN=$(BIN) go install github.com/goreleaser/goreleaser@v1.3.1 || exit 1

$(DBASSET):
$(call title,Building assets)
mkdir -p $(ASSETS) || exit 1
@mkdir -p $(ASSETS) || exit 1
$(BIN)/license_serializer -output $(ASSETS) || exit 1

pkged.go: $(DBASSET)
Expand All @@ -89,22 +81,19 @@ lint-fix: ## Auto-format all source code + run golangci-lint fixers
unit: ## Run unit tests (with coverage)
$(call title,Running unit tests)
go test -coverprofile $(COVER_REPORT) ./...
@go tool cover -func $(COVER_REPORT) | grep total | awk '{print substr($$3, 1, length($$3)-1)}' > $(COVER_TOTAL)
@go tool cover -func $(COVER_REPORT) | grep total | awk '{print substr($$3, 1, length($$3)-1)}' > $(COVER_TOTAL)
@echo "Coverage: $$(cat $(COVER_TOTAL))"
@if [ $$(echo "$$(cat $(COVER_TOTAL)) >= $(COVERAGE_THRESHOLD)" | bc -l) -ne 1 ]; then echo "$(RED)$(BOLD)Failed coverage quality gate (> $(COVERAGE_THRESHOLD)%)$(RESET)" && false; fi

# The following targets are all CI related
@if [ $$(echo "$$(cat $(COVER_TOTAL)) >= $(COVERAGE_THRESHOLD)" | bc -l) -ne 1 ]; then \
echo "$(RED)$(BOLD)Failed coverage quality gate (> $(COVERAGE_THRESHOLD)%)$(RESET)" && false; \
fi

ci-build-snapshot-packages: pkged.go
$(RELEASE_CMD) \
--snapshot \
--skip-publish
$(RELEASE_CMD) --snapshot --skip-publish

# note: since google's licenseclassifier requires the go tooling ('go list' from x/tools/go/packages) we need to use a golang image
ci-plugs-out-test:
docker run \
-v //var/run/docker.sock://var/run/docker.sock \
-v /${PWD}://src \
-v ${PWD}://src \
-w //src \
golang:latest \
/bin/bash -x -c "\
Expand Down Expand Up @@ -137,6 +126,4 @@ ci-release: pkged.go
$(BIN)/goreleaser --rm-dist

clean: ## Clean build artifacts
rm -rf dist
rm -rf .tmp
rm -rf $(RESULTS)
rm -rf dist .tmp $(RESULTS)
4 changes: 2 additions & 2 deletions golicenses/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"flag"
"fmt"
"io/ioutil"
"io"
"strings"

"github.com/google/licenseclassifier"
Expand Down Expand Up @@ -35,7 +35,7 @@ func licenseDBArchiveFetcher() ([]byte, error) {
}

defer f.Close()
return ioutil.ReadAll(f)
return io.ReadAll(f)
}

func (r LicenseFinder) Find() (<-chan LicenseResult, error) {
Expand Down
4 changes: 2 additions & 2 deletions golicenses/licenses/classifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package licenses

import (
"fmt"
"io/ioutil"
"os"

"github.com/google/licenseclassifier"
)
Expand Down Expand Up @@ -88,7 +88,7 @@ func (c *googleClassifier) Identify(licensePath string) (string, Type, error) {
if licensePath == "" {
return "", Unknown, nil
}
content, err := ioutil.ReadFile(licensePath)
content, err := os.ReadFile(licensePath)
if err != nil {
return "", "", err
}
Expand Down
4 changes: 2 additions & 2 deletions golicenses/licenses/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package licenses
import (
"fmt"
"go/build"
"io/ioutil"
"os"
"path/filepath"
"regexp"
)
Expand Down Expand Up @@ -57,7 +57,7 @@ func findUpwards(dir string, r *regexp.Regexp, stopAt []*regexp.Regexp, predicat
start := dir
// Stop once dir matches a stopAt regexp or dir is the filesystem root
for !matchAny(stopAt, dir) {
dirContents, err := ioutil.ReadDir(dir)
dirContents, err := os.ReadDir(dir)
if err != nil {
return "", err
}
Expand Down

0 comments on commit 1dce744

Please sign in to comment.