-
Notifications
You must be signed in to change notification settings - Fork 0
chore: migrate diagnose & capture-screen to multi-gateway TARGETS_JSON #88
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,11 @@ name: Capture Gateway Screen | |
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| target: | ||
| description: Gateway target (from IB_GATEWAY_TARGETS_JSON) | ||
| required: false | ||
| default: all | ||
| type: string | ||
| screen_action: | ||
| description: Optional interaction before capturing the screen | ||
| required: false | ||
|
|
@@ -19,27 +24,74 @@ on: | |
| default: false | ||
| type: boolean | ||
|
|
||
| env: | ||
| GCP_PROJECT_ID: interactivebrokersquant | ||
| GCP_WORKLOAD_IDENTITY_PROVIDER: projects/303168642265/locations/global/workloadIdentityPools/github-actions/providers/github-ibkr-gateway-main | ||
| GCP_WORKLOAD_IDENTITY_SERVICE_ACCOUNT: ibkr-gateway-deploy@interactivebrokersquant.iam.gserviceaccount.com | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref_name }} | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| resolve: | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| matrix: ${{ steps.resolve.outputs.matrix }} | ||
| steps: | ||
| - name: Resolve gateway targets | ||
| id: resolve | ||
| env: | ||
| TARGETS_JSON: ${{ vars.IB_GATEWAY_TARGETS_JSON }} | ||
| SELECTED_TARGET: ${{ github.event.inputs.target || 'all' }} | ||
| run: | | ||
| import json, os, sys | ||
|
|
||
| raw = os.environ.get("TARGETS_JSON", "").strip() | ||
| if not raw: | ||
| raise SystemExit("IB_GATEWAY_TARGETS_JSON is required") | ||
|
|
||
| loaded = json.loads(raw) | ||
| targets = [] | ||
| if isinstance(loaded, dict): | ||
| for name, config in loaded.items(): | ||
| cfg = dict(config) | ||
| cfg["name"] = name | ||
| targets.append(cfg) | ||
| elif isinstance(loaded, list): | ||
| targets = loaded | ||
| else: | ||
| raise SystemExit("IB_GATEWAY_TARGETS_JSON must be an object or list") | ||
|
|
||
| selected_name = os.environ.get("SELECTED_TARGET", "all") | ||
| if selected_name == "all": | ||
| selected = targets | ||
| else: | ||
| selected = [t for t in targets if t["name"] == selected_name] | ||
| if not selected: | ||
| known = ", ".join(t["name"] for t in targets) | ||
| raise SystemExit(f"Unknown target {selected_name!r}. Known: {known}") | ||
|
|
||
| with open(os.environ["GITHUB_OUTPUT"], "a") as f: | ||
| f.write("matrix=" + json.dumps({"target": selected}, separators=(",", ":")) + "\n") | ||
| print("Targets: " + ", ".join(t["name"] for t in selected)) | ||
| shell: python3 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Both migrated resolve jobs set Useful? React with 👍 / 👎. |
||
|
|
||
| capture: | ||
| needs: resolve | ||
| if: needs.resolve.outputs.matrix != '{"target":[]}' | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 8 | ||
| strategy: | ||
| matrix: ${{ fromJson(needs.resolve.outputs.matrix) }} | ||
|
Comment on lines
+80
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎. |
||
| fail-fast: false | ||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
| env: | ||
| GCE_USER: ${{ vars.IB_GATEWAY_GCE_USER }} | ||
| GCE_INSTANCE_NAME: ${{ vars.IB_GATEWAY_INSTANCE_NAME }} | ||
| GCE_ZONE: ${{ vars.IB_GATEWAY_ZONE }} | ||
| SSH_PRIVATE_KEY_SECRET_NAME: ${{ vars.IB_GATEWAY_SSH_PRIVATE_KEY_SECRET_NAME }} | ||
| TARGET_NAME: ${{ matrix.target.name }} | ||
| GCP_PROJECT_ID: ${{ matrix.target.gcp_project_id }} | ||
| GCP_WORKLOAD_IDENTITY_PROVIDER: ${{ matrix.target.gcp_workload_identity_provider }} | ||
| GCP_WORKLOAD_IDENTITY_SERVICE_ACCOUNT: ${{ matrix.target.gcp_workload_identity_service_account }} | ||
| GCE_USER: ${{ matrix.target.gce_user }} | ||
| GCE_INSTANCE_NAME: ${{ matrix.target.gce_instance_name }} | ||
| GCE_ZONE: ${{ matrix.target.gce_zone }} | ||
| SSH_PRIVATE_KEY_SECRET_NAME: ${{ matrix.target.ssh_private_key_secret_name }} | ||
|
Comment on lines
+87
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This matrix env block only carries VM and SSH fields from Useful? React with 👍 / 👎. |
||
| SCREEN_ACTION: ${{ github.event.inputs.screen_action }} | ||
| WAIT_FOR_SECOND_FACTOR: ${{ github.event.inputs.wait_for_second_factor }} | ||
| steps: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,30 +5,83 @@ on: | |
| branches: [ main ] | ||
| paths: | ||
| - '.github/workflows/diagnose.yml' | ||
| workflow_dispatch: {} | ||
|
|
||
| env: | ||
| GCP_PROJECT_ID: interactivebrokersquant | ||
| GCP_WORKLOAD_IDENTITY_PROVIDER: projects/303168642265/locations/global/workloadIdentityPools/github-actions/providers/github-ibkr-gateway-main | ||
| GCP_WORKLOAD_IDENTITY_SERVICE_ACCOUNT: ibkr-gateway-deploy@interactivebrokersquant.iam.gserviceaccount.com | ||
| workflow_dispatch: | ||
| inputs: | ||
| target: | ||
| description: Gateway target (from IB_GATEWAY_TARGETS_JSON) | ||
| required: false | ||
| default: all | ||
| type: string | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref_name }} | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| resolve: | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| matrix: ${{ steps.resolve.outputs.matrix }} | ||
| steps: | ||
| - name: Resolve gateway targets | ||
| id: resolve | ||
| env: | ||
| TARGETS_JSON: ${{ vars.IB_GATEWAY_TARGETS_JSON }} | ||
| SELECTED_TARGET: ${{ github.event.inputs.target || 'all' }} | ||
| run: | | ||
| import json, os, sys | ||
|
|
||
| raw = os.environ.get("TARGETS_JSON", "").strip() | ||
| if not raw: | ||
| raise SystemExit("IB_GATEWAY_TARGETS_JSON is required") | ||
|
|
||
| loaded = json.loads(raw) | ||
| targets = [] | ||
| if isinstance(loaded, dict): | ||
| for name, config in loaded.items(): | ||
| cfg = dict(config) | ||
| cfg["name"] = name | ||
| targets.append(cfg) | ||
| elif isinstance(loaded, list): | ||
| targets = loaded | ||
| else: | ||
| raise SystemExit("IB_GATEWAY_TARGETS_JSON must be an object or list") | ||
|
|
||
| selected_name = os.environ.get("SELECTED_TARGET", "all") | ||
| if selected_name == "all": | ||
| selected = targets | ||
| else: | ||
| selected = [t for t in targets if t["name"] == selected_name] | ||
| if not selected: | ||
| known = ", ".join(t["name"] for t in targets) | ||
| raise SystemExit(f"Unknown target {selected_name!r}. Known: {known}") | ||
|
|
||
| with open(os.environ["GITHUB_OUTPUT"], "a") as f: | ||
| f.write("matrix=" + json.dumps({"target": selected}, separators=(",", ":")) + "\n") | ||
| print("Targets: " + ", ".join(t["name"] for t in selected)) | ||
| shell: python3 | ||
|
|
||
| diagnose: | ||
| needs: resolve | ||
| if: needs.resolve.outputs.matrix != '{"target":[]}' | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 8 | ||
| strategy: | ||
| matrix: ${{ fromJson(needs.resolve.outputs.matrix) }} | ||
| fail-fast: false | ||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
| env: | ||
| GCE_USER: ${{ vars.IB_GATEWAY_GCE_USER }} | ||
| GCE_INSTANCE_NAME: ${{ vars.IB_GATEWAY_INSTANCE_NAME }} | ||
| GCE_ZONE: ${{ vars.IB_GATEWAY_ZONE }} | ||
| DEPLOY_PATH: ${{ vars.IB_GATEWAY_DEPLOY_PATH }} | ||
| SSH_PRIVATE_KEY_SECRET_NAME: ${{ vars.IB_GATEWAY_SSH_PRIVATE_KEY_SECRET_NAME }} | ||
| TARGET_NAME: ${{ matrix.target.name }} | ||
| GCP_PROJECT_ID: ${{ matrix.target.gcp_project_id }} | ||
| GCP_WORKLOAD_IDENTITY_PROVIDER: ${{ matrix.target.gcp_workload_identity_provider }} | ||
| GCP_WORKLOAD_IDENTITY_SERVICE_ACCOUNT: ${{ matrix.target.gcp_workload_identity_service_account }} | ||
| GCE_USER: ${{ matrix.target.gce_user }} | ||
| GCE_INSTANCE_NAME: ${{ matrix.target.gce_instance_name }} | ||
| GCE_ZONE: ${{ matrix.target.gce_zone }} | ||
| DEPLOY_PATH: ${{ matrix.target.deploy_path }} | ||
| SSH_PRIVATE_KEY_SECRET_NAME: ${{ matrix.target.ssh_private_key_secret_name }} | ||
|
Comment on lines
+76
to
+84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The diagnostic job now selects a target, but this env block drops the target's Useful? React with 👍 / 👎.
Comment on lines
+83
to
+84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The migrated diagnostic env only passes deploy/SSH fields, but multi-gateway targets in Useful? React with 👍 / 👎. |
||
| steps: | ||
| - name: Authenticate to Google Cloud | ||
| id: auth | ||
|
|
||
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.
The resolver now overwrites every object-form entry's
namewith the map key, while.github/workflows/main.ymlusestarget.setdefault("name", name)for the sameIB_GATEWAY_TARGETS_JSONschema. If the repo variable already relies on an explicitnameinside the target object (which main accepts), manualtargetselection by that gateway name fails here and the matrix runs under the wrong name; usesetdefaultand validate names consistently.Useful? React with 👍 / 👎.