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

Commit a1ce362

Browse files
authored
Add example go project and Action
1 parent b4e5a1b commit a1ce362

File tree

7 files changed

+81
-5
lines changed

7 files changed

+81
-5
lines changed

.github/workflows/go-action.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Go Action detection of dependencies
2+
on:
3+
push
4+
# on:
5+
# push:
6+
# branches:
7+
# - main
8+
jobs:
9+
go-action-detection:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: 'Checkout Repository'
13+
uses: actions/checkout@v3
14+
- uses: actions/setup-go@v3
15+
with:
16+
go-version: ">=1.18.0"
17+
- name: Run snapshot action
18+
uses: dsp-testing/go-snapshot-action@main
19+
with:
20+
go-mod-path: go-example/go.mod
21+
go-build-target: go-example/cmd/octocat.go

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ An Action that creates a dependency submission using `go mod graph`.
55
Optional inputs for the Action include: `detector-name`, `detector-url`, `detector-version`, and `metadata` - a JSON of max eight keys to provide with the snapshot.
66

77
### Example
8-
```
8+
```yaml
99
name: Go Action detection of dependencies
1010
on:
1111
push:
@@ -27,6 +27,16 @@ jobs:
2727
- name: Run snapshot action
2828
uses: @dsp-testing/go-snapshot-action
2929
with:
30+
# Required: Define the repo path to the go.mod file used by the
31+
# build target
32+
go-mod-path: go-example/go.mod
33+
#
34+
# Define the repo path of a build target (a file with a
35+
# `main()` function) If not defined, this Aciton will collect all
36+
# dependencies used by all build targets for the module, which may
37+
# include Go dependencies used by tests and tooling.
38+
go-build-target: go-example/cmd/octocat.go
39+
#
3040
# All of the below have defaults, but can be overriden manually
3141
detector-name: go snapshot action
3242
detector-url: ${{ github.server_url }}/${{ github.repository }}

go-example/cmd/octocat.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"golang.org/x/example/stringutil"
7+
)
8+
9+
func main() {
10+
fmt.Println(stringutil.Reverse("reverof stacotcO"))
11+
}

go-example/go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module go-example
2+
3+
go 1.18
4+
5+
require golang.org/x/example v0.0.0-20220412213650-2e68773dfca0

go-example/go.sum

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
2+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
3+
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
4+
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
5+
golang.org/x/example v0.0.0-20220412213650-2e68773dfca0 h1:ygD+9PaH9IfzZUF131IxmiXGkxzuN/pphDjzh2LY8N8=
6+
golang.org/x/example v0.0.0-20220412213650-2e68773dfca0/go.mod h1:+yakPl5KR9J+ysfUNADYwEU5qeqjUO473wDktD4xMYw=
7+
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
8+
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
9+
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
10+
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
11+
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
12+
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
13+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
14+
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
15+
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
16+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
17+
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
18+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
19+
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
20+
golang.org/x/tools v0.0.0-20210112183307-1e6ecd4bf1b0/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
21+
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
22+
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
23+
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

go-example/octocat

1.68 MB
Binary file not shown.

src/index.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,20 @@ const goListDependencies = `go list -deps -f '{{define "M"}}{{.Path}}@{{.Version
2525
// Enumerate directories
2626
async function detect () {
2727
// If provided, set the metadata provided from the action workflow input
28-
const goModPath = core.getInput('goModPath')
28+
const goModPath = path.normalize(core.getInput('go-mod-path'))
2929
if (path.basename(goModPath) !== 'go.mod' && fs.existsSync(goModPath)) {
3030
throw new Error(`${goModPath} is not a go.mod file or does not exist!`)
3131
}
3232
const goModDir = path.dirname(goModPath)
33-
const goBuildTarget = core.getInput('goBuildTarget')
34-
if (goBuildTarget !== 'all' && goBuildTarget !== '...' && fs.existsSync(path.join(goModDir, goBuildTarget))) {
35-
throw new Error(`The build target '${goBuildTarget}' does not exist at ${path.join(goModDir, goBuildTarget)}`)
33+
34+
const goBuildTarget = path.normalize(core.getInput('go-build-target'))
35+
if (goBuildTarget !== 'all' && goBuildTarget !== '...') {
36+
if (!fs.existsSync(goBuildTarget)) {
37+
throw new Error(`The build target '${goBuildTarget}' does not exist`)
38+
}
39+
if (goModDir !== "." && !goBuildTarget.startsWith(goModDir)) {
40+
throw new Error(`The build target ${goBuildTarget} is not a sub-directory of ${goModDir}`)
41+
}
3642
}
3743

3844
const metadataInput = core.getInput('metadata')

0 commit comments

Comments
 (0)