-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from storyprotocol/feat/refactor_bastion
[feat] add reusable-check-network workflow
- Loading branch information
Showing
8 changed files
with
934 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,70 @@ | ||
name: Check Network File Changes | ||
|
||
on: | ||
workflow_call: | ||
secrets: | ||
token: | ||
required: true | ||
outputs: | ||
devnet_changed: | ||
description: 'Whether the devnet network files were changed' | ||
value: ${{ jobs.check-network-changes.outputs.devnet_changed }} | ||
testnet_changed: | ||
description: 'Whether the testnet network files were changed' | ||
value: ${{ jobs.check-network-changes.outputs.testnet_changed }} | ||
|
||
jobs: | ||
check-network-changes: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
devnet_changed: ${{ steps.check_changes.outputs.devnet_changed }} | ||
testnet_changed: ${{ steps.check_changes.outputs.testnet_changed }} | ||
|
||
steps: | ||
- uses: jitterbit/get-changed-files@v1 | ||
id: changed_files | ||
with: | ||
format: space-delimited | ||
token: ${{ secrets.token }} | ||
|
||
- name: Determine if relevant files changed and retrieve network types | ||
id: check_changes | ||
run: | | ||
CHANGED_FILES="${{ steps.changed_files.outputs.modified }}" | ||
echo "Changed files: $CHANGED_FILES" | ||
# Define the files we care about | ||
AUTHORIZED_KEYS_DEVNET="authorized_keys_odyssey_devnet" | ||
AUTHORIZED_KEYS_TESTNET="authorized_keys_odyssey_testnet" | ||
BASTION_ACCESS_DEVNET="bastion-access-devnet.yml" | ||
BASTION_ACCESS_TESTNET="bastion-access-testnet.yml" | ||
# Initialize flags for network types | ||
DEVNET_CHANGED=false | ||
TESTNET_CHANGED=false | ||
# Check if any of the files were modified and set the flags | ||
if echo "$CHANGED_FILES" | grep -q "$AUTHORIZED_KEYS_DEVNET"; then | ||
DEVNET_CHANGED=true | ||
echo "authorized_keys for devnet changed" | ||
fi | ||
if echo "$CHANGED_FILES" | grep -q "$AUTHORIZED_KEYS_TESTNET"; then | ||
TESTNET_CHANGED=true | ||
echo "authorized_keys for testnet changed" | ||
fi | ||
if echo "$CHANGED_FILES" | grep -q "$BASTION_ACCESS_DEVNET"; then | ||
DEVNET_CHANGED=true | ||
echo "bastion access for devnet changed" | ||
fi | ||
if echo "$CHANGED_FILES" | grep -q "$BASTION_ACCESS_TESTNET"; then | ||
TESTNET_CHANGED=true | ||
echo "bastion access for testnet changed" | ||
fi | ||
# Output the values for use in subsequent steps | ||
echo "devnet_changed=$DEVNET_CHANGED" >> $GITHUB_OUTPUT | ||
echo "testnet_changed=$TESTNET_CHANGED" >> $GITHUB_OUTPUT | ||
# Print the results for verification | ||
echo "DevNet changed: $DEVNET_CHANGED" | ||
echo "TestNet changed: $TESTNET_CHANGED" |
This file contains 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,116 @@ | ||
name: Fetch Bastion Host IPs | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
role_to_assume: | ||
description: "The role to assume" | ||
required: true | ||
type: string | ||
aws_region: | ||
description: "The AWS region to use" | ||
required: true | ||
type: string | ||
devnet_changed: | ||
description: "Boolean to check if DevNet files have changed" | ||
required: true | ||
type: string | ||
testnet_changed: | ||
description: "Boolean to check if TestNet files have changed" | ||
required: true | ||
type: string | ||
instance_name_devnet: | ||
description: "The instance name for Odyssey DevNet Bastion" | ||
required: true | ||
type: string | ||
instance_name_testnet: | ||
description: "The instance name for Odyssey TestNet Bastion" | ||
required: true | ||
type: string | ||
role_bastion: | ||
description: "The role for the Bastion host (default: bastion)" | ||
required: true | ||
type: string | ||
default: "bastion" | ||
instance_region: | ||
description: "The region to search for instances" | ||
required: true | ||
type: string | ||
outputs: | ||
instance_ip_odyssey_devnet: | ||
description: "The IP address of the DevNet Bastion host" | ||
value: ${{ jobs.fetch_bastion_ips.outputs.instance_ip_odyssey_devnet }} | ||
instance_ip_odyssey_testnet: | ||
description: "The IP address of the TestNet Bastion host" | ||
value: ${{ jobs.fetch_bastion_ips.outputs.instance_ip_odyssey_testnet }} | ||
|
||
jobs: | ||
fetch_bastion_ips: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
instance_ip_odyssey_devnet: ${{ steps.get_instance_ips.outputs.instance_ip_odyssey_devnet }} | ||
instance_ip_odyssey_testnet: ${{ steps.get_instance_ips.outputs.instance_ip_odyssey_testnet }} | ||
|
||
steps: | ||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
role-to-assume: ${{ inputs.role_to_assume }} | ||
aws-region: ${{ inputs.aws_region }} | ||
role-session-name: github-actions | ||
|
||
- name: Fetch Bastion Host IPs | ||
id: get_instance_ips | ||
run: | | ||
DEVNET_CHANGED="${{ inputs.devnet_changed }}" | ||
TESTNET_CHANGED="${{ inputs.testnet_changed }}" | ||
INSTANCE_NAME_ODYSSEY_DEVNET="${{ inputs.instance_name_devnet }}" | ||
INSTANCE_NAME_ODYSSEY_TESTNET="${{ inputs.instance_name_testnet }}" | ||
ROLE_BASTION="${{ inputs.role_bastion }}" | ||
INSTANCE_REGION="${{ inputs.instance_region }}" | ||
# Fetch DevNet Bastion IP if changes are detected | ||
if [ "$DEVNET_CHANGED" = "true" ]; then | ||
echo "Fetching DevNet Bastion IP" | ||
INSTANCE_IP_ODYSSEY_DEVNET=$(aws ec2 describe-instances \ | ||
--region $INSTANCE_REGION \ | ||
--filters "Name=tag:Network,Values=$INSTANCE_NAME_ODYSSEY_DEVNET" "Name=tag:Role,Values=$ROLE_BASTION" \ | ||
--query "Reservations[].Instances[].PublicIpAddress" \ | ||
--output text) | ||
if [ -n "$INSTANCE_IP_ODYSSEY_DEVNET" ]; then | ||
echo "Odyssey DevNet Instance IP: $INSTANCE_IP_ODYSSEY_DEVNET" | ||
echo "instance_ip_odyssey_devnet=$INSTANCE_IP_ODYSSEY_DEVNET" >> $GITHUB_OUTPUT | ||
else | ||
echo "Failed to fetch DevNet IP or no instance found" | ||
fi | ||
else | ||
echo "DevNet unchanged, skipping IP fetch" | ||
fi | ||
# Fetch TestNet Bastion IP if changes are detected | ||
if [ "$TESTNET_CHANGED" = "true" ]; then | ||
echo "Fetching TestNet Bastion IP" | ||
INSTANCE_IP_ODYSSEY_TESTNET=$(aws ec2 describe-instances \ | ||
--region $INSTANCE_REGION \ | ||
--filters "Name=tag:Network,Values=$INSTANCE_NAME_ODYSSEY_TESTNET" "Name=tag:Role,Values=$ROLE_BASTION" \ | ||
--query "Reservations[].Instances[].PublicIpAddress" \ | ||
--output text) | ||
if [ -n "$INSTANCE_IP_ODYSSEY_TESTNET" ]; then | ||
echo "Odyssey TestNet Instance IP: $INSTANCE_IP_ODYSSEY_TESTNET" | ||
echo "instance_ip_odyssey_testnet=$INSTANCE_IP_ODYSSEY_TESTNET" >> $GITHUB_OUTPUT | ||
else | ||
echo "Failed to fetch TestNet IP or no instance found" | ||
fi | ||
else | ||
echo "TestNet unchanged, skipping IP fetch" | ||
fi | ||
# Display the fetched IPs (if any) | ||
if [ -n "$INSTANCE_IP_ODYSSEY_DEVNET" ]; then | ||
echo "Odyssey DevNet Instance IP: $INSTANCE_IP_ODYSSEY_DEVNET" | ||
fi | ||
if [ -n "$INSTANCE_IP_ODYSSEY_TESTNET" ]; then | ||
echo "Odyssey TestNet Instance IP: $INSTANCE_IP_ODYSSEY_TESTNET" | ||
fi |
This file contains 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,132 @@ | ||
name: Fetch Network Node IPs | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
role_to_assume: | ||
description: "The role to assume" | ||
required: true | ||
type: string | ||
aws_region: | ||
description: "The AWS region to use" | ||
required: true | ||
type: string | ||
devnet_changed: | ||
description: "Boolean to check if DevNet files have changed" | ||
required: true | ||
type: string | ||
testnet_changed: | ||
description: "Boolean to check if TestNet files have changed" | ||
required: true | ||
type: string | ||
network_odyssey_devnet: | ||
description: "The network name for Odyssey DevNet" | ||
required: true | ||
type: string | ||
network_odyssey_testnet: | ||
description: "The network name for Odyssey TestNet" | ||
required: true | ||
type: string | ||
aws_regions: | ||
description: "Comma-separated list of AWS regions" | ||
required: true | ||
type: string | ||
outputs: | ||
node_ips_odyssey_devnet: | ||
description: "The IP addresses for DevNet" | ||
value: ${{ jobs.fetch_network_node_ips.outputs.node_ips_odyssey_devnet }} | ||
node_ips_odyssey_testnet: | ||
description: "The IP addresses for TestNet" | ||
value: ${{ jobs.fetch_network_node_ips.outputs.node_ips_odyssey_testnet }} | ||
|
||
jobs: | ||
fetch_network_node_ips: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
node_ips_odyssey_devnet: ${{ steps.get_all_node_ips.outputs.node_ips_odyssey_devnet }} | ||
node_ips_odyssey_testnet: ${{ steps.get_all_node_ips.outputs.node_ips_odyssey_testnet }} | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5 | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
role-to-assume: ${{ inputs.role_to_assume }} | ||
aws-region: ${{ inputs.aws_region }} | ||
role-session-name: github-actions | ||
|
||
- name: Fetch All Network Node IPs, Regions, and SSH Users | ||
id: get_all_node_ips | ||
run: | | ||
DEVNET_CHANGED="${{ inputs.devnet_changed }}" | ||
TESTNET_CHANGED="${{ inputs.testnet_changed }}" | ||
NETWORK_ODYSSEY_DEVNET="${{ inputs.network_odyssey_devnet }}" | ||
NETWORK_ODYSSEY_TESTNET="${{ inputs.network_odyssey_testnet }}" | ||
# Convert the comma-separated regions into an array | ||
IFS=',' read -ra regions <<< "${{ inputs.aws_regions }}" | ||
pwd | ||
ls -la | ||
# Make the script executable | ||
chmod +x scripts/fetch_all_node_ips.sh | ||
if [ "$DEVNET_CHANGED" = "true" ]; then | ||
echo "Fetching DevNet Node IPs" | ||
DEVNET_NODE_IPS="" | ||
for region in "${regions[@]}"; do | ||
NODE_INFOS=$(./scripts/fetch_all_node_ips.sh "$NETWORK_ODYSSEY_DEVNET" "$region") | ||
if [ -n "$NODE_INFOS" ]; then | ||
# Append node infos to DEVNET_NODE_IPS, separated by semicolons | ||
while IFS= read -r line; do | ||
DEVNET_NODE_IPS+="${line};" | ||
done <<< "$NODE_INFOS" | ||
fi | ||
done | ||
# Remove trailing semicolon | ||
DEVNET_NODE_IPS="${DEVNET_NODE_IPS%?}" | ||
echo "node_ips_odyssey_devnet<<EOF" >> $GITHUB_OUTPUT | ||
echo "$DEVNET_NODE_IPS" >> $GITHUB_OUTPUT | ||
echo "EOF" >> $GITHUB_OUTPUT | ||
echo "Odyssey DevNet Node IPs: $DEVNET_NODE_IPS" | ||
else | ||
echo "DevNet unchanged, skipping Node IP fetch" | ||
fi | ||
if [ "$TESTNET_CHANGED" = "true" ]; then | ||
echo "Fetching TestNet Node IPs" | ||
TESTNET_NODE_IPS="" | ||
for region in "${regions[@]}"; do | ||
NODE_INFOS=$(./scripts/fetch_all_node_ips.sh "$NETWORK_ODYSSEY_TESTNET" "$region") | ||
if [ -n "$NODE_INFOS" ]; then | ||
# Append node infos to TESTNET_NODE_IPS, separated by semicolons | ||
while IFS= read -r line; do | ||
TESTNET_NODE_IPS+="${line};" | ||
done <<< "$NODE_INFOS" | ||
fi | ||
done | ||
# Remove trailing semicolon | ||
TESTNET_NODE_IPS="${TESTNET_NODE_IPS%?}" | ||
echo "node_ips_odyssey_testnet<<EOF" >> $GITHUB_OUTPUT | ||
echo "$TESTNET_NODE_IPS" >> $GITHUB_OUTPUT | ||
echo "EOF" >> $GITHUB_OUTPUT | ||
echo "Odyssey TestNet Node IPs: $TESTNET_NODE_IPS" | ||
else | ||
echo "TestNet unchanged, skipping Node IP fetch" | ||
fi | ||
# If both are false, output a message | ||
if [ "$DEVNET_CHANGED" = "false" ] && [ "$TESTNET_CHANGED" = "false" ]; then | ||
echo "No changes detected for either network, no Node IPs fetched" | ||
fi | ||
# Display the fetched Node IPs (if any) | ||
if [ -n "$DEVNET_NODE_IPS" ]; then | ||
echo "Odyssey DevNet Node IPs: $DEVNET_NODE_IPS" | ||
fi | ||
if [ -n "$TESTNET_NODE_IPS" ]; then | ||
echo "Odyssey TestNet Node IPs: $TESTNET_NODE_IPS" | ||
fi |
Oops, something went wrong.