Skip to content
This repository was archived by the owner on Jul 19, 2022. It is now read-only.

Commit 383424e

Browse files
authored
(wip) setup github action
1 parent 0a3eee3 commit 383424e

File tree

8 files changed

+285
-26
lines changed

8 files changed

+285
-26
lines changed

.gitignore

+167-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,171 @@
1+
# Created by https://www.toptal.com/developers/gitignore/api/go,node
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=go,node
13

2-
# dist
3-
bin
4-
picasso
4+
### Go ###
5+
# If you prefer the allow list template instead of the deny list, see community template:
6+
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
7+
#
8+
# Binaries for programs and plugins
9+
*.exe
10+
*.exe~
11+
*.dll
12+
*.so
13+
*.dylib
514

6-
debug
15+
# Test binary, built with `go test -c`
16+
*.test
717

8-
# test
18+
# Output of the go coverage tool, specifically when used with LiteIDE
919
*.out
10-
coverage.html
20+
21+
# Dependency directories (remove the comment below to include it)
22+
# vendor/
23+
24+
# Go workspace file
25+
go.work
26+
27+
### Go Patch ###
28+
/vendor/
29+
/Godeps/
30+
31+
### Node ###
32+
# Logs
33+
logs
34+
*.log
35+
npm-debug.log*
36+
yarn-debug.log*
37+
yarn-error.log*
38+
lerna-debug.log*
39+
.pnpm-debug.log*
40+
41+
# Diagnostic reports (https://nodejs.org/api/report.html)
42+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
43+
44+
# Runtime data
45+
pids
46+
*.pid
47+
*.seed
48+
*.pid.lock
49+
50+
# Directory for instrumented libs generated by jscoverage/JSCover
51+
lib-cov
52+
53+
# Coverage directory used by tools like istanbul
54+
coverage
55+
*.lcov
56+
57+
# nyc test coverage
58+
.nyc_output
59+
60+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
61+
.grunt
62+
63+
# Bower dependency directory (https://bower.io/)
64+
bower_components
65+
66+
# node-waf configuration
67+
.lock-wscript
68+
69+
# Compiled binary addons (https://nodejs.org/api/addons.html)
70+
build/Release
71+
72+
# Dependency directories
73+
node_modules/
74+
jspm_packages/
75+
76+
# Snowpack dependency directory (https://snowpack.dev/)
77+
web_modules/
78+
79+
# TypeScript cache
80+
*.tsbuildinfo
81+
82+
# Optional npm cache directory
83+
.npm
84+
85+
# Optional eslint cache
86+
.eslintcache
87+
88+
# Optional stylelint cache
89+
.stylelintcache
90+
91+
# Microbundle cache
92+
.rpt2_cache/
93+
.rts2_cache_cjs/
94+
.rts2_cache_es/
95+
.rts2_cache_umd/
96+
97+
# Optional REPL history
98+
.node_repl_history
99+
100+
# Output of 'npm pack'
101+
*.tgz
102+
103+
# Yarn Integrity file
104+
.yarn-integrity
105+
106+
# dotenv environment variable files
107+
.env
108+
.env.development.local
109+
.env.test.local
110+
.env.production.local
111+
.env.local
112+
113+
# parcel-bundler cache (https://parceljs.org/)
114+
.cache
115+
.parcel-cache
116+
117+
# Next.js build output
118+
.next
119+
out
120+
121+
# Nuxt.js build / generate output
122+
.nuxt
123+
dist
124+
125+
# Gatsby files
126+
.cache/
127+
# Comment in the public line in if your project uses Gatsby and not Next.js
128+
# https://nextjs.org/blog/next-9-1#public-directory-support
129+
# public
130+
131+
# vuepress build output
132+
.vuepress/dist
133+
134+
# vuepress v2.x temp and cache directory
135+
.temp
136+
137+
# Docusaurus cache and generated files
138+
.docusaurus
139+
140+
# Serverless directories
141+
.serverless/
142+
143+
# FuseBox cache
144+
.fusebox/
145+
146+
# DynamoDB Local files
147+
.dynamodb/
148+
149+
# TernJS port file
150+
.tern-port
151+
152+
# Stores VSCode versions used for testing VSCode extensions
153+
.vscode-test
154+
155+
# yarn v2
156+
.yarn/cache
157+
.yarn/unplugged
158+
.yarn/build-state.yml
159+
.yarn/install-state.gz
160+
.pnp.*
161+
162+
### Node Patch ###
163+
# Serverless Webpack directories
164+
.webpack/
165+
166+
# Optional stylelint cache
167+
168+
# SvelteKit build / generate output
169+
.svelte-kit
170+
171+
# End of https://www.toptal.com/developers/gitignore/api/go,node

.goreleaser.yml

