-
Notifications
You must be signed in to change notification settings - Fork 33
210 lines (193 loc) · 6.71 KB
/
stable.yml
File metadata and controls
210 lines (193 loc) · 6.71 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
name: Stable
on:
push:
tags:
- '*'
jobs:
# Builds the package and creates artifact with dist files
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, mysql, mysqli, pdo_mysql, bcmath, soap, intl, gd, exif, iconv, imagick
coverage: none
- name: Download Strauss
run: |
curl -sL https://github.com/BrianHenryIE/strauss/releases/download/0.19.5/strauss.phar -o strauss.phar
chmod +x strauss.phar
- name: Install Composer dependencies
uses: "ramsey/composer-install@v2"
with:
composer-options: "--no-dev --no-scripts"
- name: Run Strauss
run: |
php strauss.phar --deleteVendorPackages=true
composer dump-autoload --optimize
find vendor -type d -empty -delete
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '22'
cache: yarn
- name: Install yarn dependencies
run: yarn install --immutable
- name: Build static assets
run: yarn build:production
- name: Create build dir
run: mkdir build
- name: Copy files
run: rsync -avq --exclude-from=".build-excludes" . build/
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: build
path: build
# Creates the stable package artifact when tag is created
pack:
name: Pack
runs-on: ubuntu-latest
needs: build
steps:
- name: Setup variables
id: vars
run: |
echo "package-name=${{ secrets.SLUG }}-${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: build
path: ${{ secrets.SLUG }}
- name: Create archive
run: |
zip -rq ${{ steps.vars.outputs.package-name }}.zip ${{ secrets.SLUG }}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.vars.outputs.package-name }}
path: ${{ steps.vars.outputs.package-name }}.zip
# Release on GitHub
github-release:
name: Release on GitHub
runs-on: ubuntu-latest
needs: pack
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup variables
id: vars
run: |
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
echo "package-name=${{ secrets.SLUG }}-${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Parse changelog
run: |
VERSION="${{ steps.vars.outputs.version }}"
# Extract the changelog content for the current version, excluding the version header
awk -v ver="$VERSION" '
/^= / {
if ($0 ~ "= " ver " =") {
found=1;
next
}
else if (found && /^= [0-9]/) {
exit
}
}
found && /^\*/ { print }
' readme.txt > changelog.txt
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: ${{ steps.vars.outputs.package-name }}
path: .
- name: Release
uses: softprops/action-gh-release@v2
with:
body_path: changelog.txt
files: ${{ steps.vars.outputs.package-name }}.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Deploy to WordPress.org
wordpress-org-release:
name: Deploy to WordPress.org
runs-on: ubuntu-latest
needs: pack
steps:
- name: Checkout
uses: actions/checkout@v4
with:
sparse-checkout: |
.wordpress-org
- name: Setup variables
id: vars
run: |
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
echo "package-name=${{ secrets.SLUG }}-${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: ${{ steps.vars.outputs.package-name }}
path: .
- name: Extract plugin files
run: |
unzip -q ${{ steps.vars.outputs.package-name }}.zip
ls -la ${{ secrets.SLUG }}/
- name: Install SVN
run: sudo apt-get update && sudo apt-get install -y subversion
- name: Deploy to WordPress.org
run: |
SVN_URL="https://plugins.svn.wordpress.org/${SLUG}/"
SVN_DIR="${HOME}/svn-${SLUG}"
VERSION="${GITHUB_REF#refs/tags/}"
# Checkout
svn checkout --depth immediates "$SVN_URL" "$SVN_DIR"
cd "$SVN_DIR"
svn update --set-depth infinity assets
svn update --set-depth infinity trunk
svn update --set-depth immediates tags
# Bail if already tagged
if [[ -d "tags/$VERSION" ]]; then
echo "Version $VERSION already published"
exit 0
fi
# Sync build → trunk
rsync -rc --delete --delete-excluded "${GITHUB_WORKSPACE}/${SLUG}/" trunk/
# Sync assets
if [[ -d "$GITHUB_WORKSPACE/.wordpress-org" ]]; then
rsync -rc --delete "$GITHUB_WORKSPACE/.wordpress-org/" assets/
fi
# Stage changes using svn status (avoids svn add . --force / E155007)
svn status | grep '^\?' | sed 's/? *//' | xargs -I% svn add %@
svn status | grep '^\!' | sed 's/! *//' | xargs -I% svn rm %@
# Tag
svn cp trunk "tags/$VERSION"
# Set image MIME types
if compgen -G "$SVN_DIR/assets/*.png" > /dev/null; then
svn propset svn:mime-type "image/png" "$SVN_DIR/assets/"*.png || true
fi
if compgen -G "$SVN_DIR/assets/*.jpg" > /dev/null; then
svn propset svn:mime-type "image/jpeg" "$SVN_DIR/assets/"*.jpg || true
fi
if compgen -G "$SVN_DIR/assets/*.gif" > /dev/null; then
svn propset svn:mime-type "image/gif" "$SVN_DIR/assets/"*.gif || true
fi
if compgen -G "$SVN_DIR/assets/*.svg" > /dev/null; then
svn propset svn:mime-type "image/svg+xml" "$SVN_DIR/assets/"*.svg || true
fi
# Avoid "directory out of date"
svn update
svn status
# Commit
svn commit -m "Update to version $VERSION from GitHub" \
--no-auth-cache --non-interactive \
--username "$SVN_USERNAME" --password "$SVN_PASSWORD"
echo "✓ Plugin deployed!"
env:
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
SLUG: ${{ secrets.SLUG }}