-
Notifications
You must be signed in to change notification settings - Fork 370
Update cpflow workflows for 6.0.0.rc.0 #818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
justin808
wants to merge
1
commit into
master
Choose a base branch
from
jg-codex/cpflow-6-final-verification
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| name: Detect release phase support | ||
| description: >- | ||
| Inspects .controlplane/controlplane.yml for an app and emits `flag=--run-release-phase` | ||
| when a `release_script:` is configured. Outputs an empty `flag` otherwise. | ||
|
|
||
| inputs: | ||
| app_name: | ||
| description: cpflow app name to inspect | ||
| required: true | ||
| working_directory: | ||
| description: Directory containing .controlplane/controlplane.yml | ||
| required: false | ||
| default: "." | ||
|
|
||
| outputs: | ||
| flag: | ||
| description: Either `--run-release-phase` or empty | ||
| value: ${{ steps.detect.outputs.flag }} | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Detect release phase support | ||
| id: detect | ||
| shell: bash | ||
| env: | ||
| APP_NAME: ${{ inputs.app_name }} | ||
| WORKING_DIRECTORY: ${{ inputs.working_directory }} | ||
| run: | | ||
| set -euo pipefail | ||
| cd "${WORKING_DIRECTORY}" | ||
|
|
||
| release_script="$(ruby - "${APP_NAME}" <<'RUBY' | ||
| require "yaml" | ||
|
|
||
| app_name = ARGV.fetch(0) | ||
|
|
||
| unless File.file?(".controlplane/controlplane.yml") | ||
| warn "Error: `.controlplane/controlplane.yml` is missing. " \ | ||
| "cpflow-detect-release-phase must be invoked from a cpflow-configured project." | ||
| exit 1 | ||
| end | ||
|
|
||
| data = YAML.safe_load(File.read(".controlplane/controlplane.yml"), aliases: true) | ||
| apps = data["apps"] || {} | ||
| app_config = apps[app_name] | ||
|
|
||
| unless app_config | ||
| app_config = apps.find do |name, config| | ||
| config.is_a?(Hash) && | ||
| config["match_if_app_name_starts_with"] && | ||
| app_name.start_with?(name) | ||
| end&.last | ||
| end | ||
|
|
||
| unless app_config.is_a?(Hash) | ||
| warn "Error: app '#{app_name}' is not defined under `apps:` in `.controlplane/controlplane.yml`." | ||
| exit 1 | ||
| end | ||
|
|
||
| puts app_config["release_script"].to_s | ||
| RUBY | ||
| )" | ||
|
|
||
| if [[ -n "${release_script}" ]]; then | ||
| echo "flag=--run-release-phase" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "flag=" >> "$GITHUB_OUTPUT" | ||
| fi |
137 changes: 137 additions & 0 deletions
137
.github/actions/cpflow-resolve-review-config/action.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| name: Resolve Review App Config | ||
| description: Infers review app prefix and Control Plane org from controlplane.yml | ||
|
|
||
| inputs: | ||
| configured_cpln_org_staging: | ||
| description: Optional override for the staging Control Plane org. | ||
| required: false | ||
| default: "" | ||
| configured_review_app_prefix: | ||
| description: Optional override for the review app prefix. | ||
| required: false | ||
| default: "" | ||
| pr_number: | ||
| description: Pull request number used to build the review app name. | ||
| required: false | ||
| default: "" | ||
| working_directory: | ||
| description: Directory containing .controlplane/controlplane.yml. | ||
| required: false | ||
| default: "." | ||
|
|
||
| outputs: | ||
| review_app_prefix: | ||
| description: Resolved review app prefix. | ||
| value: ${{ steps.resolve.outputs.review_app_prefix }} | ||
| cpln_org: | ||
| description: Resolved Control Plane org. | ||
| value: ${{ steps.resolve.outputs.cpln_org }} | ||
| app_name: | ||
| description: Resolved review app name when pr_number is present; omitted when pr_number is empty. | ||
| value: ${{ steps.resolve.outputs.app_name }} | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Resolve review app config | ||
| id: resolve | ||
| shell: bash | ||
| working-directory: ${{ inputs.working_directory }} | ||
| env: | ||
| CONFIGURED_CPLN_ORG_STAGING: ${{ inputs.configured_cpln_org_staging }} | ||
| CONFIGURED_REVIEW_APP_PREFIX: ${{ inputs.configured_review_app_prefix }} | ||
| PR_NUMBER: ${{ inputs.pr_number }} | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| ruby <<'RUBY' | ||
| require "yaml" | ||
|
|
||
| def safe_load_yaml_file(path) | ||
| contents = File.read(path) | ||
|
|
||
| if YAML.method(:safe_load).parameters.any? { |type, name| type == :key && name == :aliases } | ||
| YAML.safe_load(contents, aliases: true) | ||
| else | ||
| YAML.safe_load(contents, [], [], true) | ||
| end | ||
| end | ||
|
|
||
| def validate_github_env_value!(name, value) | ||
| return if value.match?(/\A[A-Za-z0-9-]+\z/) | ||
|
|
||
| warn "::error::#{name} must contain only letters, numbers, and hyphens so it is a valid Control Plane name and can be safely written to GitHub environment files." | ||
| exit 1 | ||
| end | ||
|
|
||
| begin | ||
| config = safe_load_yaml_file(".controlplane/controlplane.yml") | ||
| unless config.is_a?(Hash) | ||
| warn "::error::.controlplane/controlplane.yml must be a YAML mapping; got #{config.class}: #{config.inspect}" | ||
| exit 1 | ||
| end | ||
|
|
||
| apps = config["apps"] | ||
| unless apps.is_a?(Hash) | ||
| warn "::error::.controlplane/controlplane.yml must define an apps mapping; got #{apps.class}: #{apps.inspect}" | ||
| exit 1 | ||
| end | ||
|
|
||
| review_apps = apps.select do |_name, app_config| | ||
| app_config.is_a?(Hash) && app_config["match_if_app_name_starts_with"] == true | ||
| end | ||
|
|
||
| prefix = ENV.fetch("CONFIGURED_REVIEW_APP_PREFIX", "").strip | ||
| if prefix.empty? | ||
| if review_apps.length == 1 | ||
| prefix = review_apps.keys.first | ||
| elsif review_apps.empty? | ||
| warn "::error::Set REVIEW_APP_PREFIX or define exactly one app with match_if_app_name_starts_with: true in .controlplane/controlplane.yml." | ||
| exit 1 | ||
| else | ||
| warn "::error::Set REVIEW_APP_PREFIX because .controlplane/controlplane.yml defines multiple review app prefixes: #{review_apps.keys.sort.join(', ')}." | ||
| exit 1 | ||
| end | ||
| end | ||
|
|
||
| app_config = apps[prefix] | ||
| unless app_config.is_a?(Hash) && app_config["match_if_app_name_starts_with"] == true | ||
| warn "::error::Review app prefix '#{prefix}' must match an app in .controlplane/controlplane.yml with match_if_app_name_starts_with: true." | ||
| exit 1 | ||
| end | ||
|
|
||
| cpln_org = ENV.fetch("CONFIGURED_CPLN_ORG_STAGING", "").strip | ||
| cpln_org = app_config["cpln_org"].to_s.strip if cpln_org.empty? | ||
| if cpln_org.empty? | ||
| warn "::error::Set CPLN_ORG_STAGING or cpln_org for review app prefix '#{prefix}' in .controlplane/controlplane.yml." | ||
| exit 1 | ||
| end | ||
|
|
||
| pr_number = ENV.fetch("PR_NUMBER", "").strip | ||
| unless pr_number.empty? || pr_number.match?(/\A[1-9][0-9]*\z/) | ||
| warn "::error::PR_NUMBER must be a positive integer; got: #{pr_number.inspect}" | ||
| exit 1 | ||
| end | ||
|
|
||
| app_name = pr_number.empty? ? "" : "#{prefix}-#{pr_number}" | ||
|
|
||
| validate_github_env_value!("REVIEW_APP_PREFIX", prefix) | ||
| validate_github_env_value!("CPLN_ORG", cpln_org) | ||
| validate_github_env_value!("APP_NAME", app_name) unless app_name.empty? | ||
|
|
||
| File.open(ENV.fetch("GITHUB_ENV"), "a") do |file| | ||
| file.puts "REVIEW_APP_PREFIX=#{prefix}" | ||
| file.puts "CPLN_ORG=#{cpln_org}" | ||
| file.puts "APP_NAME=#{app_name}" unless app_name.empty? | ||
| end | ||
|
|
||
| File.open(ENV.fetch("GITHUB_OUTPUT"), "a") do |file| | ||
| file.puts "review_app_prefix=#{prefix}" | ||
| file.puts "cpln_org=#{cpln_org}" | ||
| file.puts "app_name=#{app_name}" unless app_name.empty? | ||
| end | ||
| rescue StandardError => e | ||
| warn "::error::Could not resolve review app config from .controlplane/controlplane.yml: #{e.class}: #{e.message}" | ||
| exit 1 | ||
| end | ||
| RUBY |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this action runs on a reused or self-hosted runner and the job is cancelled after SSH preparation but before the build step starts, the private key remains at
~/.ssh/cpflow_build_keybecause cleanup is registered only by the later step. The preparation step also overwrites any existingknown_hostsfile without preserving it. This can expose the key to a later job and damage the runner's SSH configuration. Cleanup should be registered where the files are created or handled by action-level post cleanup, while preserving existing SSH configuration.How this was verified: The secret is written during the preparation step, while the only removal is an EXIT trap installed by the later build step.