Last active
September 2, 2025 03:39
-
-
Save shazron/88a1c2794584d7a834b8447a92f88989 to your computer and use it in GitHub Desktop.
Improved version of https://developer.adobe.com/app-builder/docs/guides/app_builder_guides/deployment/cicd-using-github-actions
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
| #!/bin/bash | |
| main (){ | |
| # Check if jq is available | |
| if ! command -v jq &> /dev/null; then | |
| echo "Error: jq is not installed. Please install jq to use this script." >&2 | |
| echo "" >&2 | |
| echo "Installation instructions:" >&2 | |
| echo " macOS: brew install jq" >&2 | |
| echo " Ubuntu/Debian: sudo apt-get install jq" >&2 | |
| echo " CentOS/RHEL: sudo yum install jq" >&2 | |
| echo " Or download from: https://stedolan.github.io/jq/download/" >&2 | |
| exit 1 | |
| fi | |
| # Parse command line argument for output file | |
| output_file="$1" | |
| config=$(aio config ls --json) | |
| # Extract workspace_services | |
| workspace_services=$(echo "$config" | jq -c '.project.workspace.details.services') | |
| # Check if I/O Management API is present | |
| if ! echo "$workspace_services" | jq -e 'any(.[]; .code == "AdobeIOManagementAPISDK")' > /dev/null; then | |
| echo "Error: I/O Management API was not found in your workspace." >&2 | |
| exit 1 | |
| fi | |
| # Get the lowercase context name | |
| ctx=$(echo "$config" \ | |
| | jq -r '.project.workspace.details.credentials[] | select(.integration_type == "oauth_server_to_server") | .name' \ | |
| | tr '[:upper:]' '[:lower:]' | |
| ) | |
| # Get workspace name and determine suffix | |
| workspace_name=$(echo "$config" | jq -r '.project.workspace.name') | |
| if [ "$workspace_name" = "Production" ]; then | |
| suffix="_PROD" | |
| else | |
| suffix="_STAGE" | |
| fi | |
| # Function to output env variables | |
| output_env() { | |
| echo "CLIENTID${suffix}=$(echo "$config" | jq -r --arg ctx "$ctx" '.ims.contexts[$ctx].client_id')" | |
| echo "CLIENTSECRET${suffix}=$(echo "$config" | jq --arg ctx "$ctx" '.ims.contexts[$ctx].client_secrets' | jq -r | jq -r '.[0]')" | |
| echo "TECHNICALACCID${suffix}=$(echo "$config" | jq -r --arg ctx "$ctx" '.ims.contexts[$ctx].technical_account_id')" | |
| echo "TECHNICALACCEMAIL${suffix}=$(echo "$config" | jq -r --arg ctx "$ctx" '.ims.contexts[$ctx].technical_account_email')" | |
| echo "IMSORGID${suffix}=$(echo "$config" | jq -r --arg ctx "$ctx" '.ims.contexts[$ctx].ims_org_id')" | |
| echo "SCOPES${suffix}=$(echo "$config" | jq --arg ctx "$ctx" '.ims.contexts[$ctx].scopes' | jq -r | jq -r '. | join(",")')" | |
| echo "AIO_RUNTIME_NAMESPACE${suffix}=$(echo "$config" | jq -r '.runtime.namespace')" | |
| echo "AIO_RUNTIME_AUTH${suffix}=$(echo "$config" | jq -r '.runtime.auth')" | |
| echo "AIO_PROJECT_ID${suffix}=$(echo "$config" | jq -r '.project.id')" | |
| echo "AIO_PROJECT_NAME${suffix}=$(echo "$config" | jq -r '.project.name')" | |
| echo "AIO_PROJECT_ORG_ID${suffix}=$(echo "$config" | jq -r '.project.org.id')" | |
| echo "AIO_PROJECT_WORKSPACE_ID${suffix}=$(echo "$config" | jq -r '.project.workspace.id')" | |
| echo "AIO_PROJECT_WORKSPACE_NAME${suffix}=$(echo "$config" | jq -r '.project.workspace.name')" | |
| echo "AIO_PROJECT_WORKSPACE_DETAILS_SERVICES${suffix}=$(echo "$config" | jq -r -c '.project.workspace.details.services')" | |
| } | |
| # Output to file or stdout | |
| if [ -n "$output_file" ]; then | |
| output_env > "$output_file" | |
| echo "Environment variables written to $output_file" >&2 | |
| echo "" >&2 | |
| echo "To upload these secrets to a GitHub repository, use:" >&2 | |
| echo " gh secret set -f $output_file" >&2 | |
| echo "" >&2 | |
| echo "Make sure you have the GitHub CLI installed and are authenticated before running the command." >&2 | |
| else | |
| output_env | |
| echo "" >&2 | |
| echo "To upload these secrets to a GitHub repository:" >&2 | |
| echo " 1. Copy and paste the above output into a file (e.g., secrets.env)" >&2 | |
| echo " 2. Run: gh secret set -f YOUR_ENV_FILE_NAME" >&2 | |
| echo "" >&2 | |
| echo "Make sure you have the GitHub CLI installed and are authenticated before running the command." >&2 | |
| fi | |
| } | |
| main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://developer.adobe.com/app-builder/docs/guides/app_builder_guides/deployment/cicd-using-github-actions
This will output the secrets in a dotenv format (depending on Production or non-prod). You can then use the Github CLI to upload the secrets to your repo via
gh secret set -f YOUR_ENV_FILE_HERE.env