-
Notifications
You must be signed in to change notification settings - Fork 102
219 lines (194 loc) · 7.57 KB
/
deploy-standalone-plugins.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
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
---
name: Deploy Standalone Plugin(s) to WordPress.org
on:
release:
types:
- published
workflow_dispatch:
inputs:
plugin:
type: string
description: 'The slug of the plugin to deploy'
required: true
dry-run:
type: boolean
description: 'Debug mode (run without publishing).'
default: false
permissions: {}
jobs:
pre-run:
name: Pre-run
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.plugins }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js (.nvmrc)
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: npm
- name: Install npm dependencies
run: npm ci
- name: Build assets
run: npm run build
- name: Get directory
id: get-plugin-directory
if: ${{ github.event_name == 'workflow_dispatch' }}
run: |
echo "directory=$(node ./bin/plugin/cli.js get-plugin-dir --slug=${{ inputs.slug }})" >> $GITHUB_OUTPUT
- name: Get plugin version
id: get-version
if: ${{ github.event_name == 'workflow_dispatch' }}
run: |
echo "version=$(node ./bin/plugin/cli.js get-plugin-version --slug=${{ inputs.slug }})" >> $GITHUB_OUTPUT
- name: Set matrix
id: set-matrix
run: |
PLUGINS=$(jq -r '.plugins' plugins.json)
if ${{ github.event_name == 'workflow_dispatch' }}; then
SLUG=${{ inputs.plugin }}
if echo $PLUGINS | jq -e '.[] | select(. == "'$SLUG'")' > /dev/null; then
PLUGINS="[ \"$SLUG\" ]"
else
echo "::error::The plugin $SLUG is not in the list of plugins to deploy."
exit 1
fi
fi
# Set the matrix.
echo "::notice::Deploying the following plugins: $(echo ${PLUGINS[@]})"
echo "plugins=$(echo $PLUGINS | jq -c .)" >> $GITHUB_OUTPUT
deploy:
name: "Deploy Plugin: ${{ matrix.plugin }}"
needs: pre-run
runs-on: ubuntu-latest
permissions:
actions: write
deployments: write
strategy:
matrix:
plugin: ${{ fromJSON(needs.pre-run.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js (.nvmrc)
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: npm
- name: Install npm dependencies
run: npm ci
- name: Build plugin
run: npm run build:plugin:${{ matrix.plugin }}
- name: Set plugin version
working-directory: ./build
run: |
echo "PLUGIN_VERSION=$(jq -r '."${{ matrix.plugin }}"' manifest.json)" >> $GITHUB_ENV
- name: Check if deployment is needed
id: check-deployment
run: |
PLUGIN_VERSION_WPORG=$(curl -sSL https://api.wordpress.org/plugins/info/1.0/${{ matrix.plugin }}.json --retry 3 --retry-delay 5 --retry-all-errors --fail | jq -r '.version')
echo "::debug::The ${{ matrix.plugin }} plugin is currently at version $PLUGIN_VERSION_WPORG on WordPress.org."
# Bail if the plugin version is not found.
if [ -z "$PLUGIN_VERSION_WPORG" ]; then
echo "::error::Could not retrieve ${{ matrix.plugin }} information from WordPress.org. The plugin may not exist or the API may be down."
exit 1
fi
# Bail if the plugin is already up to date.
if [ "$PLUGIN_VERSION_WPORG" = "$PLUGIN_VERSION" ]; then
echo "::notice::The ${{ matrix.plugin }} plugin is already up to date on WordPress.org. Halting deployment."
exit 0
fi
echo "deploy=true" >> $GITHUB_OUTPUT
- name: Create zip file
if: steps.check-deployment.outputs.deploy == 'true'
run: |
mkdir -p ./build/dist
cd ./build/${{ matrix.plugin }}
zip -r ../dist/${{ matrix.plugin }}.zip .
- name: Generate checksum
if: steps.check-deployment.outputs.deploy == 'true'
working-directory: ./build/dist
run: |
mkdir -p $RUNNER_TEMP/plugin-checksums
find . -type f -print0 | sort -z | xargs -r0 shasum -a 256 -b | sed 's# \*\./# *#' > $RUNNER_TEMP/plugin-checksums/checksums.txt
shasum -a 256 -U -c $RUNNER_TEMP/plugin-checksums/checksums.txt
cat $RUNNER_TEMP/plugin-checksums/checksums.txt | while read sum file; do echo "$sum $file" > ${file#\*}.sha256; done
- name: Upload artifact
if: steps.check-deployment.outputs.deploy == 'true'
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.plugin }}
path: ./build/dist
- name: Start deployment
if: steps.check-deployment.outputs.deploy == 'true'
uses: bobheadxi/deployments@v1
id: wporg-deployment
with:
step: start
token: ${{ secrets.GITHUB_TOKEN }}
env: "wp.org plugin: ${{ matrix.plugin }}"
- name: Deploy Plugin - ${{ matrix.plugin }}
if: steps.check-deployment.outputs.deploy == 'true'
uses: 10up/action-wordpress-plugin-deploy@stable
with:
dry-run: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run || false }}
env:
SLUG: ${{ matrix.plugin }}
VERSION: ${{ env.PLUGIN_VERSION }}
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
BUILD_DIR: ./build/${{ matrix.plugin }}
ASSETS_DIR: ./plugins/${{ matrix.plugin }}/.wordpress-org
- name: Finish deployment
if: ${{ steps.wporg-deployment.outputs.deployment_id && always() }}
uses: bobheadxi/deployments@v1
with:
step: finish
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
deployment_id: ${{ steps.wporg-deployment.outputs.deployment_id }}
env: "wp.org plugin: ${{ matrix.plugin }}"
env_url: "https://wordpress.org/plugins/${{ matrix.plugin }}/"
release-assets:
name: Add release assets
needs: [ pre-run, deploy ]
runs-on: ubuntu-latest
permissions:
actions: read
contents: write
if: github.event_name == 'release'
strategy:
matrix:
plugin: ${{ fromJSON(needs.pre-run.outputs.matrix) }}
steps:
- name: Check artifact existence
id: artifact-existence
uses: actions/github-script@v7
with:
script: |
const getArtifact = await github.request('GET /repos/{owner}/{repo}/actions/runs/{run_id}/artifacts{?name}', {
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.runId,
name: "${{ matrix.plugin }}"
});
if (getArtifact.status !== 200) {
throw new Error(`Invalid response from GitHub API: ${getArtifact.status}`);
}
core.setOutput('exists', getArtifact.data.artifacts.length > 0);
core.debug(`Artifact for ${{ matrix.plugin }} exists: ${core.getInput('exists')} ? "true" : "false"`);
- name: Download artifact
if: steps.artifact-existence.outputs.exists == 'true'
uses: actions/download-artifact@v4
with:
name: ${{ matrix.plugin }}
path: ./build/dist
- name: Upload release assets
if: steps.artifact-existence.outputs.exists == 'true'
uses: softprops/action-gh-release@v1
with:
files: |
./build/dist/${{ matrix.plugin }}.zip
./build/dist/${{ matrix.plugin }}.zip.sha256