Skip to content

Commit

Permalink
feat: init
Browse files Browse the repository at this point in the history
  • Loading branch information
morlay committed Dec 26, 2023
0 parents commit 0a4f306
Show file tree
Hide file tree
Showing 91 changed files with 7,213 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"

- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: ci

on:
push:
branches:
- "*"
tags:
- 'v*'

jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version: '^1.21'

- run: go mod download -x
- run: make release
env:
GH_PASSWORD: ${{ secrets.GITHUB_TOKEN }}

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea/
.build/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 octohelm

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.
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
PIPER = go run ./cmd/piper

DEBUG = 0
ifeq ($(DEBUG),1)
PIPER := $(PIPER) --log-level=debug
endif

build:
$(PIPER) do go build

archive:
$(PIPER) do go archive

release:
$(PIPER) do release

gen:
go run ./internal/cmd/tool gen ./cmd/piper

install:
go install ./cmd/piper
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Piper

Similar as [`cue/tool`](https://pkg.go.dev/cuelang.org/go/pkg/tool), but not just on current host.

## Install

```shell
curl -sSLf https://raw.githubusercontent.com/octohelm/piper/main/install.sh | sudo sh
```
16 changes: 16 additions & 0 deletions cmd/piper/do.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main

import (
"github.com/innoai-tech/infra/pkg/cli"
"github.com/octohelm/piper/pkg/engine"
)

func init() {
cli.AddTo(App, &Do{})
}

type Do struct {
cli.C
engine.Logger
engine.Pipeline
}
18 changes: 18 additions & 0 deletions cmd/piper/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import (
"context"
"os"

"github.com/innoai-tech/infra/pkg/cli"

"github.com/octohelm/piper/internal/version"
)

var App = cli.NewApp("piper", version.Version())

func main() {
if err := cli.Execute(context.Background(), App, os.Args[1:]); err != nil {
os.Exit(1)
}
}
36 changes: 36 additions & 0 deletions cmd/piper/zz_generated.runtimedoc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Package main GENERATED BY gengo:runtimedoc
DON'T EDIT THIS FILE
*/
package main

// nolint:deadcode,unused
func runtimeDoc(v any, names ...string) ([]string, bool) {
if c, ok := v.(interface {
RuntimeDoc(names ...string) ([]string, bool)
}); ok {
return c.RuntimeDoc(names...)
}
return nil, false
}

func (v Do) RuntimeDoc(names ...string) ([]string, bool) {
if len(names) > 0 {
switch names[0] {
case "Logger":
return []string{}, true
case "Pipeline":
return []string{}, true

}
if doc, ok := runtimeDoc(v.Logger, names...); ok {
return doc, ok
}
if doc, ok := runtimeDoc(v.Pipeline, names...); ok {
return doc, ok
}

return nil, false
}
return []string{}, true
}
3 changes: 3 additions & 0 deletions cue.mod/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
gen/
pkg/
module.sum
5 changes: 5 additions & 0 deletions cue.mod/module.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module: "github.com/octohelm/piper"

require: {
"piper.octohelm.tech": "v0.0.0"
}
148 changes: 148 additions & 0 deletions cuepkg/github/release.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package github

import (
"path"
"strings"
"strconv"
"encoding/json"

"piper.octohelm.tech/http"
"piper.octohelm.tech/file"
"piper.octohelm.tech/client"
"piper.octohelm.tech/flow"
)

#GithubAPI: {
core: "https://api.github.com"
uploads: "https://uploads.github.com"
}

#Release: {
token: client.#Secret

owner: string
repo: string

name: string | *"latest"
notes: string | *""
prerelease: bool | *true
draft: bool | *false

assets: [...file.#File]

_client: #Client & {"token": token}

_get_or_create_release: {
_ret: flow.#Some & {
steps: [
_client.#Do & {
method: "GET"
url: "\(#GithubAPI.core)/repos/\(owner)/\(repo)/releases/tags/\(name)"
},
_client.#Do & {
"method": "POST"
"url": "\(#GithubAPI.core)/repos/\(owner)/\(repo)/releases"
"header": {
"Content-Type": "application/json"
}
"body": json.Marshal({
"tag_name": name
"name": name
"body": notes
"prerelease": prerelease
"draft": draft
})
},
]
}

id: _ret.result.data.id
}

_list_assets: {
_req: _client.#Do & {
method: "GET"
url: "\(#GithubAPI.core)/repos/\(owner)/\(repo)/releases/\(_get_or_create_release.id)/assets"
}

assets: {
for asset in _req.result.data {
"\(asset.name)": strconv.FormatFloat(asset.id, strings.ByteAt("f", 0), 0, 64)
}
}
}

_upload_assets: flow.#Every & {
steps: [
for f in assets {
let assetName = path.Base(f.filename)

flow.#Every & {
steps: [
// if asset name exists, delete first
if _list_assets.assets[assetName] != _|_ {
_client.#Do & {
"method": "DELETE"
"url": "\(#GithubAPI.core)/repos/\(owner)/\(repo)/releases/assets/\(_list_assets.assets[assetName])"
}
},
// then upload
_client.#Do & {
"method": "POST"
"url": "\(#GithubAPI.uploads)/repos/\(owner)/\(repo)/releases/\(_get_or_create_release.id)/assets"
"header": {
"Content-Type": "application/octet-stream"
}
"query": {
"name": "\(assetName)"
}
"body": f
},
]
}
},
]
}
result: _upload_assets.result
}

#Client: {
token: client.#Secret

_token: client.#ReadSecret & {
secret: token
}

#Do: {
method: string
url: string
body?: file.#StringOrFile
header: [Name=string]: string | [...string]
query: [Name=string]: string | [...string]

_default_header: {
"Accept": "application/vnd.github+json"
"Authorization": "Bearer \(_token.value)"
"X-GitHub-Api-Version": "2022-11-28"
}

_req: http.#Do & {
"method": method
"url": url
"header": {
for k, vv in header {
"\(k)": vv
}
for k, vv in _default_header if header[k] == _|_ {
"\(k)": vv
}
}
"query": query
if body != _|_ {
"body": body
}
}

result: _req.result
}
}
Loading

0 comments on commit 0a4f306

Please sign in to comment.