|
1 | 1 | name: Deploy to InstaWP |
2 | 2 | on: |
3 | | - release: |
4 | | - types: [published] |
| 3 | + workflow_run: |
| 4 | + workflows: ["Build Accessibility Checker Plugin with Ref Param"] |
| 5 | + types: [completed] |
5 | 6 | workflow_dispatch: |
6 | 7 | inputs: |
7 | 8 | plugin_zip_path: |
8 | 9 | description: 'Path to the plugin zip file to deploy. Must be a zip file.' |
9 | 10 | required: true |
10 | 11 | type: string |
11 | 12 |
|
| 13 | +permissions: |
| 14 | + contents: read |
| 15 | + |
12 | 16 | jobs: |
13 | 17 | deploy: |
14 | 18 | runs-on: ubuntu-latest |
| 19 | + if: | |
| 20 | + github.event_name == 'workflow_dispatch' || |
| 21 | + ( |
| 22 | + github.event_name == 'workflow_run' && |
| 23 | + github.event.workflow_run.conclusion == 'success' && |
| 24 | + github.event.workflow_run.event == 'release' |
| 25 | + ) |
15 | 26 |
|
16 | 27 | steps: |
17 | 28 | - name: Get release assets |
18 | 29 | id: get_release_assets |
19 | | - if: github.event_name == 'release' |
| 30 | + if: github.event_name == 'workflow_run' |
20 | 31 | run: | |
21 | | - # Get the list of assets from the release |
22 | | - ASSETS_URL="${{ github.event.release.assets_url }}" |
23 | | - echo "Release assets URL: $ASSETS_URL" |
| 32 | + RELEASES_URL="https://api.github.com/repos/${{ github.repository }}/releases" |
| 33 | + echo "Fetching releases from: $RELEASES_URL" |
24 | 34 |
|
25 | | - # Get the list of assets |
26 | | - ASSETS=$(curl -s \ |
| 35 | + RELEASE=$(curl -s \ |
27 | 36 | -H "Authorization: token ${{ github.token }}" \ |
28 | 37 | -H "Accept: application/vnd.github.v3+json" \ |
29 | | - "$ASSETS_URL") |
| 38 | + "$RELEASES_URL?per_page=5" | jq -c '[.[] | select(.draft == false)][0]') |
| 39 | +
|
| 40 | + if [[ -z "$RELEASE" || "$RELEASE" == "null" ]]; then |
| 41 | + echo "No published release found." |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | +
|
| 45 | + RELEASE_TAG=$(echo "$RELEASE" | jq -r '.tag_name') |
| 46 | + echo "Using release tag: $RELEASE_TAG" |
30 | 47 |
|
31 | | - # Find the first zip file that starts with accessibility-checker in the assets |
32 | | - ZIP_URL=$(echo "$ASSETS" | jq -r '.[] | select(.name | test("^accessibility-checker.*\\.zip$")) | .browser_download_url' | head -n 1) |
| 48 | + # Pick the non-woocommerce zip only. |
| 49 | + ZIP_URL=$(echo "$RELEASE" | jq -r '.assets[] |
| 50 | + | select(.name | test("^accessibility-checker.*\\.zip$")) |
| 51 | + | select(.name | test("-ref-woocommerce-") | not) |
| 52 | + | .browser_download_url' | head -n 1) |
33 | 53 |
|
34 | 54 | if [[ -z "$ZIP_URL" ]]; then |
35 | | - echo "No accessibility-checker zip file found in release assets" |
| 55 | + echo "No non-woocommerce accessibility-checker zip file found in release assets." |
36 | 56 | exit 1 |
37 | 57 | fi |
38 | 58 |
|
39 | | - echo "Found accessibility-checker zip file: $ZIP_URL" |
| 59 | + echo "Found non-woocommerce accessibility-checker zip file: $ZIP_URL" |
40 | 60 | echo "zip_url=$ZIP_URL" >> $GITHUB_OUTPUT |
41 | 61 |
|
42 | 62 | - name: Download and validate plugin zip file |
43 | 63 | id: validate_zip |
44 | 64 | run: | |
45 | 65 | # Determine the ZIP_URL based on the trigger |
46 | | - if [[ "${{ github.event_name }}" == "release" ]]; then |
| 66 | + if [[ "${{ github.event_name }}" == "workflow_run" ]]; then |
47 | 67 | ZIP_URL="${{ steps.get_release_assets.outputs.zip_url }}" |
48 | 68 | else |
49 | 69 | ZIP_URL="${{ github.event.inputs.plugin_zip_path }}" |
@@ -73,24 +93,41 @@ jobs: |
73 | 93 | - name: Deploy to InstaWP |
74 | 94 | run: | |
75 | 95 | API_KEY=${{ secrets.INSTAWP_API_KEY }} |
76 | | - SITE_ID=${{ secrets.INSTAWP_SITE_ID }} |
| 96 | + SITE_ID_MAIN=${{ secrets.INSTAWP_SITE_ID_MAIN }} |
| 97 | + SITE_ID_ARCHIVEWP=${{ secrets.INSTAWP_SITE_ID_ARCHIVEWP }} |
| 98 | +
|
| 99 | + if [[ -z "$API_KEY" || -z "$SITE_ID_MAIN" || -z "$SITE_ID_ARCHIVEWP" ]]; then |
| 100 | + echo "Required InstaWP secrets are missing. Set INSTAWP_API_KEY, INSTAWP_SITE_ID_MAIN, and INSTAWP_SITE_ID_ARCHIVEWP." |
| 101 | + exit 1 |
| 102 | + fi |
77 | 103 |
|
78 | 104 | # Determine the PLUGIN_URL based on the trigger |
79 | | - if [[ "${{ github.event_name }}" == "release" ]]; then |
| 105 | + if [[ "${{ github.event_name }}" == "workflow_run" ]]; then |
80 | 106 | PLUGIN_URL="${{ steps.get_release_assets.outputs.zip_url }}" |
81 | 107 | else |
82 | 108 | PLUGIN_URL="${{ github.event.inputs.plugin_zip_path }}" |
83 | 109 | fi |
84 | 110 |
|
85 | 111 | echo "Deploying plugin from: $PLUGIN_URL" |
| 112 | + for SITE_ID in "$SITE_ID_MAIN" "$SITE_ID_ARCHIVEWP"; do |
| 113 | + echo "Deploying to InstaWP site ID: $SITE_ID" |
| 114 | + HTTP_CODE=$(curl -sS -o /tmp/instawp-response.json -w "%{http_code}" \ |
| 115 | + -X POST "https://app.instawp.io/api/v2/sites/$SITE_ID/execute-command" \ |
| 116 | + -H "Authorization: Bearer $API_KEY" \ |
| 117 | + -H "Accept: application/json" \ |
| 118 | + -H "Content-Type: application/json" \ |
| 119 | + -d "{ |
| 120 | + \"command_id\": 2623, |
| 121 | + \"commandArguments\": [ |
| 122 | + {\"PLUGIN_STRING\": \"$PLUGIN_URL\"} |
| 123 | + ] |
| 124 | + }") |
| 125 | +
|
| 126 | + if [[ "$HTTP_CODE" -lt 200 || "$HTTP_CODE" -ge 300 ]]; then |
| 127 | + echo "InstaWP deploy failed for site $SITE_ID (HTTP $HTTP_CODE)" |
| 128 | + cat /tmp/instawp-response.json |
| 129 | + exit 1 |
| 130 | + fi |
86 | 131 |
|
87 | | - curl -X POST "https://app.instawp.io/api/v2/sites/$SITE_ID/execute-command" \ |
88 | | - -H "Authorization: Bearer $API_KEY" \ |
89 | | - -H "Accept: application/json" \ |
90 | | - -H "Content-Type: application/json" \ |
91 | | - -d "{ |
92 | | - \"command_id\": 2623, |
93 | | - \"commandArguments\": [ |
94 | | - {\"PLUGIN_STRING\": \"$PLUGIN_URL\"} |
95 | | - ] |
96 | | - }" |
| 132 | + echo "InstaWP deploy succeeded for site $SITE_ID" |
| 133 | + done |
0 commit comments