|
1 | | -name: Create Release Archive |
| 1 | +name: Publish Release |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | 5 | branches: |
6 | 6 | - main |
7 | | - release: |
8 | | - types: [published] |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
9 | 10 |
|
10 | 11 | jobs: |
11 | | - build-and-upload-archive: |
| 12 | + release: |
12 | 13 | runs-on: ubuntu-latest |
| 14 | + |
13 | 15 | steps: |
14 | | - # Step 1: Checkout code |
15 | | - - name: Checkout code |
| 16 | + - name: Checkout repository |
16 | 17 | uses: actions/checkout@v4 |
17 | | - with: |
18 | | - fetch-depth: 0 |
19 | | - |
20 | | - # Step 2: Install Node dependencies |
21 | | - - name: Install Node dependencies |
22 | | - run: npm ci |
23 | 18 |
|
24 | | - # Step 3: Run build |
25 | | - - name: Run npm build |
26 | | - run: npm run build |
27 | | - |
28 | | - # Step 4: Install composer dependencies for production |
29 | | - - name: Composer install |
30 | | - run: composer install --no-dev --optimize-autoloader |
31 | | - |
32 | | - # Step 5: Remove unnecessary files and folders |
33 | | - - name: Clean repo for release |
34 | | - run: | |
35 | | - rm -rf .github src node_modules |
36 | | - rm -f .gitignore LICENSE README.md readme.txt .cursorrc.json |
37 | | - rm -f *.lock *.js *.xml *.json |
38 | | -
|
39 | | - # Step 6: Generate manifest.json and extract $VERSION |
40 | | - - name: Generate manifest.json |
41 | | - id: generate_manifest |
| 19 | + - name: Read version from composer.json |
| 20 | + id: version |
42 | 21 | run: | |
43 | | - MAIN_FILE=$(grep -rl "Plugin Name:" --include="*.php" . | head -n 1) |
44 | | - echo "Main plugin file: $MAIN_FILE" |
45 | | -
|
46 | | - parse_field() { |
47 | | - grep -i "$1:" "$MAIN_FILE" | head -n1 \ |
48 | | - | sed -E "s/^\s*\*\s*//" \ |
49 | | - | sed -E "s|$1:[[:space:]]*||i" \ |
50 | | - | xargs |
51 | | - } |
52 | | -
|
53 | | - PLUGIN_NAME="$(parse_field 'Plugin Name')" |
54 | | - PLUGIN_URI="$(parse_field 'Plugin URI')" |
55 | | - DESCRIPTION="$(parse_field 'Description')" |
56 | | - AUTHOR="$(parse_field 'Author')" |
57 | | - AUTHOR_URI="$(parse_field 'Author URI')" |
58 | | - VERSION="$(parse_field 'Version')" |
59 | | - REQUIRES_PHP="$(parse_field 'Requires PHP')" |
60 | | - REQUIRES_WP="$(parse_field 'Requires at least')" |
61 | | - LICENSE="$(parse_field 'License')" |
62 | | - LICENSE_URI="$(parse_field 'License URI')" |
63 | | - TEXT_DOMAIN="$(parse_field 'Text Domain')" |
64 | | - DOMAIN_PATH="$(parse_field 'Domain Path')" |
65 | | - TESTED_UP_TO="$(parse_field 'Tested up to')" |
| 22 | + VERSION=$(jq -r '.version' composer.json) |
66 | 23 |
|
67 | | - echo "VERSION=$VERSION" >> $GITHUB_ENV |
| 24 | + if [ "$VERSION" = "null" ] || [ -z "$VERSION" ]; then |
| 25 | + echo "❌ Version not found in composer.json" |
| 26 | + exit 1 |
| 27 | + fi |
68 | 28 |
|
69 | | - cat > manifest.json <<EOF |
70 | | - { |
71 | | - "plugin_name": "$PLUGIN_NAME", |
72 | | - "plugin_uri": "$PLUGIN_URI", |
73 | | - "description": "$DESCRIPTION", |
74 | | - "author": "$AUTHOR", |
75 | | - "author_uri": "$AUTHOR_URI", |
76 | | - "version": "$VERSION", |
77 | | - "requires_php": "$REQUIRES_PHP", |
78 | | - "requires_wp": "$REQUIRES_WP", |
79 | | - "license": "$LICENSE", |
80 | | - "license_uri": "$LICENSE_URI", |
81 | | - "text_domain": "$TEXT_DOMAIN", |
82 | | - "domain_path": "$DOMAIN_PATH", |
83 | | - "tested_up_to": "$TESTED_UP_TO" |
84 | | - } |
85 | | - EOF |
| 29 | + echo "version=v$VERSION" >> $GITHUB_OUTPUT |
86 | 30 |
|
87 | | - # Step 7: Create custom zip archive |
88 | | - - name: Create custom archive |
89 | | - run: | |
90 | | - REPO_NAME=$(echo "${{ github.repository }}" | cut -d'/' -f2) |
91 | | - CUSTOM_ARCHIVE_NAME="${REPO_NAME}.zip" |
92 | | -
|
93 | | - # Move one level up and zip the repository folder |
94 | | - cd .. |
95 | | - zip -r "$CUSTOM_ARCHIVE_NAME" "$REPO_NAME" -x "$REPO_NAME/.git/*" "$REPO_NAME/.github/*" |
96 | | -
|
97 | | - # Move the zip back to the original workflow directory |
98 | | - mv "$CUSTOM_ARCHIVE_NAME" "$GITHUB_WORKSPACE/" |
99 | | -
|
100 | | - # Set the zip file name as environment variable for later steps |
101 | | - echo "CUSTOM_ARCHIVE_NAME=$CUSTOM_ARCHIVE_NAME" >> "$GITHUB_ENV" |
102 | | -
|
103 | | - # Step 8: Get last commit message (push events only) |
104 | | - - name: Get last commit message |
105 | | - if: github.event_name == 'push' |
106 | | - id: last_commit |
107 | | - run: | |
108 | | - LAST_COMMIT_MESSAGE="$(git log -1 --pretty=%B)" |
109 | | - { |
110 | | - echo "LAST_COMMIT_MESSAGE<<EOF" |
111 | | - echo "$LAST_COMMIT_MESSAGE" |
112 | | - echo "EOF" |
113 | | - } >> $GITHUB_ENV |
114 | | -
|
115 | | - # Step 9: Ensure tag exists on remote (push events only) |
116 | | - - name: Ensure tag exists |
117 | | - if: github.event_name == 'push' |
| 31 | + - name: Delete existing release and tag if they exist |
118 | 32 | env: |
119 | 33 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
120 | 34 | run: | |
121 | | - TAG=v${{ env.VERSION }} |
122 | | - git config user.name "github-actions[bot]" |
123 | | - git config user.email "github-actions[bot]@users.noreply.github.com" |
124 | | - git tag "$TAG" |
125 | | - git push https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git "$TAG" |
| 35 | + TAG="${{ steps.version.outputs.version }}" |
126 | 36 |
|
127 | | - # Step 10: Create GitHub release (push events) |
128 | | - - name: Create GitHub release (push) |
129 | | - if: github.event_name == 'push' |
130 | | - id: create_release_push |
131 | | - uses: softprops/action-gh-release@v2 |
132 | | - with: |
133 | | - tag_name: ${{ env.VERSION }} |
134 | | - name: Version ${{ env.VERSION }} |
135 | | - body: ${{ env.LAST_COMMIT_MESSAGE }} |
136 | | - files: | |
137 | | - ${{ env.CUSTOM_ARCHIVE_NAME }} |
138 | | - manifest.json |
139 | | - overwrite_files: true |
140 | | - env: |
141 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 37 | + if gh release view "$TAG" > /dev/null 2>&1; then |
| 38 | + echo "⚠️ Release $TAG already exists. Deleting..." |
| 39 | + gh release delete "$TAG" --yes |
| 40 | + git push --delete origin "$TAG" || true |
| 41 | + else |
| 42 | + echo "✅ No existing release for $TAG" |
| 43 | + fi |
142 | 44 |
|
143 | | - # Step 11: Create GitHub release (release events) |
144 | | - - name: Create GitHub release (release) |
145 | | - if: github.event_name == 'release' |
146 | | - id: create_release_event |
| 45 | + - name: Create GitHub Release |
147 | 46 | uses: softprops/action-gh-release@v2 |
148 | 47 | with: |
149 | | - tag_name: ${{ github.event.release.tag_name }} |
150 | | - name: Release ${{ github.event.release.tag_name }} |
151 | | - body: ${{ github.event.release.body }} |
152 | | - files: | |
153 | | - ${{ env.CUSTOM_ARCHIVE_NAME }} |
154 | | - manifest.json |
155 | | - overwrite_files: true |
| 48 | + tag_name: ${{ steps.version.outputs.version }} |
| 49 | + name: Release ${{ steps.version.outputs.version }} |
| 50 | + generate_release_notes: true |
156 | 51 | env: |
157 | 52 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments