Skip to content

Commit

Permalink
initial poc
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-pmillz committed Sep 3, 2024
1 parent 9a0c65c commit 874857a
Show file tree
Hide file tree
Showing 13 changed files with 866 additions and 0 deletions.
99 changes: 99 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: CI

# Controls when the action will run. Triggers the workflow on push with tags
on:
push:
tags:
- '*'
pull_request:

permissions:
contents: write
# packages: write
# issues: write

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# The "build" workflow
build:
# The type of runner that the job will run on
strategy:
matrix:
go-version: [1.21, 1.22, 1.23]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4

# Setup Go
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
cache: true

# Run build of the application
- name: Run build
run: |
go env -w GOFLAGS=-mod=mod
go mod tidy
go build -v -o eoldate ./cmd/eoldate/main.go
golangci:
needs: build
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v5
with:
go-version: 1.22
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest
# Optional: golangci-lint command line arguments.
args: --config ./.golangci-lint.yml
# ================
# RELEASE JOB
# runs after a successful build
# only runs on push "*" tag
# ================
release:
needs: [build, golangci]
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

# Setup Go
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.22
cache: true

- name: Set GOPATH
run: |
echo "GOPATH=$(go env GOPATH)/bin" >> $GITHUB_ENV
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
if: startsWith(github.ref, 'refs/tags/v')
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload assets
uses: actions/upload-artifact@v4
with:
name: eoldate
path: dist/*
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.idea
.idea/
.idea/*
*.txt
*.sh
*.yaml
*.json
*.log
*.csv
eoldate
60 changes: 60 additions & 0 deletions .golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
run:
timeout: 5m

linters:
disable-all: true
enable:
- bodyclose
#- copyloopvar
#- deadcode
#- depguard
#- dogsled
- dupl
- errorlint
#- exportloopref
#- exhaustive
#- funlen
#- gas
#- gochecknoinits
- goconst
- gocognit
- gocritic
#- gocyclo
#- gofmt
#- goimports
#- golint
#- gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
#- interfacer
#- lll
#- maligned
#- misspell
#- nakedret
#- noctx
#- nolintlint
# - prealloc
# - revive
#- rowserrcheck
#- scopelint
- staticcheck
#- structcheck
- stylecheck
- typecheck
- unconvert
#- unparam
- unused
#- varcheck
- whitespace
fast: false

linters-settings:
gosimple:
checks: ["all", "-S1028"]
staticcheck:
checks: ["all"]
gosec:
checks: ["all", "-G306"]
42 changes: 42 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
env:
- GO111MODULE=on
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
builds:
- env:
- CGO_ENABLED=0
id: eoldate
binary: eoldate
main: cmd/eoldate/main.go
flags:
- -trimpath
asmflags:
- all=-trimpath={{.Env.GOPATH}}
gcflags:
- all=-trimpath={{.Env.GOPATH}}
ldflags: |
-s -w
goos:
- linux
goarch:
- amd64
- arm64

archives:
- id: tgz
format: tar.gz
format_overrides:
- goos: windows
format: zip

checksum:
name_template: 'checksums.txt'

changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
55 changes: 55 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
BIN="./bin"
SRC=$(shell find . -name "*.go")
CURRENT_TAG=$(shell git describe --tags --abbrev=0)

GOLANGCI := $(shell command -v golangci-lint 2>/dev/null)
RICHGO := $(shell command -v richgo 2>/dev/null)
GOTESTFMT := $(shell command -v gotestfmt 2>/dev/null)

.PHONY: fmt lint build test changelog

default: all

all: fmt lint build test changelog

fmt:
$(info ******************** checking formatting ********************)
@test -z $(shell gofmt -l $(SRC)) || (gofmt -d $(SRC); exit 1)

.PHONY: golangci-lint-check
golangci-lint-check:
ifndef GITHUB_ACTIONS
$(info ******************** checking if golangci-lint is installed ********************)
$(warning "ensuring latest version of golangci-lint installed, running: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest")
go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@latest
endif

.PHONY: lint
lint: golangci-lint-check
$(info ******************** running lint tools ********************)
golangci-lint run -c .golangci-lint.yml -v ./... --timeout 10m

test:
$(info ******************** running tests ********************)
ifeq ($(GITHUB_ACTIONS), true)
ifndef GOTESTFMT
$(warning "could not find gotestfmt in $(PATH), running: go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest")
$(shell go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest)
endif
go test -json -v ./... 2>&1 | tee coverage/gotest.log | gotestfmt
else
ifndef RICHGO
$(warning "could not find richgo in $(PATH), running: go install github.com/kyoh86/richgo@latest")
$(shell go install github.com/kyoh86/richgo@latest)
endif
richgo test -v ./...
endif

changelog:
$(info ******************** running git-cliff updating CHANGELOG.md ********************)
git-cliff -o CHANGELOG.md

build:
go env -w GOFLAGS=-mod=mod
go mod tidy
go build -v -o eoldate -trimpath -ldflags="-s -w" ./cmd/eoldate
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,38 @@
# eoldate

## About

An End of Life Date API SDK written in Go

This is a fairly simple wrapper around the endoflife.date API
[Read the Docs](https://endoflife.date/docs/api)

## Installation

To install, just run the below command or download pre-compiled binary from the [releases page](https://github.com/mr-pmillz/eoldate/releases)

```bash
go install -v github.com/mr-pmillz/eoldate/cmd/eoldate@latest
```

## eoldate as a library

Integrate eoldate with other go programs

```go
package main

import (
"fmt"
"github.com/mr-pmillz/eoldate"
)

func main() {
client := eoldate.NewClient(eoldate.EOLBaseURL)
releaseVersions, err := client.GetProduct("php")
if err != nil {
panic(err)
}
fmt.Println(releaseVersions)
}
```
Loading

0 comments on commit 874857a

Please sign in to comment.