Skip to content

Commit 96548ef

Browse files
committed
Update plugin versioning and add release workflow for automated version bumps
1 parent e95e8dd commit 96548ef

2 files changed

Lines changed: 84 additions & 10 deletions

File tree

.github/workflows/release.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Plugin Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
with:
17+
fetch-depth: '0'
18+
19+
- name: Get current version
20+
id: get_version
21+
run: |
22+
version=$(grep -oP 'Version:\s*\K[0-9.]+' github-to-wordpress-sync.php)
23+
echo "Current version: $version"
24+
echo "version=$version" >> $GITHUB_ENV
25+
26+
- name: Bump version if release
27+
if: contains(github.event.head_commit.message, 'release')
28+
run: |
29+
current_version=$(grep -oP 'Version:\s*\K[0-9.]+' github-to-wordpress-sync.php)
30+
next_version=$(awk -F. '{print $1 "." ($2+1)}' <<< "$current_version")
31+
sed -i "s/Version: $current_version/Version: $next_version/" github-to-wordpress-sync.php
32+
echo "new_version=$next_version" >> $GITHUB_ENV
33+
34+
- name: Commit version bump
35+
if: contains(github.event.head_commit.message, 'release')
36+
run: |
37+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
38+
git config --local user.name "github-actions[bot]"
39+
git add github-to-wordpress-sync.php
40+
git commit -m "Bump version to ${{ env.new_version }}"
41+
git push
42+
43+
- name: Create zip file
44+
run: |
45+
mkdir -p github-to-wordpress-sync
46+
rsync -av --exclude='.git' --exclude='.github' --exclude='github-to-wordpress-sync' ./ github-to-wordpress-sync/
47+
zip -r github-to-wordpress-sync.zip github-to-wordpress-sync
48+
rm -rf github-to-wordpress-sync
49+
50+
- name: Create GitHub Release
51+
if: contains(github.event.head_commit.message, 'release')
52+
uses: softprops/action-gh-release@v1
53+
with:
54+
files: github-to-wordpress-sync.zip
55+
tag_name: "v${{ env.new_version }}"
56+
name: "Release v${{ env.new_version }}"
57+
body: "Release v${{ env.new_version }} of the plugin."
58+
env:
59+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60+
61+
- name: Create GitHub Pre-release
62+
if: contains(github.event.head_commit.message, 'alphatag')
63+
uses: softprops/action-gh-release@v1
64+
with:
65+
prerelease: true
66+
files: github-to-wordpress-sync.zip
67+
tag_name: "pre-v${{ env.version }}"
68+
name: "Pre-release v${{ env.version }}"
69+
body: "Pre-release v${{ env.version }} of the plugin."
70+
env:
71+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

github-to-wordpress-sync.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: Github to WordPress Sync
44
* Plugin URI: https://sinanisler.com
55
* Description: GitHub to WordPress Sync: Streamline theme & plugin updates directly from GitHub. Easy, secure, and developer-friendly.
6-
* Version: 1.0.0
6+
* Version: 0.1
77
* Author: Sinan Isler
88
* Author URI: https://sinanisler.com/
99
* License: GPL v2 or later
@@ -17,7 +17,6 @@
1717
}
1818

1919
// Define plugin constants
20-
define('GTWS_VERSION', '1.0.0');
2120
define('GTWS_PLUGIN_DIR', plugin_dir_path(__FILE__));
2221
define('GTWS_PLUGIN_URL', plugin_dir_url(__FILE__));
2322
define('GTWS_PLUGIN_FILE', __FILE__);
@@ -87,9 +86,6 @@ public function activate() {
8786
if (!get_option('gtws_projects')) {
8887
add_option('gtws_projects', array());
8988
}
90-
91-
// Set default options
92-
add_option('gtws_version', GTWS_VERSION);
9389
}
9490

9591
/**
@@ -120,22 +116,29 @@ public function enqueue_admin_assets($hook) {
120116
if ($hook !== 'settings_page_github-to-wordpress-sync') {
121117
return;
122118
}
123-
119+
120+
// Get version from plugin header
121+
if (!function_exists('get_plugin_data')) {
122+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
123+
}
124+
$plugin_data = get_plugin_data(GTWS_PLUGIN_FILE);
125+
$version = $plugin_data['Version'];
126+
124127
wp_enqueue_style(
125128
'gtws-admin-style',
126129
GTWS_PLUGIN_URL . 'assets/css/admin.css',
127130
array(),
128-
GTWS_VERSION
131+
$version
129132
);
130-
133+
131134
wp_enqueue_script(
132135
'gtws-admin-script',
133136
GTWS_PLUGIN_URL . 'assets/js/admin.js',
134137
array('jquery'),
135-
GTWS_VERSION,
138+
$version,
136139
true
137140
);
138-
141+
139142
wp_localize_script('gtws-admin-script', 'gtws_ajax', array(
140143
'ajax_url' => admin_url('admin-ajax.php'),
141144
'nonce' => wp_create_nonce('gtws_nonce'),

0 commit comments

Comments
 (0)