Skip to content

Commit c374ce2

Browse files
committed
Fix review app delete project checkout
1 parent 6f44c84 commit c374ce2

4 files changed

Lines changed: 76 additions & 2 deletions

File tree

.github/actions/cpflow-delete-control-plane-app/action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@ inputs:
1111
review_app_prefix:
1212
description: Prefix used for review app names
1313
required: true
14+
working_directory:
15+
description: Directory containing the downstream project's .controlplane/controlplane.yml
16+
required: false
17+
default: "."
1418

1519
runs:
1620
using: composite
1721
steps:
1822
- name: Delete application
1923
shell: bash
24+
working-directory: ${{ inputs.working_directory }}
2025
run: ${{ github.action_path }}/delete-app.sh
2126
env:
2227
APP_NAME: ${{ inputs.app_name }}

.github/workflows/cpflow-delete-review-app.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,20 @@ jobs:
8181
variable:REVIEW_APP_PREFIX
8282
pull_request_friendly: "true"
8383

84+
- name: Checkout repository
85+
if: steps.config.outputs.ready == 'true'
86+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
87+
with:
88+
path: app
89+
persist-credentials: false
90+
8491
- name: Setup environment
8592
if: steps.config.outputs.ready == 'true'
8693
uses: ./.cpflow/.github/actions/cpflow-setup-environment
8794
with:
8895
token: ${{ secrets.CPLN_TOKEN_STAGING }}
8996
org: ${{ vars.CPLN_ORG_STAGING }}
90-
working_directory: .cpflow
97+
working_directory: app
9198
cpln_cli_version: ${{ vars.CPLN_CLI_VERSION }}
9299
cpflow_version: ${{ vars.CPFLOW_VERSION }}
93100

@@ -130,6 +137,7 @@ jobs:
130137
app_name: ${{ env.APP_NAME }}
131138
cpln_org: ${{ vars.CPLN_ORG_STAGING }}
132139
review_app_prefix: ${{ vars.REVIEW_APP_PREFIX }}
140+
working_directory: app
133141

134142
# Finalizer still runs after delete failures, but only after config validation
135143
# created the initial PR comment and workflow link env vars it updates.

spec/command/generate_github_actions_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,9 @@ def shared_workflow_path(name)
346346
contents = reusable_delete_review_workflow_path.read
347347
expect(contents).to include("concurrency:")
348348
expect(contents).to include('pull_request_friendly: "true"')
349-
expect(contents).to include("working_directory: .cpflow")
349+
expect(contents).to include("Checkout repository")
350+
expect(contents).to include("path: app")
351+
expect(contents).to include("working_directory: app")
350352
expect(delete_review_workflow_path.read).to include("pull_request_target:")
351353
expect(delete_review_workflow_path.read).to include("pull_request_target is intentional")
352354
expect(delete_review_workflow_path.read).to include("mirrors the upstream job guard")

spec/github_workflows_spec.rb

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# frozen_string_literal: true
2+
3+
require "spec_helper"
4+
require "yaml"
5+
6+
RSpec.describe "GitHub workflow definitions" do # rubocop:disable RSpec/DescribeClass
7+
describe "Delete Review App workflow" do
8+
let(:workflow) do
9+
YAML.safe_load_file(
10+
File.expand_path("../.github/workflows/cpflow-delete-review-app.yml", __dir__),
11+
aliases: true
12+
)
13+
end
14+
15+
let(:steps) { workflow.fetch("jobs").fetch("delete-review-app").fetch("steps") }
16+
17+
def step_named(name)
18+
steps.find { |step| step["name"] == name }
19+
end
20+
21+
it "runs cpflow delete from a downstream app checkout" do
22+
expect(step_named("Checkout repository")).to include(
23+
"uses" => "actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd",
24+
"with" => include(
25+
"path" => "app",
26+
"persist-credentials" => false
27+
)
28+
)
29+
30+
expect(step_named("Setup environment").fetch("with")).to include(
31+
"working_directory" => "app"
32+
)
33+
expect(step_named("Delete review app").fetch("with")).to include(
34+
"working_directory" => "app"
35+
)
36+
end
37+
end
38+
39+
describe "Delete Control Plane App action" do
40+
let(:action) do
41+
YAML.safe_load_file(
42+
File.expand_path("../.github/actions/cpflow-delete-control-plane-app/action.yml", __dir__),
43+
aliases: true
44+
)
45+
end
46+
47+
it "allows callers to choose the project working directory" do
48+
expect(action.fetch("inputs")).to include(
49+
"working_directory" => include("default" => ".")
50+
)
51+
52+
delete_step = action.fetch("runs").fetch("steps").find { |step| step["name"] == "Delete application" }
53+
54+
expect(delete_step).to include(
55+
"working-directory" => "${{ inputs.working_directory }}"
56+
)
57+
end
58+
end
59+
end

0 commit comments

Comments
 (0)