-
Notifications
You must be signed in to change notification settings - Fork 2
154 lines (127 loc) · 5.16 KB
/
pre-release.yml
File metadata and controls
154 lines (127 loc) · 5.16 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
name: Pre-release Tag
on:
push:
branches:
- main
paths:
- "plugins/**"
permissions:
contents: write # Allow actions to read and write repository contents
actions: read # Allow actions to read repository metadata but not write
jobs:
tag-pre-release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: mbstring, json, zip
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18.x
- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
version: 10
- name: Get changed plugin directory
id: plugin
run: |
git fetch --prune --unshallow 2>/dev/null || git fetch --prune
plugin=$(git diff --name-only HEAD~1 HEAD | grep '^plugins/' | head -1 | cut -d/ -f2)
echo "plugin_slug=$plugin" >> $GITHUB_OUTPUT
- name: Validate plugin detection
run: |
if [ -z "${{ steps.plugin.outputs.plugin_slug }}" ]; then
echo "No plugin detected in changes"
exit 1
fi
if [ ! -d "plugins/${{ steps.plugin.outputs.plugin_slug }}" ]; then
echo "Plugin directory does not exist"
exit 1
fi
- name: Install dependencies
run: pnpm install
- name: Apply version bumps from changesets
run: pnpm changeset version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Commit updated package.json and changelogs
run: |
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git add .
git commit -m "chore: apply version bump from changesets" || echo "No changes to commit"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Read package metadata
id: metadata
run: |
PLUGIN_DIR="plugins/${{ steps.plugin.outputs.plugin_slug }}"
if [ ! -f "$PLUGIN_DIR/package.json" ]; then
echo "package.json not found in $PLUGIN_DIR"
exit 1
fi
package_name=$(jq -r '.name // empty' "$PLUGIN_DIR/package.json")
package_version=$(jq -r '.version // empty' "$PLUGIN_DIR/package.json")
if [ -z "$package_name" ] || [ "$package_name" = "null" ] || [ "$package_name" = "empty" ]; then
echo "Missing or invalid name in $PLUGIN_DIR/package.json"
exit 1
fi
if [ -z "$package_version" ] || [ "$package_version" = "null" ] || [ "$package_version" = "empty" ]; then
echo "Missing or invalid version in $PLUGIN_DIR/package.json"
exit 1
fi
echo "package_name=$package_name" >> $GITHUB_OUTPUT
echo "package_version=$package_version" >> $GITHUB_OUTPUT
echo "PLUGIN_DIR=$PLUGIN_DIR" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Git tag
run: |
TAG_NAME="${{ steps.metadata.outputs.package_name }}-${{ steps.metadata.outputs.package_version }}"
# Check if tag already exists
if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
echo "Tag $TAG_NAME already exists. Skipping tag creation."
exit 0
fi
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git tag "$TAG_NAME"
git push origin "$TAG_NAME"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Run composer install
working-directory: ${{ steps.metadata.outputs.PLUGIN_DIR }}
run: composer install --no-dev --optimize-autoloader
- name: Validate composer setup
working-directory: ${{ steps.metadata.outputs.PLUGIN_DIR }}
run: |
composer validate --no-check-publish --no-check-lock
- name: Create plugin archive
working-directory: ${{ steps.metadata.outputs.PLUGIN_DIR }}
run: |
mkdir -p plugin-build
composer archive --format=zip --file="plugin-build/${{ steps.plugin.outputs.plugin_slug }}.zip"
# Verify archive was created
if [ ! -f "plugin-build/${{ steps.plugin.outputs.plugin_slug }}.zip" ]; then
echo "Failed to create plugin archive"
exit 1
fi
echo "Archive created successfully: $(ls -lh plugin-build/${{ steps.plugin.outputs.plugin_slug }}.zip)"
- name: Upload archive to GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.metadata.outputs.package_name }}-${{ steps.metadata.outputs.package_version }}
name: "Pre-release ${{ steps.metadata.outputs.package_version }} for ${{ steps.metadata.outputs.package_name }}"
prerelease: true
files: |
${{ steps.metadata.outputs.PLUGIN_DIR }}/plugin-build/${{ steps.plugin.outputs.plugin_slug }}.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}