Skip to content

Commit 630b056

Browse files
authored
test: act fixes (#411)
1 parent f107c84 commit 630b056

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

.github/workflows/test-act.yml renamed to .github/workflows/pr-checks-test-ci.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ on:
99
- main
1010
paths:
1111
- "tests/**"
12-
- ".github/workflows/test-act.yml"
12+
- ".github/workflows/pr-checks-test-ci.yml"
1313
- ".github/workflows/ci.yml"
1414

15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.ref }}
17+
cancel-in-progress: true
18+
1519
env:
1620
ACT_VERSION: v0.2.82
1721

@@ -24,7 +28,7 @@ jobs:
2428
runs-on: ubuntu-x64-large
2529
steps:
2630
- name: Checkout
27-
uses: actions/checkout@v5
31+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
2832
with:
2933
ref: ${{ github.event.pull_request.head.sha || github.ref }}
3034
fetch-depth: 0
@@ -47,7 +51,7 @@ jobs:
4751
shell: bash
4852

4953
- name: Setup Go
50-
uses: actions/setup-go@v5
54+
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
5155
with:
5256
go-version-file: tests/act/go.mod
5357
cache-dependency-path: tests/act/go.sum

tests/act/internal/act/act.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,29 @@ func NewRunner(t *testing.T) (*Runner, error) {
6969
}
7070

7171
// args returns the CLI arguments to pass to act for the given workflow and event payload files.
72-
func (r *Runner) args(workflowFile string, payloadFile string) []string {
72+
func (r *Runner) args(workflowFile string, payloadFile string) ([]string, error) {
7373
pciwfRoot, err := os.Getwd()
7474
if err != nil {
75-
// TODO: do not fail silently
76-
pciwfRoot = ""
75+
return nil, fmt.Errorf("get working directory: %w", err)
7776
}
77+
f, err := os.Open(".release-please-manifest.json")
78+
if err != nil {
79+
return nil, fmt.Errorf("open .release-please-manifest.json: %w", err)
80+
}
81+
defer f.Close()
82+
var releasePleaseManifest map[string]string
83+
if err := json.NewDecoder(f).Decode(&releasePleaseManifest); err != nil {
84+
return nil, fmt.Errorf("decode release-please-config.json: %w", err)
85+
}
86+
releasePleaseTag := "ci-cd-workflows/" + "v" + releasePleaseManifest[".github/workflows"]
7887
args := []string{
7988
"-W", workflowFile,
8089
"-e", payloadFile,
8190
"--rm",
8291
"--json",
8392
"--artifact-server-path=/tmp/artifacts/",
8493
"--local-repository=grafana/plugin-ci-workflows@main=" + pciwfRoot,
94+
"--local-repository=grafana/plugin-ci-workflows@" + releasePleaseTag + "=" + pciwfRoot,
8595
"--secret", "GITHUB_TOKEN=" + r.gitHubToken,
8696
}
8797
if r.ConcurrentJobs > 0 {
@@ -91,7 +101,7 @@ func (r *Runner) args(workflowFile string, payloadFile string) []string {
91101
for _, label := range selfHostedRunnerLabels {
92102
args = append(args, "-P", label+"="+nektosActRunnerImage)
93103
}
94-
return args
104+
return args, nil
95105
}
96106

97107
// Run runs the given workflow with the given event payload using act.
@@ -111,7 +121,10 @@ func (r *Runner) Run(workflow workflow.Marshalable, eventPayload EventPayload) e
111121
}
112122
defer os.Remove(payloadFile)
113123

114-
args := r.args(workflowFile, payloadFile)
124+
args, err := r.args(workflowFile, payloadFile)
125+
if err != nil {
126+
return fmt.Errorf("get act args: %w", err)
127+
}
115128

116129
// TODO: escape args to avoid shell injection
117130
actCmd := "act " + strings.Join(args, " ")

0 commit comments

Comments
 (0)