|
1 | 1 | name: Deploy to InstaWP |
2 | 2 | on: |
3 | | - release: |
4 | | - types: [published] |
5 | 3 | workflow_dispatch: |
| 4 | + inputs: |
| 5 | + plugin_zip_path: |
| 6 | + description: 'Path to the plugin zip file to deploy. Must be a zip file.' |
| 7 | + required: true |
| 8 | + type: string |
6 | 9 |
|
7 | 10 | jobs: |
8 | 11 | deploy: |
9 | 12 | runs-on: ubuntu-latest |
10 | 13 |
|
11 | 14 | steps: |
12 | | - - name: Checkout Repository |
13 | | - uses: actions/checkout@v4 |
14 | | - |
15 | | - - name: Set up PHP |
16 | | - uses: shivammathur/setup-php@v2 |
17 | | - with: |
18 | | - php-version: '8.2' |
19 | | - tools: composer |
20 | | - |
21 | | - - name: Set up Node.js |
22 | | - uses: actions/setup-node@v4 |
23 | | - with: |
24 | | - node-version: '20' |
25 | | - |
26 | | - - name: Cache Composer dependencies |
27 | | - uses: actions/cache@v4 |
28 | | - with: |
29 | | - path: vendor |
30 | | - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} |
31 | | - restore-keys: | |
32 | | - ${{ runner.os }}-composer- |
33 | | -
|
34 | | - - name: Cache NPM dependencies |
35 | | - uses: actions/cache@v4 |
36 | | - with: |
37 | | - path: node_modules |
38 | | - key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} |
39 | | - restore-keys: | |
40 | | - ${{ runner.os }}-npm- |
41 | | -
|
42 | | - - name: Install Composer dependencies |
43 | | - run: composer install --no-dev |
44 | | - |
45 | | - - name: Install NPM dependencies |
46 | | - run: npm install |
47 | | - |
48 | | - - name: Build plugin zip |
49 | | - run: npm run dist |
50 | | - |
51 | | - - name: List files before deploy |
| 15 | + - name: Validate plugin zip file |
| 16 | + id: validate_zip |
| 17 | + run: | |
| 18 | + ZIP_PATH="${{ github.event.inputs.plugin_zip_path }}" |
| 19 | + if [ ! -f "$ZIP_PATH" ]; then |
| 20 | + echo "File does not exist: $ZIP_PATH" |
| 21 | + exit 1 |
| 22 | + fi |
| 23 | + if [[ "$ZIP_PATH" != *.zip ]]; then |
| 24 | + echo "File does not have .zip extension: $ZIP_PATH" |
| 25 | + exit 1 |
| 26 | + fi |
| 27 | + MIME_TYPE=$(file --mime-type -b "$ZIP_PATH") |
| 28 | + if [ "$MIME_TYPE" != "application/zip" ]; then |
| 29 | + echo "File is not a valid zip archive: $ZIP_PATH (type: $MIME_TYPE)" |
| 30 | + exit 1 |
| 31 | + fi |
| 32 | + echo "ZIP_PATH=$ZIP_PATH" >> $GITHUB_ENV |
| 33 | +
|
| 34 | + - name: Upload plugin zip to transfer.sh |
| 35 | + id: upload_zip |
52 | 36 | run: | |
53 | | - echo "Current working directory:" |
54 | | - pwd |
55 | | - echo "Listing all files recursively:" |
56 | | - find . -type f | sort |
| 37 | + UPLOAD_URL=$(curl --silent --upload-file "$ZIP_PATH" "https://transfer.sh/$(basename $ZIP_PATH)") |
| 38 | + echo "UPLOAD_URL=$UPLOAD_URL" >> $GITHUB_ENV |
57 | 39 |
|
58 | 40 | - name: Deploy to InstaWP |
59 | 41 | run: | |
60 | 42 | API_KEY=${{ secrets.INSTAWP_API_KEY }} |
61 | | - PLUGIN_ZIP=$(ls dist/accessibility-checker-*.zip | head -n 1) |
62 | 43 | SITE_ID=${{ secrets.INSTAWP_SITE_ID }} |
63 | | - curl -X POST "https://api.instawp.io/v2/sites/install-plugin" \ |
| 44 | + PLUGIN_URL="$UPLOAD_URL" |
| 45 | + curl -X PUT "https://app.instawp.io/api/v2/sites/$SITE_ID/install-content" \ |
64 | 46 | -H "Authorization: Bearer $API_KEY" \ |
65 | | - -H "Content-Type: multipart/form-data" \ |
66 | | - -F "file=@$PLUGIN_ZIP" \ |
67 | | - -F "site_id=$SITE_ID" |
| 47 | + -H "Accept: application/json" \ |
| 48 | + -H "Content-Type: application/json" \ |
| 49 | + -d "{\"plugin_urls\": \"$PLUGIN_URL\"}" |
0 commit comments