+47-20
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,49 @@
1-
build:
2-
binary: picasso
3-
main: main.go
4-
goos:
5-
- windows
6-
- darwin
7-
- linux
8-
goarch:
9-
- 386
10-
- amd64
11-
- arm
12-
- arm64
13-
ignore:
14-
- goos: darwin
15-
goarch: 386
16-
env:
17-
- CGO_ENABLED=0
18-
ldflags:
19-
- -s -w
1+
builds:
2+
- id: action
3+
binary: action-{{.Os}}-{{ .Arch }}
4+
main: ./cmd/action/main.go
5+
goos:
6+
- linux
7+
goarch:
8+
- amd64
9+
env:
10+
- CGO_ENABLED=0
11+
ldflags:
12+
- -s -w
13+
no_unique_dist_dir: true
14+
15+
- id: picasso
16+
binary: picasso-{{.Os}}-{{ .Arch }}
17+
main: main.go
18+
goos:
19+
- windows
20+
- darwin
21+
- linux
22+
goarch:
23+
- 386
24+
- amd64
25+
- arm
26+
- arm64
27+
ignore:
28+
- goos: darwin
29+
goarch: 386
30+
env:
31+
- CGO_ENABLED=0
32+
ldflags:
33+
- -s -w
34+
no_unique_dist_dir: true
35+
36+
archives:
37+
-
38+
id: action
39+
builds:
40+
- action
41+
name_template: "action_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
42+
-
43+
id: picasso
44+
builds:
45+
- picasso
46+
name_template: "picasso_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
2047

2148
gomod:
2249
proxy: true
@@ -28,4 +55,4 @@ snapshot:
2855
name_template: "{{.Tag}}"
2956

3057
checksum:
31-
name_template: "task_checksums.txt"
58+
name_template: "picasso_checksums.txt"

action.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
runs:
2+
using: 'node16'
3+
main: 'index.js'

cmd/action/main.go

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package main
2+
3+
import (
4+
a "github.com/andersnormal/picasso/pkg/action"
5+
6+
githubactions "github.com/sethvargo/go-githubactions"
7+
)
8+
9+
var action *githubactions.Action
10+
11+
func run() error {
12+
action = githubactions.New()
13+
14+
_, err := a.NewFromInputs(action)
15+
if err != nil {
16+
return err
17+
}
18+
19+
return nil
20+
}
21+
22+
func main() {
23+
err := run()
24+
if err != nil {
25+
action.Fatalf("%v", err)
26+
}
27+
}

go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
github.com/hashicorp/go-hclog v0.14.1
1111
github.com/hashicorp/go-plugin v1.4.4
1212
github.com/manifoldco/promptui v0.9.0
13+
github.com/sethvargo/go-githubactions v1.0.0
1314
github.com/spf13/pflag v1.0.5
1415
go.uber.org/zap v1.21.0
1516
golang.org/x/exp v0.0.0-20220613132600-b0d781184e0d
@@ -42,6 +43,7 @@ require (
4243
github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77 // indirect
4344
github.com/oklog/run v1.0.0 // indirect
4445
github.com/sergi/go-diff v1.1.0 // indirect
46+
github.com/sethvargo/go-envconfig v0.6.0 // indirect
4547
github.com/xanzy/ssh-agent v0.3.0 // indirect
4648
go.uber.org/atomic v1.9.0 // indirect
4749
go.uber.org/multierr v1.8.0 // indirect

go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUA
155155
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
156156
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
157157
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
158+
github.com/sethvargo/go-envconfig v0.6.0 h1:GxxdoeiNpWgGiVEphNFNObgMYRN/ZvI2dN7rBwadyss=
159+
github.com/sethvargo/go-envconfig v0.6.0/go.mod h1:00S1FAhRUuTNJazWBWcJGvEHOM+NO6DhoRMAOX7FY5o=
160+
github.com/sethvargo/go-githubactions v1.0.0 h1:5mYGPNxIwIXaS8MLj4uYGWM8QM8giUVqA4FuSYOZjXE=
161+
github.com/sethvargo/go-githubactions v1.0.0/go.mod h1:UaidDD1ENTLXzTtj/4MnYjY40/5WLijgn2O8KBsdv7o=
158162
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
159163
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
160164
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=

index.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function chooseBinary() {
2+
if (platform === 'linux' && arch === 'x64') {
3+
return `main-linux-amd64-${VERSION}`
4+
}
5+
}
6+
7+
const binary = chooseBinary()
8+
const mainScript = `${__dirname}/${binary}`
9+
const spawnSyncReturns = childProcess.spawnSync(mainScript, { stdio: 'inherit' })

pkg/action/config.go

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package action
2+
3+
import (
4+
"time"
5+
6+
"github.com/sethvargo/go-githubactions"
7+
)
8+
9+
type Config struct {
10+
Role string
11+
LeaseDuration time.Duration
12+
}
13+
14+
func NewFromInputs(action *githubactions.Action) (*Config, error) {
15+
lease := action.GetInput("lease-duration")
16+
d, err := time.ParseDuration(lease)
17+
if err != nil {
18+
return nil, err
19+
}
20+
21+
c := Config{
22+
Role: action.GetInput("role"),
23+
LeaseDuration: d,
24+
}
25+
return &c, nil
26+
}

0 commit comments

Comments
 (0)