Skip to content

Commit

Permalink
Setup GitHub Actions (#20)
Browse files Browse the repository at this point in the history
* build($ci): setup github actions

Signed-off-by: Rain Wu <[email protected]>
  • Loading branch information
RainrainWu authored Nov 30, 2022
1 parent eeea000 commit 492b4db
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 15 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/dockerized_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Dockerized CI

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:

build:
runs-on: ubuntu-latest
steps:

- name: Checkout branch
uses: actions/checkout@v3

- name: Run golangci-lint
uses: golangci/[email protected]

- name: Build
run: make build
9 changes: 9 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# General
PWD := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))

# Docker
CONTAINER_REGISTRY := docker.io
IMAGE_NAME := r41nwu/telescope

Expand All @@ -15,6 +18,12 @@ endif
lint:
go mod tidy
gofmt -w -s .
docker run \
--rm \
-v ${PWD}:/app \
-w /app \
golangci/golangci-lint:v1.50.1 \
golangci-lint run

.PHONY: build
build:
Expand Down
16 changes: 9 additions & 7 deletions telescope/atlas.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package telescope

import (
"errors"
"fmt"
"io/ioutil"
"os"
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -62,7 +61,7 @@ func NewAtlas(filePath string, strictSemVer bool, ignoredDeps map[string]bool) I
case "poetry.lock":
atlas = buildAtlasPoetryLock(fileBytes, strictSemVer, ignoredDeps)
default:
panic(errors.New(fmt.Sprintf("unknown dep file: %s", filePath)))
panic(fmt.Errorf("unknown dep file: %s", filePath))
}
atlas.sortLexicographically()
atlas.queryVersionsInformation()
Expand All @@ -72,10 +71,10 @@ func NewAtlas(filePath string, strictSemVer bool, ignoredDeps map[string]bool) I

func parseDependenciesFile(filePath string) []byte {

fileBytes, err := ioutil.ReadFile(filePath)
fileBytes, err := os.ReadFile(filePath)
if err != nil {
logrus.Fatal(err.Error())
panic(errors.New(fmt.Sprintf("failed to read dep file %s", filePath)))
panic(fmt.Errorf("failed to read dep file %s", filePath))
}

return fileBytes
Expand Down Expand Up @@ -107,7 +106,10 @@ func buildAtlasGoMod(fileBytes []byte, strictSemVer bool, ignoredDeps map[string
func buildAtlasPoetryLock(fileBytes []byte, strictSemVer bool, ignoredDeps map[string]bool) IReportable {

var poetryLock PoetryLock
toml.Unmarshal(fileBytes, &poetryLock)
err := toml.Unmarshal(fileBytes, &poetryLock)
if err != nil {
panic(err)
}

atlas := Atlas{
name: "",
Expand Down Expand Up @@ -181,7 +183,7 @@ func (a *Atlas) ReportOutdated(desiredScope OutdatedScope, skipUnknown bool) {
if scp > desiredScope {
break
}
color, _ := MapScopeColor[scp]
color := MapScopeColor[scp]
a.reportByScope(scp, color)
}
if !skipUnknown {
Expand Down
14 changes: 8 additions & 6 deletions telescope/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package telescope

import (
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -88,7 +87,7 @@ func (d *Dependency) QueryReleaseVersions(language Language, wg *sync.WaitGroup)
case PYTHON:
d.queryVersionsPython()
default:
panic(errors.New(fmt.Sprintf("unsupported language %s", language.String())))
panic(fmt.Errorf("unsupported language %s", language.String()))
}
}

Expand All @@ -97,14 +96,14 @@ func getVersionsResponse(url string) *http.Response {
request, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
logrus.Fatal(err.Error())
panic(errors.New(fmt.Sprintf("failed to build request with url %s", url)))
panic(fmt.Errorf("failed to build request with url %s", url))
}
request.Header.Set("User-Agent", "GoMajor/1.0")

response, err := http.DefaultClient.Do(request)
if err != nil {
logrus.Fatal(err.Error())
panic(errors.New(fmt.Sprintf("failed to send request to url %s", url)))
panic(fmt.Errorf("failed to send request to url %s", url))
}
return response
}
Expand Down Expand Up @@ -134,7 +133,7 @@ func (d *Dependency) queryVersionsGo() {
modulePath, err := module.EscapePath(d.Name)
if err != nil {
logrus.Fatal(err.Error())
panic(errors.New(fmt.Sprintf("failed to escape module path %s", d.Name)))
panic(fmt.Errorf("failed to escape module path %s", d.Name))
}
response := getVersionsResponse(fmt.Sprintf(proxyUrlGoModule, modulePath))
defer response.Body.Close()
Expand All @@ -156,7 +155,10 @@ func (d *Dependency) queryVersionsPython() {

var pypiJson PypiJson
body, _ := io.ReadAll(response.Body)
json.Unmarshal(body, &pypiJson)
err := json.Unmarshal(body, &pypiJson)
if err != nil {
panic(err)
}

versions := []string{}
for ver := range pypiJson.Releases {
Expand Down
3 changes: 1 addition & 2 deletions telescope/scope.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package telescope

import (
"errors"
"fmt"
"strings"
)
Expand Down Expand Up @@ -36,5 +35,5 @@ func OutdatedScopeStrToEnum(scopeStr string) OutdatedScope {
return OutdatedScope(idx)
}
}
panic(errors.New(fmt.Sprintf("unknown scope %s", scopeStr)))
panic(fmt.Errorf("unknown scope %s", scopeStr))
}

0 comments on commit 492b4db

Please sign in to comment.