|
| 1 | +name: update_connection |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + env_url: |
| 7 | + description: "Select source and target env's" |
| 8 | + type: choice |
| 9 | + default: "Source: SANDBOX, Target: PRODUCTION" |
| 10 | + options: |
| 11 | + - "Source: SANDBOX, Target: PRODUCTION" |
| 12 | + - "Source: SANDBOX, Target: SANDBOX" |
| 13 | + - "Source: PRODUCTION, Target: PRODUCTION" |
| 14 | + - "Source: PRODUCTION, Target: SANDBOX" |
| 15 | + source_connection_id: |
| 16 | + description: "Source Connection ID" |
| 17 | + required: false |
| 18 | + target_connection_id: |
| 19 | + description: "Target Connection ID" |
| 20 | + required: true |
| 21 | + source_account_access_token: |
| 22 | + description: "Access token of the Source Account" |
| 23 | + required: false |
| 24 | + target_account_access_token: |
| 25 | + description: "Access token of the Target Account" |
| 26 | + required: true |
| 27 | + source_account_id: |
| 28 | + description: "Source Account ID. If not provided, will use the repository variable" |
| 29 | + required: false |
| 30 | + target_account_id: |
| 31 | + description: "Target Account ID. If not provided, will use the repository variable" |
| 32 | + required: false |
| 33 | + |
| 34 | + |
| 35 | +jobs: |
| 36 | + execute-update-connection-script: |
| 37 | + runs-on: ubuntu-latest |
| 38 | + |
| 39 | + steps: |
| 40 | + - name: Checkout code |
| 41 | + uses: actions/checkout@v4 |
| 42 | + |
| 43 | + - name: Set up Python |
| 44 | + uses: actions/setup-python@v5 |
| 45 | + with: |
| 46 | + python-version: "3.x" |
| 47 | + |
| 48 | + - name: Install dependencies |
| 49 | + run: pip install requests |
| 50 | + |
| 51 | + - name: Parse and map environment URLs |
| 52 | + id: map_envs |
| 53 | + shell: bash |
| 54 | + run: | |
| 55 | + input="${{ github.event.inputs.env_url }}" |
| 56 | +
|
| 57 | + source_name=$(echo "$input" | sed -n 's/Source: \([^,]*\),.*/\1/p' | xargs) |
| 58 | + target_name=$(echo "$input" | sed -n 's/.*Target: \(.*\)/\1/p' | xargs) |
| 59 | +
|
| 60 | + get_env_url() { |
| 61 | + case "$1" in |
| 62 | + SANDBOX) echo "https://manage.skyflowapis-preview.com" ;; |
| 63 | + PRODUCTION) echo "https://manage.skyflowapis.com" ;; |
| 64 | + *) echo "Invalid environment: $1" >&2; exit 1 ;; |
| 65 | + esac |
| 66 | + } |
| 67 | +
|
| 68 | + # Resolve URLs |
| 69 | + source_url=$(get_env_url "$source_name") |
| 70 | + target_url=$(get_env_url "$target_name") |
| 71 | +
|
| 72 | + echo "source_url=$source_url" >> $GITHUB_OUTPUT |
| 73 | + echo "target_url=$target_url" >> $GITHUB_OUTPUT |
| 74 | +
|
| 75 | + - name: Run Python script |
| 76 | + env: |
| 77 | + SOURCE_CONNECTION_ID: ${{ github.event.inputs.source_connection_id }} |
| 78 | + TARGET_CONNECTION_ID: ${{ github.event.inputs.target_connection_id }} |
| 79 | + SOURCE_ACCOUNT_AUTH: ${{ github.event.inputs.source_account_access_token }} |
| 80 | + TARGET_ACCOUNT_AUTH: ${{ github.event.inputs.target_account_access_token }} |
| 81 | + SOURCE_ACCOUNT_ID: ${{ github.event.inputs.source_account_id != '' && github.event.inputs.source_account_id || vars.SOURCE_ACCOUNT_ID }} |
| 82 | + TARGET_ACCOUNT_ID: ${{ github.event.inputs.target_account_id != '' && github.event.inputs.target_account_id || vars.TARGET_ACCOUNT_ID }} |
| 83 | + SOURCE_ENV_URL: ${{ steps.map_envs.outputs.source_url }} |
| 84 | + TARGET_ENV_URL: ${{ steps.map_envs.outputs.target_url }} |
| 85 | + run: python3 update_connection.py |
0 commit comments