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

Go list implementation for detecting dependencies #5

Merged
merged 23 commits into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add example go project and Action
  • Loading branch information
lseppala authored May 14, 2022
commit a1ce362bb42fb49b7e079d2e03511ba233dd6ae6
21 changes: 21 additions & 0 deletions .github/workflows/go-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Go Action detection of dependencies
on:
push
# on:
# push:
# branches:
# - main
jobs:
go-action-detection:
runs-on: ubuntu-latest
steps:
- name: 'Checkout Repository'
uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: ">=1.18.0"
- name: Run snapshot action
uses: dsp-testing/go-snapshot-action@main
with:
go-mod-path: go-example/go.mod
go-build-target: go-example/cmd/octocat.go
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ An Action that creates a dependency submission using `go mod graph`.
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.

### Example
```
```yaml
name: Go Action detection of dependencies
on:
push:
Expand All @@ -27,6 +27,16 @@ jobs:
- name: Run snapshot action
uses: @dsp-testing/go-snapshot-action
with:
# Required: Define the repo path to the go.mod file used by the
# build target
go-mod-path: go-example/go.mod
#
# Define the repo path of a build target (a file with a
# `main()` function) If not defined, this Aciton will collect all
# dependencies used by all build targets for the module, which may
# include Go dependencies used by tests and tooling.
go-build-target: go-example/cmd/octocat.go
#
# All of the below have defaults, but can be overriden manually
detector-name: go snapshot action
detector-url: ${{ github.server_url }}/${{ github.repository }}
Expand Down
11 changes: 11 additions & 0 deletions go-example/cmd/octocat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import (
"fmt"

"golang.org/x/example/stringutil"
)

func main() {
fmt.Println(stringutil.Reverse("reverof stacotcO"))
}
5 changes: 5 additions & 0 deletions go-example/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module go-example

go 1.18

require golang.org/x/example v0.0.0-20220412213650-2e68773dfca0
23 changes: 23 additions & 0 deletions go-example/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/example v0.0.0-20220412213650-2e68773dfca0 h1:ygD+9PaH9IfzZUF131IxmiXGkxzuN/pphDjzh2LY8N8=
golang.org/x/example v0.0.0-20220412213650-2e68773dfca0/go.mod h1:+yakPl5KR9J+ysfUNADYwEU5qeqjUO473wDktD4xMYw=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20210112183307-1e6ecd4bf1b0/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Binary file added go-example/octocat
Binary file not shown.
14 changes: 10 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,20 @@ const goListDependencies = `go list -deps -f '{{define "M"}}{{.Path}}@{{.Version
// Enumerate directories
async function detect () {
// If provided, set the metadata provided from the action workflow input
const goModPath = core.getInput('goModPath')
const goModPath = path.normalize(core.getInput('go-mod-path'))
if (path.basename(goModPath) !== 'go.mod' && fs.existsSync(goModPath)) {
throw new Error(`${goModPath} is not a go.mod file or does not exist!`)
}
const goModDir = path.dirname(goModPath)
const goBuildTarget = core.getInput('goBuildTarget')
if (goBuildTarget !== 'all' && goBuildTarget !== '...' && fs.existsSync(path.join(goModDir, goBuildTarget))) {
throw new Error(`The build target '${goBuildTarget}' does not exist at ${path.join(goModDir, goBuildTarget)}`)

const goBuildTarget = path.normalize(core.getInput('go-build-target'))
if (goBuildTarget !== 'all' && goBuildTarget !== '...') {
if (!fs.existsSync(goBuildTarget)) {
throw new Error(`The build target '${goBuildTarget}' does not exist`)
}
if (goModDir !== "." && !goBuildTarget.startsWith(goModDir)) {
throw new Error(`The build target ${goBuildTarget} is not a sub-directory of ${goModDir}`)
}
}

const metadataInput = core.getInput('metadata')
Expand Down