-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
97 lines (83 loc) · 3.53 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
name: 'Save Org to GitHub Environment'
description: 'Collects Salesforce org info and 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
env:
GITHUB_TOKEN: ${{ github.env.GH_TOKEN }}
run: |
set -e
echo "Starting org info collection..."
echo "Using GH_TOKEN: ${GH_TOKEN}"
# Get org info
ORG_INFO=$(cci org info ${{ inputs.org-alias }} --json)
echo "Org info retrieved successfully."
# Function to safely extract JSON values
safe_extract() {
echo "$ORG_INFO" | jq -r ".$1 | if type==\"string\" then . else \"\" end" || echo ""
}
# Extract information
ORG_NAME=$(safe_extract "org_name")
INSTANCE_URL=$(safe_extract "instance_url")
USERNAME=$(safe_extract "username")
SFDX_ALIAS=$(safe_extract "sfdx_alias")
ORG_ID=$(safe_extract "org_id")
ORG_TYPE=$(safe_extract "org_type")
SCRATCH=$(safe_extract "scratch")
echo "Information extracted successfully."
echo "ORG_NAME: ${ORG_NAME}"
echo "INSTANCE_URL: ${INSTANCE_URL}"
echo "USERNAME: ${USERNAME}"
echo "SFDX_ALIAS: ${USERNAME}"
# Set 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
echo "Creating/updating GitHub environment..."
# Get SFDX auth URL (sensitive)
sf org list
sf org display --target-org "${USERNAME}"
SFDX_AUTH_URL=$(sf org display --json --verbose --target-org "${USERNAME}" | jq -r '.result.sfdxAuthUrl')
# Create or update environment
gh api -X PUT /repos/${{ github.repository }}/environments/${{ inputs.environment-name }}
# Set environment variables
set_env_var() {
gh api -X PUT /repos/${{ github.repository }}/environments/${{ inputs.environment-name }}/variables/$1 \
-f name="$1" -f value="$2"
}
set_env_var "INSTANCE_URL" "${INSTANCE_URL}"
set_env_var "USERNAME" "${USERNAME}"
set_env_var "SFDX_ALIAS" "${SFDX_ALIAS}"
set_env_var "ORG_ID" "${ORG_ID}"
set_env_var "ORG_TYPE" "${ORG_TYPE}"
set_env_var "SCRATCH" "${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