-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
135 lines (119 loc) · 4.8 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
128
129
130
131
132
133
134
135
---
name: 'GH Deployment from PlatformSH'
description: 'Creating a GitHub deployment if PlatformSH has deployed'
branding:
icon: 'box'
color: 'purple'
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
GH_DEPLOYMENT_TOKEN:
description: "PAT GH token, for deployment. Cannot be github.token."
required: true
type: string
PSH_DEPLOY_STATUS_PATH:
description: 'The location of the deploy-status file on the website.'
default: '/sites/default/files/deploy-status'
required: false
type: string
PSH_ACTIVITY_TYPES:
description: "Comma-seperated types of deployments to wait for. Default: push - See types here: https://docs.platform.sh/integrations/activity/reference.html#environment-activity-types"
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: 30 seconds."
default: 15
required: false
type: integer
BRANCH_NAME:
description: "Branch, which we will use to look"
required: true
type: string
USE_PULL_REQUESTS:
description: "If true, we will look up PSH environments based on PRs, rather than just the branch name. Default: 0"
default: 0
required: false
type: integer
outputs:
url:
description: "The ready-to-connect URL"
value: ${{ steps.platform_sh.outputs.url }}
deployment_id:
description: "The GH Deployment ID"
value: ${{ steps.deployment.outputs.deployment_id }}
deployment_status_id:
description: "The GH Deployment status ID"
value: ${{ steps.deployment_status_success.outputs.deployment_status_id }}
runs:
using: composite
steps:
- uses: actions/checkout@v3
- shell: bash
run: echo "ENVIRONMENT=${{ inputs.BRANCH_NAME }}" >> $GITHUB_ENV
- id: get_pr_environment
shell: bash
if: inputs.USE_PULL_REQUESTS == 1
run: |
PR_NUMBER="$(gh api "/repos/$OWNER/$REPO/pulls?head=$OWNER:$BRANCH" --jq '.[].number')"
echo "ENVIRONMENT=pr-$PR_NUMBER" >> $GITHUB_ENV
env:
GH_TOKEN: ${{ inputs.GH_DEPLOYMENT_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
BRANCH: ${{ inputs.BRANCH_NAME }}
- id: deployment
shell: bash
name: Create GH Deployment
run: |
DEPLOYMENT_ID=$(echo '{
"ref": "${{ inputs.BRANCH_NAME }}",
"environment": "${{ env.ENVIRONMENT }}",
"auto_merge": false,
"required_contexts": []
}' | gh api --method POST "/repos/$OWNER/$REPO/deployments" \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
--input - --jq '.id')
echo "deployment_id=$DEPLOYMENT_ID" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ inputs.GH_DEPLOYMENT_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
- id: deployment_status_fail
shell: bash
if: github.event.state == 'error' || github.event.state == 'failure'
run: |
STATUS_ID="$(gh api --method POST "/repos/$OWNER/$REPO/deployments/${{ steps.deployment.outputs.deployment_id }}/statuses" -f "state=failure" --jq '.id')"
echo "deployment_status_id=$STATUS_ID" >> $GITHUB_OUTPUT
exit 1
env:
GH_TOKEN: ${{ inputs.GH_DEPLOYMENT_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
- uses: reload/action-platformsh-deploy-status@main
id: platform_sh
with:
PLATFORMSH_ID: ${{ inputs.PLATFORMSH_ID }}
PLATFORMSH_KEY: ${{ inputs.PLATFORMSH_KEY }}
PSH_DETECTION_WAIT: ${{ inputs.PSH_DETECTION_WAIT }}
DEPLOY_STATUS_PATH: ${{ inputs.PSH_DEPLOY_STATUS_PATH }}
ACTIVITY_TYPES: ${{ inputs.PSH_ACTIVITY_TYPES }}
ENVIRONMENT_NAME: ${{ env.ENVIRONMENT }}
ALLOW_CANCEL_CRON: 0
- id: deployment_status_success
if: always()
shell: bash
run: |
STATUS_ID="$(gh api --method POST "/repos/$OWNER/$REPO/deployments/${{ steps.deployment.outputs.deployment_id }}/statuses" -f "state=${{ steps.platform_sh.outputs.state }}" -f "description=${{ steps.platform_sh.outputs.state_description }}" -f "target_url=${{ steps.platform_sh.outputs.url }}" --jq '.id')"
echo "deployment_status_id=$STATUS_ID" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ inputs.GH_DEPLOYMENT_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}