-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yaml
More file actions
196 lines (179 loc) · 6.98 KB
/
Copy pathaction.yaml
File metadata and controls
196 lines (179 loc) · 6.98 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
name: Plan Tailor Platform Changes
description: >-
Show planned changes by running dry-run against the target workspace.
Merges base branch and runs tailor-sdk apply --dry-run, then comments the result on the PR.
Requires Node.js and dependencies to be installed by the caller.
inputs:
workspace-id:
description: >-
Tailor Platform workspace ID to run dry-run against.
Set this from a GitHub Environment variable (e.g. vars.TAILOR_PLATFORM_WORKSPACE_ID).
When empty, the action reports "not yet provisioned" and exits successfully —
this covers the chicken-and-egg case where a workspace does not exist before the first deploy.
required: false
default: ""
label:
description: >-
Human-readable label for this workspace (e.g. the workspace name).
Used only for the PR comment marker and heading.
When omitted, the comment marker falls back to workspace-id, then "workspace".
required: false
working-directory:
description: Working directory for the project (for monorepo setups)
required: false
default: "."
package-manager:
description: >-
Package manager used to run tailor-sdk (pnpm, npm, yarn, or bun).
Defaults to npx when empty, so Bun uses its own runtime instead of
relying on an ambient Node, and the locally-installed version is used.
required: false
default: ""
platform-client-id:
description: OAuth2 client ID for Tailor Platform machine user
required: true
platform-client-secret:
description: OAuth2 client secret for Tailor Platform machine user
required: true
github-token:
description: >-
GitHub token for commenting on PR.
When omitted, no PR comment is posted (step summary only).
required: false
outputs:
workspace-id:
description: Tailor Platform workspace ID
value: ${{ inputs.workspace-id }}
exit-code:
description: Exit code of the dry-run (empty when skipped)
value: ${{ steps.dry-run.outputs.exit-code }}
runs:
using: composite
steps:
- name: Set up Tailor SDK
if: inputs.workspace-id != ''
uses: tailor-platform/actions/_internal/sdk-setup@d203a37c87b7a69c6040611c33e9e50c1d564ed1
with:
platform-client-id: ${{ inputs.platform-client-id }}
platform-client-secret: ${{ inputs.platform-client-secret }}
package-manager: ${{ inputs.package-manager }}
working-directory: ${{ inputs.working-directory }}
- name: Merge base branch
if: inputs.workspace-id != '' && github.event_name == 'pull_request'
shell: bash
env:
BASE_REF: ${{ github.base_ref }}
run: |
git fetch origin "$BASE_REF"
git merge --no-commit --no-ff "origin/$BASE_REF" || true
- name: Run dry-run
id: dry-run
if: inputs.workspace-id != ''
shell: bash
working-directory: ${{ inputs.working-directory }}
env:
TAILOR_PLATFORM_WORKSPACE_ID: ${{ inputs.workspace-id }}
run: |
set +e
OUTPUT=$($TAILOR_SDK_RUN tailor-sdk apply --dry-run --yes 2>&1)
EXIT_CODE=$?
set -e
echo "exit-code=$EXIT_CODE" >> "$GITHUB_OUTPUT"
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "output<<$EOF" >> "$GITHUB_OUTPUT"
echo "$OUTPUT" >> "$GITHUB_OUTPUT"
echo "$EOF" >> "$GITHUB_OUTPUT"
- name: Write step summary (not provisioned)
if: inputs.workspace-id == ''
shell: bash
env:
LABEL: ${{ inputs.label }}
run: |
if [ -n "$LABEL" ]; then KEY="$LABEL"; else KEY="workspace"; fi
{
echo "### ⏭️ Tailor Platform Plan ($KEY)"
echo ""
echo "Workspace is not yet provisioned — run deploy first to create it."
} >> "$GITHUB_STEP_SUMMARY"
- name: Write step summary
if: inputs.workspace-id != ''
shell: bash
env:
WORKSPACE_ID: ${{ inputs.workspace-id }}
LABEL: ${{ inputs.label }}
DRY_RUN_OUTPUT: ${{ steps.dry-run.outputs.output }}
DRY_RUN_EXIT_CODE: ${{ steps.dry-run.outputs.exit-code }}
run: |
# Compute the display key: label > workspace-id > "workspace"
if [ -n "$LABEL" ]; then
KEY="$LABEL"
elif [ -n "$WORKSPACE_ID" ]; then
KEY="$WORKSPACE_ID"
else
KEY="workspace"
fi
if [ "$DRY_RUN_EXIT_CODE" = "0" ]; then
STATUS="✅"
else
STATUS="❌"
fi
{
echo "### $STATUS Tailor Platform Plan ($KEY)"
echo ""
echo "<details>"
echo "<summary>Plan output (exit code: $DRY_RUN_EXIT_CODE)</summary>"
echo ""
echo '```'
echo "$DRY_RUN_OUTPUT"
echo '```'
echo ""
echo "</details>"
} >> "$GITHUB_STEP_SUMMARY"
- name: Build plan comment body
id: comment-body
if: inputs.workspace-id != '' && github.event_name == 'pull_request' && inputs.github-token != ''
shell: bash
env:
WORKSPACE_ID: ${{ inputs.workspace-id }}
LABEL: ${{ inputs.label }}
DRY_RUN_OUTPUT: ${{ steps.dry-run.outputs.output }}
DRY_RUN_EXIT_CODE: ${{ steps.dry-run.outputs.exit-code }}
run: |
if [ -n "$LABEL" ]; then KEY="$LABEL"
elif [ -n "$WORKSPACE_ID" ]; then KEY="$WORKSPACE_ID"
else KEY="workspace"
fi
MARKER="<!-- tailor-plan: $KEY -->"
echo "marker=$MARKER" >> "$GITHUB_OUTPUT"
if [ "$DRY_RUN_EXIT_CODE" = "0" ]; then STATUS="✅"; else STATUS="❌"; fi
OUTPUT="$DRY_RUN_OUTPUT"
MAX_OUTPUT=60000
if [ "${#OUTPUT}" -gt "$MAX_OUTPUT" ]; then
NOTE=$(printf '[output truncated to the last %s characters — see the job'\''s step summary for the full plan]' "$MAX_OUTPUT")
OUTPUT=$(printf '%s\n\n%s' "$NOTE" "${OUTPUT: -$MAX_OUTPUT}")
fi
CONTENT=$(printf '### %s Tailor Platform Plan (%s)\n\n<details>\n<summary>Plan output (exit code: %s)</summary>\n\n```\n%s\n```\n\n</details>' \
"$STATUS" "$KEY" "$DRY_RUN_EXIT_CODE" "$OUTPUT")
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
{
echo "body<<$EOF"
printf '%s\n%s\n' "$MARKER" "$CONTENT"
echo "$EOF"
} >> "$GITHUB_OUTPUT"
- name: Post sticky plan comment
if: inputs.workspace-id != '' && github.event_name == 'pull_request' && inputs.github-token != ''
uses: tailor-platform/actions/_internal/sticky-comment@d203a37c87b7a69c6040611c33e9e50c1d564ed1
with:
marker-prefix: ${{ steps.comment-body.outputs.marker }}
body: ${{ steps.comment-body.outputs.body }}
github-token: ${{ inputs.github-token }}
- name: Fail on plan error
if: inputs.workspace-id != ''
shell: bash
env:
DRY_RUN_EXIT_CODE: ${{ steps.dry-run.outputs.exit-code }}
run: |
if [ "$DRY_RUN_EXIT_CODE" != "0" ]; then
echo "::error::Plan dry-run failed with exit code $DRY_RUN_EXIT_CODE"
exit "$DRY_RUN_EXIT_CODE"
fi