-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathdeploy-on-release-to-instawp.yml
More file actions
133 lines (114 loc) · 4.74 KB
/
Copy pathdeploy-on-release-to-instawp.yml
File metadata and controls
133 lines (114 loc) · 4.74 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
name: Deploy to InstaWP
on:
workflow_run:
workflows: ["Build Accessibility Checker Plugin with Ref Param"]
types: [completed]
workflow_dispatch:
inputs:
plugin_zip_path:
description: 'Path to the plugin zip file to deploy. Must be a zip file.'
required: true
type: string
permissions:
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
if: |
github.event_name == 'workflow_dispatch' ||
(
github.event_name == 'workflow_run' &&
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'release'
)
steps:
- name: Get release assets
id: get_release_assets
if: github.event_name == 'workflow_run'
run: |
RELEASES_URL="https://api.github.com/repos/${{ github.repository }}/releases"
echo "Fetching releases from: $RELEASES_URL"
RELEASE=$(curl -s \
-H "Authorization: token ${{ github.token }}" \
-H "Accept: application/vnd.github.v3+json" \
"$RELEASES_URL?per_page=5" | jq -c '[.[] | select(.draft == false)][0]')
if [[ -z "$RELEASE" || "$RELEASE" == "null" ]]; then
echo "No published release found."
exit 1
fi
RELEASE_TAG=$(echo "$RELEASE" | jq -r '.tag_name')
echo "Using release tag: $RELEASE_TAG"
# Pick the non-woocommerce zip only.
ZIP_URL=$(echo "$RELEASE" | jq -r '.assets[]
| select(.name | test("^accessibility-checker.*\\.zip$"))
| select(.name | test("-ref-woocommerce-") | not)
| .browser_download_url' | head -n 1)
if [[ -z "$ZIP_URL" ]]; then
echo "No non-woocommerce accessibility-checker zip file found in release assets."
exit 1
fi
echo "Found non-woocommerce accessibility-checker zip file: $ZIP_URL"
echo "zip_url=$ZIP_URL" >> $GITHUB_OUTPUT
- name: Download and validate plugin zip file
id: validate_zip
run: |
# Determine the ZIP_URL based on the trigger
if [[ "${{ github.event_name }}" == "workflow_run" ]]; then
ZIP_URL="${{ steps.get_release_assets.outputs.zip_url }}"
else
ZIP_URL="${{ github.event.inputs.plugin_zip_path }}"
fi
echo "Using ZIP_URL: $ZIP_URL"
ZIP_NAME=$(basename "$ZIP_URL")
curl -L "$ZIP_URL" -o "$ZIP_NAME"
if [ ! -f "$ZIP_NAME" ]; then
echo "File does not exist: $ZIP_NAME"
exit 1
fi
if [[ "$ZIP_NAME" != *.zip ]]; then
echo "File does not have .zip extension: $ZIP_NAME"
exit 1
fi
MIME_TYPE=$(file --mime-type -b "$ZIP_NAME")
if [ "$MIME_TYPE" != "application/zip" ]; then
echo "File is not a valid zip archive: $ZIP_NAME (type: $MIME_TYPE)"
exit 1
fi
# Save the ZIP_URL for the deploy step
echo "zip_url=$ZIP_URL" >> $GITHUB_OUTPUT
- name: Deploy to InstaWP
run: |
API_KEY=${{ secrets.INSTAWP_API_KEY }}
SITE_ID_MAIN=${{ secrets.INSTAWP_SITE_ID_MAIN }}
SITE_ID_ARCHIVEWP=${{ secrets.INSTAWP_SITE_ID_ARCHIVEWP }}
if [[ -z "$API_KEY" || -z "$SITE_ID_MAIN" || -z "$SITE_ID_ARCHIVEWP" ]]; then
echo "Required InstaWP secrets are missing. Set INSTAWP_API_KEY, INSTAWP_SITE_ID_MAIN, and INSTAWP_SITE_ID_ARCHIVEWP."
exit 1
fi
# Determine the PLUGIN_URL based on the trigger
if [[ "${{ github.event_name }}" == "workflow_run" ]]; then
PLUGIN_URL="${{ steps.get_release_assets.outputs.zip_url }}"
else
PLUGIN_URL="${{ github.event.inputs.plugin_zip_path }}"
fi
echo "Deploying plugin from: $PLUGIN_URL"
for SITE_ID in "$SITE_ID_MAIN" "$SITE_ID_ARCHIVEWP"; do
echo "Deploying to InstaWP site ID: $SITE_ID"
HTTP_CODE=$(curl -sS -o /tmp/instawp-response.json -w "%{http_code}" \
-X POST "https://app.instawp.io/api/v2/sites/$SITE_ID/execute-command" \
-H "Authorization: Bearer $API_KEY" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d "{
\"command_id\": 2623,
\"commandArguments\": [
{\"PLUGIN_STRING\": \"$PLUGIN_URL\"}
]
}")
if [[ "$HTTP_CODE" -lt 200 || "$HTTP_CODE" -ge 300 ]]; then
echo "InstaWP deploy failed for site $SITE_ID (HTTP $HTTP_CODE)"
cat /tmp/instawp-response.json
exit 1
fi
echo "InstaWP deploy succeeded for site $SITE_ID"
done