Skip to content

Commit

Permalink
Fix workdir for dockerized action step (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham149 authored Mar 14, 2023
1 parent e062a43 commit c989969
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/drone/plugin

go 1.19

replace github.com/nektos/act => github.com/harness/nektos-act v0.0.0-20230313083509-8da49f0747a0
replace github.com/nektos/act => github.com/harness/nektos-act v0.0.0-20230314090425-5caf6f83c677

require (
github.com/buildkite/yaml v2.1.0+incompatible
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/harness/nektos-act v0.0.0-20230313083509-8da49f0747a0 h1:XTYnayyKudpVCssAWimue+xrMdcijScFRdI8ugZf7jc=
github.com/harness/nektos-act v0.0.0-20230313083509-8da49f0747a0/go.mod h1:iLHCXqOPUElA2nSyHo4wtxSmvdkym3WU7CkP3AxF39Q=
github.com/harness/nektos-act v0.0.0-20230314090425-5caf6f83c677 h1:4Vz5ksSUCDQ78GRQQNt4fy1cwcZd/osQYEED051fBJ4=
github.com/harness/nektos-act v0.0.0-20230314090425-5caf6f83c677/go.mod h1:iLHCXqOPUElA2nSyHo4wtxSmvdkym3WU7CkP3AxF39Q=
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog=
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68=
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
Expand Down
21 changes: 16 additions & 5 deletions plugin/github/execer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package github

import (
"context"
"encoding/json"
"io"
"io/ioutil"
"os"
Expand All @@ -14,6 +15,7 @@ import (
"github.com/drone/plugin/plugin/internal/environ"
"github.com/nektos/act/cmd"
"github.com/pkg/errors"
"golang.org/x/exp/slog"
)

// Execer executes a github action.
Expand Down Expand Up @@ -61,13 +63,17 @@ func (e *Execer) Exec(ctx context.Context) error {
}

if eventPayload, ok := envVars["PLUGIN_EVENT_PAYLOAD"]; ok {
eventPayloadFile := filepath.Join(tmpDir, "event.yml")
if isJSON(eventPayload) {
eventPayloadFile := filepath.Join(tmpDir, "event.yml")

if err := ioutil.WriteFile(eventPayloadFile, []byte(eventPayload), 0644); err != nil {
return errors.Wrap(err, "failed to write event payload to file")
}
if err := ioutil.WriteFile(eventPayloadFile, []byte(eventPayload), 0644); err != nil {
return errors.Wrap(err, "failed to write event payload to file")
}

os.Args = append(os.Args, "--eventpath", eventPayloadFile)
os.Args = append(os.Args, "--eventpath", eventPayloadFile)
} else {
slog.Debug("invalid event payload", eventPayload)
}
}

cmd.Execute(ctx, "1.1")
Expand All @@ -77,3 +83,8 @@ func (e *Execer) Exec(ctx context.Context) error {
}
return nil
}

func isJSON(str string) bool {
var js json.RawMessage
return json.Unmarshal([]byte(str), &js) == nil
}

0 comments on commit c989969

Please sign in to comment.