Sandbox Resume Creation #4
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
name: Sandbox Resume Creation | |
on: | |
workflow_dispatch: | |
inputs: | |
sandboxName: | |
description: Name of the sandbox to have the creation resumed | |
type: string | |
required: true | |
wait: | |
description: Wait time for sandbox creation - if process still didn't finalize | |
default: 30 | |
type: string | |
email: | |
description: Email for the Sys Admin user | |
type: string | |
required: true | |
ref: | |
description: Reference that will be checkout to support post creation steps | |
type: string | |
required: true | |
buildfile: | |
description: Path to the buildfile.json configured to run after sandbox creation - to automate post creation steps | |
type: string | |
required: false | |
connectedApp: | |
description: API name for the connected app to be retrieved so the consumer key can be logged directly on the job - this is just used to facilitate the pipeline configuration if there sandbox needs to be connected by the CI server | |
type: string | |
required: false | |
defaultDirectory: | |
description: Defatul directory as per sfdx-project.json - to be used to log the connected app consumer key | |
type: string | |
default: force-app | |
required: false | |
# Jobs to be executed | |
jobs: | |
sandbox-creation-resume: | |
runs-on: ubuntu-latest | |
container: tnascimento013/latam_salesforcedx_industries_orgdevmodebuilds:latest | |
environment: prod | |
steps: | |
- name: Set Directory as Safe | |
run: git config --system --add safe.directory "$GITHUB_WORKSPACE" | |
- name: "Checkout source code" | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ inputs.ref }} | |
- name: Extracting private key | |
run: 'echo "${{ secrets.JWT_KEY_PROD }}" > server.key' | |
- name: Authenticate on production | |
run: sf org login jwt --instance-url https://login.salesforce.com --client-id ${{ vars.CLIENT_ID }} --username ${{ vars.USERNAME }} --jwt-key-file server.key --alias prodOrg | |
- name: Resume sandbox creation process | |
run: sf org resume sandbox --name ${{ inputs.sandboxName }} --target-org prodOrg --wait ${{ inputs.wait }} | |
- name: Getting credential for user creation | |
id: credential | |
run: echo "ACCESS_TOKEN=$(sf org display --target-org ${{ vars.USERNAME }}.${{ inputs.sandboxName }} | grep -Po '(?<=Access Token\s\s\s\s\s).*')" | |
- name: Getting instance url for user creation | |
id: instanceUrl | |
run: echo "INSTANCE_URL=$(sf org display --target-org ${{ vars.USERNAME }}.${{ inputs.sandboxName }} | grep -Po '(?<=Instance Url\s\s\s\s\s).*')" | |
- name: Create SysAdmin user | |
run: | | |
echo ${{ steps.credential.outputs.ACCESS_TOKEN }} | |
echo ${{ steps.instanceUrl.outputs.INSTANCE_URL }} | |
- name: Post creation steps | |
if: github.event.inputs.buildfile != '' | |
run: | | |
export HOME=/root | |
sf builds deploy --buildfile ${{ inputs.buildfile }} --target-org sdbxSysAdmin | |
- name: Retrieving Connected App Consumer Key | |
if: github.event.inputs.connectedApp != '' | |
run: | | |
sf project retrieve start --metadata=ConnectedApp:${{ inputs.connectedApp }} --target-org sdbxSysAdmin | |
cat ${{ inputs.defaultDirectory }}/main/default/connectedApps/${{ inputs.connectedApp }}.connectedApp-meta.xml | grep consumerKey |