-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 737e703
Showing
9 changed files
with
205 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
version: 2.1 | ||
|
||
orbs: | ||
go: circleci/go@1.7 | ||
gor: hubci/goreleaser@1.0 | ||
|
||
workflows: | ||
main: | ||
jobs: | ||
- build: | ||
matrix: | ||
parameters: | ||
go: [ "1.18.5", "1.19.0" ] | ||
release: | ||
jobs: | ||
- build: | ||
matrix: | ||
parameters: | ||
go: [ "1.18.5", "1.19.0" ] | ||
filters: | ||
branches: | ||
ignore: /.*/ | ||
tags: | ||
# Simplified SemVer regex | ||
only: /^v\d+\.\d+\.\d+$/ | ||
- gor/release: | ||
version: "1.10.3" | ||
go-version: "1.18.5" | ||
filters: | ||
branches: | ||
ignore: /.*/ | ||
tags: | ||
# Simplified SemVer regex | ||
only: /^v\d+\.\d+\.\d+$/ | ||
context: main | ||
|
||
jobs: | ||
build: | ||
parameters: | ||
go: | ||
type: string | ||
description: "The Go cimg tag to use." | ||
docker: | ||
- image: cimg/go:<< parameters.go >> | ||
steps: | ||
- checkout | ||
- go/load-cache | ||
- go/mod-download | ||
- run: | ||
name: "Try Building" | ||
command: | | ||
go build ./... | ||
- go/save-cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
main | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
project_name: winpkg | ||
|
||
builds: | ||
- skip: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright ©2022 Ricardo N Feliciano | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# winpkg [![CI Status](https://circleci.com/gh/gopherlibs/winpkg.svg?style=shield)](https://app.circleci.com/pipelines/github/gopherlibs/winpkg) [![Go Report Card](https://goreportcard.com/badge/github.com/gopherlibs/winpkg)](https://goreportcard.com/report/github.com/gopherlibs/winpkg) [![GoDoc](https://godoc.org/github.com/gopherlibs/appindicator?status.svg)](https://godoc.org/github.com/gopherlibs/appindicator) [![Software License](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/gopherlibs/winpkg/trunk/LICENSE) | ||
|
||
`winpkg` is a Go (Golang) module to pull the latest version of a Chocolatey package. | ||
Chocolatey here is a Windows package manager. | ||
|
||
|
||
## Requirements | ||
|
||
This Go module is intended to support the ~~two~~ most recent ~~minor releases~~ release of Go. | ||
Currently this is Go v1.18.x and v1.19.x. | ||
|
||
|
||
## Installation | ||
|
||
`winpkg` is a Go module intended to be used as a library. | ||
So the best way to "install" it is to import into your own code and then run `go mod tidy` to get the source code downloaded. | ||
|
||
```go | ||
import( | ||
"github.com/gopherlibs/winpkg/winpkg" | ||
) | ||
``` | ||
|
||
|
||
## Usage | ||
|
||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gopherlibs/winpkg/winpkg" | ||
) | ||
|
||
func main() { | ||
|
||
// Let's get the latest version of the 'git' package | ||
if ver, err := winpkg.GetVersion( "git" ); err != nil { | ||
fmt.Println(err) | ||
} else { | ||
fmt.Println(ver) | ||
} | ||
} | ||
``` | ||
|
||
|
||
## Development | ||
|
||
This module is written and tested with Go v1.18+ in mind. | ||
`go fmt` is your friend. | ||
Please feel free to open Issues and PRs are you see fit. | ||
Any PR that requires a good amount of work or is a significant change, it would be best to open an Issue to discuss the change first. | ||
|
||
|
||
## License & Credits | ||
|
||
This module was written by Ricardo N Feliciano (FelicianoTech). | ||
This repository is licensed under the MIT license. | ||
This repo's license can be found [here](./LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/gopherlibs/winpkg/winpkg" | ||
) | ||
|
||
func main() { | ||
if ver, err := winpkg.GetVersion(os.Args[1]); err != nil { | ||
fmt.Println(err) | ||
} else { | ||
fmt.Println(ver) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/gopherlibs/winpkg | ||
|
||
go 1.19 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package winpkg | ||
|
||
import ( | ||
"encoding/xml" | ||
"errors" | ||
"io/ioutil" | ||
"net/http" | ||
) | ||
|
||
// The root XML element returned from the Chocolatey Search API. | ||
type Feed struct { | ||
XMLName xml.Name `xml:"feed"` | ||
Entries []Entry `xml:"entry"` | ||
} | ||
|
||
// The Chocolatey Search API can return zero or more `entry` items. | ||
// Each entry represents a package. | ||
type Entry struct { | ||
XMLName xml.Name `xml:"entry"` | ||
Title string `xml:"title"` | ||
Version string `xml:"properties>Version"` | ||
} | ||
|
||
func GetVersion(pkg string) (string, error) { | ||
|
||
resp, err := http.Get("https://community.chocolatey.org/api/v2/Search()?$filter=IsLatestVersion&$skip=0&$top=1&searchTerm=%27" + pkg + "%27&targetFramework=%27%27&includePrerelease=false") | ||
if err != nil { | ||
return "", errors.New("Failed to reach Chocolately API.") | ||
} | ||
defer resp.Body.Close() | ||
|
||
data, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
return "", errors.New("Failed to read in data from API response.") | ||
} | ||
|
||
var searchResult Feed | ||
|
||
err = xml.Unmarshal(data, &searchResult) | ||
if err != nil { | ||
return "", errors.New("Failed to unmarshal API response.") | ||
} | ||
|
||
return searchResult.Entries[0].Version, nil | ||
} |