-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit fd3e1df
Showing
1 changed file
with
79 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,79 @@ | ||
name: 'Save Org to GitHub Environment' | ||
description: 'Collects Salesforce org info and optionally saves it as a GitHub environment' | ||
inputs: | ||
org-alias: | ||
description: 'Alias of the Salesforce org' | ||
required: true | ||
create-environment: | ||
description: 'Whether to create a new GitHub environment' | ||
required: false | ||
default: 'false' | ||
environment-name: | ||
description: 'Name of the GitHub environment to create' | ||
required: false | ||
default: '' | ||
outputs: | ||
org_name: | ||
description: 'Name of the Salesforce org' | ||
value: ${{ steps.process-org-info.outputs.org_name }} | ||
instance_url: | ||
description: 'Instance URL of the Salesforce org' | ||
value: ${{ steps.process-org-info.outputs.instance_url }} | ||
username: | ||
description: 'Username of the Salesforce org' | ||
value: ${{ steps.process-org-info.outputs.username }} | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Get and Process Org Info | ||
id: process-org-info | ||
shell: bash | ||
run: | | ||
# Get org info | ||
ORG_INFO=$(cci org info ${{ inputs.org-alias }} --json) | ||
# Extract non-sensitive information | ||
ORG_NAME=$(echo $ORG_INFO | jq -r '.org_name') | ||
INSTANCE_URL=$(echo $ORG_INFO | jq -r '.instance_url') | ||
USERNAME=$(echo $ORG_INFO | jq -r '.username') | ||
SFDX_ALIAS=$(echo $ORG_INFO | jq -r `'.sfdx_alias') | ||
ORG_ID=$(echo $ORG_INFO | jq -r '.org_id') | ||
ORG_TYPE=$(echo $ORG_INFO | jq -r '.org_type') | ||
SCRATCH=$(echo $ORG_INFO | jq -r '.scratch') | ||
# Set non-sensitive outputs | ||
echo "org_name=${ORG_NAME}" >> $GITHUB_OUTPUT | ||
echo "instance_url=${INSTANCE_URL}" >> $GITHUB_OUTPUT | ||
echo "username=${USERNAME}" >> $GITHUB_OUTPUT | ||
if [[ "${{ inputs.create-environment }}" == "true" && -n "${{ inputs.environment-name }}" ]]; then | ||
# Get SFDX auth URL (sensitive) | ||
SFDX_AUTH_URL=$(sf org display --json --verbose -o $SFDX_ALIAS | jq -r '.result.sfdxAuthUrl') | ||
# Create or update environment | ||
gh api -X PUT /repos/${{ github.repository }}/environments/${{ inputs.environment-name }} \ | ||
-f environment_name="${{ inputs.environment-name }}" \ | ||
-f wait_timer=0 | ||
# Set environment variables | ||
gh api -X PUT /repos/${{ github.repository }}/environments/${{ inputs.environment-name }}/variables/INSTANCE_URL \ | ||
-f name="INSTANCE_URL" -f value="${INSTANCE_URL}" | ||
gh api -X PUT /repos/${{ github.repository }}/environments/${{ inputs.environment-name }}/variables/USERNAME \ | ||
-f name="USERNAME" -f value="${USERNAME}" | ||
gh api -X PUT /repos/${{ github.repository }}/environments/${{ inputs.environment-name }}/variables/SFDX_ALIAS \ | ||
-f name="SFDX_ALIAS" -f value="${SFDX_ALIAS}" | ||
gh api -X PUT /repos/${{ github.repository }}/environments/${{ inputs.environment-name }}/variables/ORG_ID \ | ||
-f name="ORG_ID" -f value="${ORG_ID}" | ||
gh api -X PUT /repos/${{ github.repository }}/environments/${{ inputs.environment-name }}/variables/ORG_TYPE \ | ||
-f name="ORG_TYPE" -f value="${ORG_TYPE}" | ||
gh api -X PUT /repos/${{ github.repository }}/environments/${{ inputs.environment-name }}/variables/SCRATCH \ | ||
-f name="SCRATCH" -f value="${SCRATCH}" | ||
# Set secret | ||
gh secret set SFDX_AUTH_URL -b"${SFDX_AUTH_URL}" --env "${{ inputs.environment-name }}" | ||
echo "Environment '${{ inputs.environment-name }}' created/updated with necessary variables and secrets." | ||
fi | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} |