-
Notifications
You must be signed in to change notification settings - Fork 2
/
action.yml
127 lines (99 loc) · 4.33 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
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
---
name: "Platform.sh - Get Environment URL"
description: "Detecting if PlatformSH is building an environment, and returning the URL when it's done deploying."
branding:
icon: "download-cloud"
color: "blue"
inputs:
PLATFORMSH_KEY:
description: "API key for connecting to Platform.sh"
required: true
type: string
PLATFORMSH_ID:
description: "ID for the Platform.sh project."
required: true
type: string
ALLOW_CANCEL_CRON:
description: "Can we cancel on-going crons, to speed up deployment? default: 0"
default: 0
required: false
type: integer
ENVIRONMENT_NAME:
description: "Which environment to check against - defaults to pr-NUMBER"
default: "pr-${{ github.event.pull_request.number }}"
required: false
type: string
ACTIVITY_TYPES:
description: "Types of deployments to wait for. Default: push - See types here: https://docs.platform.sh/integrations/activity/reference.html#type"
default: "push"
required: true
type: string
PSH_DETECTION_WAIT:
description: "How long should we maximum wait for PSH to detect the push? If the branch doesnt exist in the PlatformSH GIT Remote, this is how long the action will take. Actually inactive environments get detected instantly."
default: 10
required: false
type: integer
outputs:
url:
description: "The ready-to-connect URL"
value: ${{ steps.platformsh_url.outputs.url }}
runs:
using: "composite"
steps:
- name: Get PlatformSH URL
shell: bash
id: platformsh_url
run: |
set +e
sleep 5s
export PLATFORMSH_CLI_NO_INTERACTION=1;
export PLATFORM_PROJECT=${{ inputs.PLATFORMSH_ID }};
export PLATFORM_BRANCH=${{ inputs.ENVIRONMENT_NAME }};
export PLATFORMSH_CLI_TOKEN=${{ inputs.PLATFORMSH_KEY }};
curl -fsSL https://raw.githubusercontent.com/platformsh/cli/main/installer.sh | bash
export PATH="/home/runner/.local/bin:{$PATH}"
if [[ "${{ inputs.ALLOW_CANCEL_CRON }}" == 1 ]]; then \
platform activity:cancel --type=environment.cron; \
fi
DETECTION_TRIES=0
TRIES=0
SUCCESS=0
DELAY_BETWEEN_ATTEMPTS=5;
DETECTION_SECONDS=${{ inputs.PSH_DETECTION_WAIT }};
MAX_WAIT_SECONDS=900;
echo "We will wait $DETECTION_SECONDS secs for PSH to detect a deploy, and a max of $MAX_WAIT_SECONDS secs for any deployment to finish."
sleep $DETECTION_SECONDS;
MAX_TRIES=$(( MAX_WAIT_SECONDS / DELAY_BETWEEN_ATTEMPTS ));
echo "We will now detect the PSH activities. You can view the deployment log using";
echo " platform activity:log [ID] -p ${{ inputs.PLATFORMSH_ID }} -e ${{ inputs.ENVIRONMENT_NAME }}";
echo "----------------------";
echo "";
while [ $TRIES -le $MAX_TRIES ]; do \
TRIES=$((TRIES+1)); \
ACTS=$(platform activities --format=plain --columns=id,state --incomplete --no-header --no-interaction --type=${{ inputs.ACTIVITY_TYPES }} 2>&1 || true); \
echo "$ACTS"; \
echo "----------------------"; \
if [[ "$ACTS" =~ "Exception]" ]]; then SUCCESS=0; break; fi; \
if [[ "$ACTS" =~ "No activities found" ]]; then SUCCESS=1; break; fi; \
echo "total tries: $TRIES / $MAX_TRIES"; \
sleep $DELAY_BETWEEN_ATTEMPTS; \
done
echo ""
STATUS=$(platform env:info status 2>&1 || true)
if [[ "$STATUS" =~ "inactive" ]]; then \
echo "PlatformSH reports that the environment is not active. This might be because you have run out of available environment slots. Try to run 'platform env:activate -e ${{ inputs.ENVIRONMENT_NAME }} -p ${{ inputs.PLATFORMSH_ID }}'"; \
exit 2; \
elif [[ "$SUCCESS" == 0 ]]; then \
echo "$STATUS"; \
exit 2; \
fi
URL=$(platform env:url -1 --pipe)
CURL_HTTP_STATUS=$(curl -L -s -o /dev/null -w "%{http_code}" $URL)
if [[ "$CURL_HTTP_STATUS" != "200" ]]; then \
echo "PlatformSH reports the environment is ready, but cURL could not connect to it. You may have pushed a broken build."; \
echo "URL: $URL"; \
echo "HTTP Status Code: $CURL_HTTP_STATUS"; \
exit 2; \
fi
echo "url=$URL" >> $GITHUB_OUTPUT
echo "$URL is active - you can use it as $ {{ [..].outputs.url }}"; \