-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·130 lines (100 loc) · 4.86 KB
/
setup.sh
File metadata and controls
executable file
·130 lines (100 loc) · 4.86 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env bash
set -o errexit # always exit on error
set -o pipefail # don't ignore exit codes when piping output
set -o nounset # fail on unset variables
#################################################################
# Script to setup a fully configured pipeline for Salesforce DX #
#################################################################
if [ "${1:-}" == "" ]; then
echo Usage: ./setup.sh "<github repo>" "<package name>" "<app name>" "<dev hub alias>" "[heroku team name]"
exit 0
fi
### Declare values
# Repository with your code
GITHUB_REPO=${1}
# Your package name
PACKAGE_NAME=${2}
# Descriptive name for the Heroku app
SFDX_APP_NAME=${3}
# Alias for your dev hub org
DEV_HUB_USERNAME=${4}
# Name of your team (optional)
HEROKU_TEAM_NAME=${5:-}
# Pipeline Names
HEROKU_PIPELINE_NAME="$SFDX_APP_NAME-pipeline"
#HEROKU_DEV_APP_NAME="$SFDX_APP_NAME-dev"
HEROKU_STAGING_APP_NAME="$SFDX_APP_NAME-staging"
HEROKU_PROD_APP_NAME="$SFDX_APP_NAME-prod"
### Setup
# Support a Heroku team
HEROKU_TEAM_FLAG=""
if [ ! "$HEROKU_TEAM_NAME" == "" ]; then
HEROKU_TEAM_FLAG="-t $HEROKU_TEAM_NAME"
fi
# Clean up script (in case something goes wrong)
echo "heroku pipelines:destroy $HEROKU_PIPELINE_NAME
#heroku apps:destroy -a $HEROKU_DEV_APP_NAME -c $HEROKU_DEV_APP_NAME
heroku apps:destroy -a $HEROKU_STAGING_APP_NAME -c $HEROKU_STAGING_APP_NAME
heroku apps:destroy -a $HEROKU_PROD_APP_NAME -c $HEROKU_PROD_APP_NAME
rm -- \"destroy$HEROKU_PIPELINE_NAME.sh\"" > destroy$HEROKU_PIPELINE_NAME.sh
echo ""
echo "Run ./destroy$HEROKU_PIPELINE_NAME.sh to remove resources"
echo ""
chmod +x "destroy$HEROKU_PIPELINE_NAME.sh"
# Create three Heroku apps to map to orgs
#heroku apps:create $HEROKU_DEV_APP_NAME $HEROKU_TEAM_FLAG
heroku apps:create $HEROKU_STAGING_APP_NAME $HEROKU_TEAM_FLAG
heroku apps:create $HEROKU_PROD_APP_NAME $HEROKU_TEAM_FLAG
# Turn on debug logging. TODO remove.
heroku config:set SFDX_BUILDPACK_DEBUG=true -a $HEROKU_STAGING_APP_NAME
heroku config:set SFDX_BUILDPACK_DEBUG=true -a $HEROKU_PROD_APP_NAME
# Setup sfdxUrl's for Dev Hub auth
devHubSfdxAuthUrl=$(sfdx force:org:display --verbose -u $DEV_HUB_USERNAME --json | jq -r .result.sfdxAuthUrl)
# Setup dev (parent for review apps)
#heroku config:set SFDX_DEV_HUB_AUTH_URL=$devHubSfdxAuthUrl -a $HEROKU_DEV_APP_NAME
#heroku config:set SFDX_SCRATCH_NAME="$SFDX_APP_NAME" -a $HEROKU_DEV_APP_NAME
#heroku config:set SFDX_PUSH_SOURCE=true -a $HEROKU_DEV_APP_NAME
# Setup staging
heroku config:set SFDX_DEV_HUB_AUTH_URL=$devHubSfdxAuthUrl -a $HEROKU_STAGING_APP_NAME
heroku config:set SFDX_CREATE_PACKAGE_VERSION=true -a $HEROKU_STAGING_APP_NAME
heroku config:set SFDX_PACKAGE_NAME="$PACKAGE_NAME" -a $HEROKU_STAGING_APP_NAME
# Setup prod
heroku config:set SFDX_DEV_HUB_AUTH_URL=$devHubSfdxAuthUrl -a $HEROKU_PROD_APP_NAME
heroku config:set SFDX_PROMOTE_PACKAGE_VERSION=true -a $HEROKU_PROD_APP_NAME
# Add buildpack to apps
heroku buildpacks:add -i 1 https://github.com/michaelhoefer/op-buildpack -a $HEROKU_PROD_APP_NAME
heroku buildpacks:add -i 1 https://github.com/michaelhoefer/op-buildpack -a $HEROKU_STAGING_APP_NAME
echo "Creating $HEROKU_PIPELINE_NAME ..."
# Create Pipeline
#heroku pipelines:create $HEROKU_PIPELINE_NAME -a $HEROKU_DEV_APP_NAME -s development $HEROKU_TEAM_FLAG
#heroku pipelines:add $HEROKU_PIPELINE_NAME -a $HEROKU_STAGING_APP_NAME -s staging
heroku pipelines:create $HEROKU_PIPELINE_NAME -a $HEROKU_STAGING_APP_NAME -s staging $HEROKU_TEAM_FLAG
heroku pipelines:add $HEROKU_PIPELINE_NAME -a $HEROKU_PROD_APP_NAME -s production
HEROKU_PIPELINE_ID=$(heroku pipelines --json | jq -r ".[] | select(.name == \"$HEROKU_PIPELINE_NAME\") | .id")
echo "Configuring CI "
heroku ci:config:set -p $HEROKU_PIPELINE_NAME SFDX_SCRATCH_NAME="$SFDX_APP_NAME"
heroku ci:config:set -p $HEROKU_PIPELINE_NAME SFDX_DEV_HUB_AUTH_URL=$devHubSfdxAuthUrl
heroku ci:config:set -p $HEROKU_PIPELINE_NAME SFDX_PUSH_SOURCE=true
heroku ci:config:set -p $HEROKU_PIPELINE_NAME SFDX_BUILDPACK_DEBUG=true
heroku ci:config -p $HEROKU_PIPELINE_NAME
exit 0
# Setup your pipeline
echo "Connecting github and enabling review apps"
heroku pipelines:connect $HEROKU_PIPELINE_NAME --repo $GITHUB_REPO
heroku reviewapps:enable -p $HEROKU_PIPELINE_NAME
curl -n -X PATCH https://api.heroku.com/pipelines/$HEROKU_PIPELINE_ID/review-app-config \
-d "{
\"repo\": \"$GITHUB_REPO\",
\"automatic_review_apps\": true,
\"wait_for_ci\": true,
\"destroy_stale_apps\": true,
\"stale_days\": 4,
\"base_name\": \"$SFDX_APP_NAME\"
}" -H "Content-Type: application/json" -H "Accept: application/vnd.heroku+json; version=3"
curl -n -X PATCH https://api.heroku.com/pipelines/$HEROKU_PIPELINE_ID/stage/review/config-vars \
-d "{
\"SFDX_DEV_HUB_AUTH_URL\": \"$devHubSfdxAuthUrl\",
\"SFDX_SCRATCH_NAME\": \"$SFDX_APP_NAME\",
\"SFDX_CREATE_SCRATCH_ORG\": \"true\",
\"SFDX_PUSH_SOURCE\": \"true\"
}" -H "Content-Type: application/json" -H "Accept: application/vnd.heroku+json; version=3"