Skip to content

Commit

Permalink
Create action.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
jlantz authored Oct 20, 2024
0 parents commit fd3e1df
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions action.yml
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 }}

0 comments on commit fd3e1df

Please sign in to comment.