-
-
Notifications
You must be signed in to change notification settings - Fork 3
258 lines (219 loc) · 9.18 KB
/
release.yml
File metadata and controls
258 lines (219 loc) · 9.18 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
name: Release
on:
release:
types: [created]
workflow_dispatch:
inputs:
tag:
description: 'Release tag to build assets for'
required: true
env:
GITHUB_TOKEN: ${{ secrets.OWNER_PAT || secrets.GITHUB_TOKEN }}
jobs:
update-version:
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.extract_version.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
token: ${{ env.GITHUB_TOKEN }}
fetch-depth: 0
ref: main
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Extract version from release tag
id: extract_version
run: |
# Remove 'v' prefix if present (e.g., v1.2.3 -> 1.2.3)
VERSION="${{ github.event.release.tag_name }}"
VERSION="${VERSION#v}"
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "Extracted version: ${VERSION}"
- name: Update versions and lock files
run: |
# Update TOML versions
sed -i 's/^version = "[^"]*"/version = "${{ steps.extract_version.outputs.version }}"/' Cargo.toml
echo "Updated root Cargo.toml version to ${{ steps.extract_version.outputs.version }}"
sed -i 's/^version = "[^"]*"/version = "${{ steps.extract_version.outputs.version }}"/' extension.toml
echo "Updated extension.toml version to ${{ steps.extract_version.outputs.version }}"
sed -i 's/^version = "[^"]*"/version = "${{ steps.extract_version.outputs.version }}"/' lsp-server/Cargo.toml
echo "Updated lsp-server/Cargo.toml version to ${{ steps.extract_version.outputs.version }}"
# Update Cargo.lock files
cargo update --manifest-path Cargo.toml
echo "Updated root Cargo.lock"
cargo update --manifest-path lsp-server/Cargo.toml
echo "Updated lsp-server/Cargo.lock"
- name: Verify changes
run: |
echo "=== Root Cargo.toml ==="
grep "^version =" Cargo.toml
echo "=== extension.toml ==="
grep "^version =" extension.toml
echo "=== lsp-server/Cargo.toml ==="
grep "^version =" lsp-server/Cargo.toml
- name: Commit and push changes
id: commit_changes
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
# Check if there are any changes to commit
if git diff --quiet && git diff --cached --quiet; then
echo "No changes to commit"
echo "new_commit_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
else
git add -A
git commit -m "chore: 🔖 Update version to ${{ steps.extract_version.outputs.version }}."
git push origin main
NEW_COMMIT_SHA=$(git rev-parse HEAD)
echo "new_commit_sha=${NEW_COMMIT_SHA}" >> $GITHUB_OUTPUT
echo "All changed files updated and pushed to main branch"
echo "New commit SHA: ${NEW_COMMIT_SHA}"
fi
- name: Update tag and release
if: steps.commit_changes.outputs.new_commit_sha != ''
run: |
TAG_NAME="${{ github.event.release.tag_name }}"
RELEASE_ID="${{ github.event.release.id }}"
FINAL_COMMIT_SHA="${{ steps.commit_changes.outputs.new_commit_sha }}"
echo "Updating tag ${TAG_NAME} to point to commit ${FINAL_COMMIT_SHA}"
# Update the tag to point to the new commit
curl -L \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/${{ github.repository }}/git/refs/tags/${TAG_NAME}" \
-d "{\"sha\":\"${FINAL_COMMIT_SHA}\",\"force\":true}"
echo "Updated tag ${TAG_NAME} to commit ${FINAL_COMMIT_SHA}"
# Update the release to point to the new commit
curl -L \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/${{ github.repository }}/releases/${RELEASE_ID}" \
-d "{\"tag_name\":\"${TAG_NAME}\",\"target_commitish\":\"${FINAL_COMMIT_SHA}\"}"
echo "Updated release ${RELEASE_ID} to point to commit ${FINAL_COMMIT_SHA}"
echo "Version update complete!"
build-lsp-server:
name: Build LSP Server
needs: update-version
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
binary_name: phpcs-lsp-server-linux-x64
- os: ubuntu-latest
target: aarch64-unknown-linux-musl
binary_name: phpcs-lsp-server-linux-arm64
- os: macos-latest
target: x86_64-apple-darwin
binary_name: phpcs-lsp-server-macos-x64
- os: macos-latest
target: aarch64-apple-darwin
binary_name: phpcs-lsp-server-macos-arm64
- os: windows-latest
target: x86_64-pc-windows-msvc
binary_name: phpcs-lsp-server-windows-x64.exe
- os: windows-latest
target: aarch64-pc-windows-msvc
binary_name: phpcs-lsp-server-windows-arm64.exe
steps:
- uses: actions/checkout@v5
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install musl tools (x86_64)
if: matrix.target == 'x86_64-unknown-linux-musl'
run: |
sudo apt-get update
sudo apt-get install -y musl-tools
- name: Install cross (aarch64-musl)
if: matrix.target == 'aarch64-unknown-linux-musl'
run: |
cargo install cross --git https://github.com/cross-rs/cross
- name: Build LSP Server (native)
if: matrix.target != 'aarch64-unknown-linux-musl'
run: |
cd lsp-server
cargo build --release --target ${{ matrix.target }}
- name: Build LSP Server (cross)
if: matrix.target == 'aarch64-unknown-linux-musl'
run: |
cd lsp-server
cross build --release --target ${{ matrix.target }}
- name: Prepare binary
shell: bash
run: |
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
cp lsp-server/target/${{ matrix.target }}/release/phpcs-lsp-server.exe ${{ matrix.binary_name }}
else
cp lsp-server/target/${{ matrix.target }}/release/phpcs-lsp-server ${{ matrix.binary_name }}
fi
- name: Create archive
shell: bash
run: |
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
7z a ${{ matrix.binary_name }}.zip ${{ matrix.binary_name }}
echo "ASSET_PATH=${{ matrix.binary_name }}.zip" >> $GITHUB_ENV
else
tar -czf ${{ matrix.binary_name }}.tar.gz ${{ matrix.binary_name }}
echo "ASSET_PATH=${{ matrix.binary_name }}.tar.gz" >> $GITHUB_ENV
fi
- name: Upload Release Asset
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.event_name == 'release' && github.event.release.tag_name || github.event.inputs.tag }}
files: ${{ env.ASSET_PATH }}
token: ${{ env.GITHUB_TOKEN }}
download-phars:
name: Download and Package PHAR Files
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Download PHPCS and PHPCBF PHARs
run: |
# Download latest stable PHPCS from PHPCSStandards (maintained fork)
curl -L https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/latest/download/phpcs.phar -o phpcs.phar
curl -L https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/latest/download/phpcbf.phar -o phpcbf.phar
# Make them executable
chmod +x phpcs.phar phpcbf.phar
# Verify they work
php phpcs.phar --version
php phpcbf.phar --version
- name: Create PHAR archives
run: |
tar -czf phpcs.phar.tar.gz phpcs.phar
tar -czf phpcbf.phar.tar.gz phpcbf.phar
- name: Upload PHAR files
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.event_name == 'release' && github.event.release.tag_name || github.event.inputs.tag }}
files: |
phpcs.phar.tar.gz
phpcbf.phar.tar.gz
token: ${{ env.GITHUB_TOKEN }}
publish:
name: Publish Zed Extension
runs-on: ubuntu-latest
needs:
- download-phars
- build-lsp-server
- update-version
steps:
- uses: huacnlee/zed-extension-action@v1
with:
extension-name: phpcs
push-to: mikebronner/extensions
tag-name: ${{ needs.update-version.outputs.new_version }}
commit-message: |
Update {{extensionName}} to {{version}}
Release notes:
https://github.com/{{owner}}/{{repo}}/releases/tag/{{version}}
env:
COMMITTER_TOKEN: ${{ secrets.ZED_PUBLISHING_TOKEN }}