Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 27 additions & 34 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
name: Version and Release

on:
release:
types: [created]
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g., 1.2.3 or v1.2.3)'
required: true
type: string

jobs:
version-and-release:
Expand All @@ -12,77 +16,66 @@ jobs:
contents: write

steps:
- name: Checkout code at tag
- name: Checkout release branch
uses: actions/checkout@v4
with:
ref: ${{ github.event.release.tag_name }}
ref: release
fetch-depth: 0

- name: Get version from tag
- name: Normalise version
id: get_version
run: |
# Extract version from tag (remove 'v' prefix if present)
TAG_NAME="${{ github.event.release.tag_name }}"
VERSION="${TAG_NAME#v}"

INPUT="${{ inputs.version }}"
VERSION="${INPUT#v}"
TAG="v${VERSION}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=$TAG_NAME" >> $GITHUB_OUTPUT
echo "Version: $VERSION"
echo "Tag: $TAG_NAME"
echo "tag=$TAG" >> $GITHUB_OUTPUT

- name: Replace __VERSION__ in plugin file
run: |
sed -i "s/__VERSION__/${{ steps.get_version.outputs.version }}/g" hm-query-loop.php
echo "Updated plugin header:"
cat hm-query-loop.php | grep "Version:"
echo "Updated version constant:"
cat hm-query-loop.php | grep "HM_QUERY_LOOP_VERSION"
grep "Version:" hm-query-loop.php
grep "HM_QUERY_LOOP_VERSION" hm-query-loop.php

- name: Commit version changes to tag
- name: Commit version and create tag
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"

# Add and commit the versioned file
git add hm-query-loop.php
git commit -m "Update version to ${{ steps.get_version.outputs.version }}"
git push origin release

# Delete the old tag and create a new one pointing to the new commit
git tag -d "${{ steps.get_version.outputs.tag }}"
# Tag is created once, after the version commit — never force-pushed.
git tag -a "${{ steps.get_version.outputs.tag }}" -m "Release ${{ steps.get_version.outputs.tag }}"

# Force push the updated tag
git push origin "${{ steps.get_version.outputs.tag }}" --force
git push origin "${{ steps.get_version.outputs.tag }}"

- name: Create ZIP archive
run: |
mkdir -p release
mkdir -p release-zip

# Create a clean copy excluding dev files
rsync -av --exclude='.git' \
--exclude='.github' \
--exclude='node_modules' \
--exclude='src' \
--exclude='release' \
--exclude='release-zip' \
--exclude='.gitignore' \
--exclude='.gitattributes' \
--exclude='package.json' \
--exclude='package-lock.json' \
--exclude='RELEASE.md' \
./ release/hm-query-loop/
./ release-zip/hm-query-loop/

# Create ZIP
cd release
cd release-zip
zip -r "hm-query-loop-${{ steps.get_version.outputs.tag }}.zip" hm-query-loop/
cd ..

echo "Created: release/hm-query-loop-${{ steps.get_version.outputs.tag }}.zip"

- name: Upload ZIP to release
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.event.release.tag_name }}
tag_name: ${{ steps.get_version.outputs.tag }}
name: ${{ steps.get_version.outputs.tag }}
files: |
release/hm-query-loop-${{ steps.get_version.outputs.tag }}.zip
release-zip/hm-query-loop-${{ steps.get_version.outputs.tag }}.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22 changes: 10 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,18 @@ This plugin uses GitHub Actions for automated versioning and release asset creat

### Creating a Release

1. Make sure the `release` branch is built and ready (assets should be in the `build/` directory)
2. Go to the GitHub repository and create a new release:
- Click "Releases" → "Draft a new release"
- Create a new tag (e.g., `v1.2.3`) from the `release` branch
- Add release title and notes
- Click "Publish release"
3. The GitHub Action will automatically:
- Checkout the code at the tag you created
1. Make sure the `release` branch is up to date (a push to `main` triggers the build workflow that keeps it current).
2. Go to the GitHub repository → **Actions** → **Version and Release** → **Run workflow**.
3. Enter the version number (e.g., `1.2.3` or `v1.2.3`) and click **Run workflow**.
4. The workflow will:
- Replace `__VERSION__` placeholders with the actual version number
- Commit the versioned file back to the tag
- Create a production-ready ZIP file (excluding dev files)
- Upload the ZIP as a release asset
- Commit the versioned file to the `release` branch
- Create and push the tag from that commit
- Create a GitHub Release with a production-ready ZIP (excluding dev files)

The tag version (e.g., `v1.2.3`) will be used as the plugin version. The version number should follow semantic versioning.
The tag version (e.g., `v1.2.3`) will be used as the plugin version. Follow semantic versioning.

> **Note:** The tag is created *after* the version commit so it is never moved or force-pushed. This is required to keep Packagist consistent — Packagist blocks versions where the tag is re-pointed to a different commit.

## License

Expand Down
Loading