Skip to content

Release & Deploy

Release & Deploy #36

name: Release & Deploy
on:
workflow_run:
workflows: ["CI"]
types: [completed]
branches: [main]
workflow_dispatch:
jobs:
release:
name: Release & Deploy to WP.org
runs-on: ubuntu-latest
if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Read version from spotmap.php
id: version
run: |
VERSION=$(grep -oP "Version:\s+\K\S+" spotmap.php | head -1)
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Detected version: $VERSION"
if [ -z "$VERSION" ]; then
echo "::error::Could not extract version from spotmap.php"
exit 1
fi
if echo "$VERSION" | grep -qP '[a-zA-Z]'; then
echo "is_prerelease=true" >> "$GITHUB_OUTPUT"
else
echo "is_prerelease=false" >> "$GITHUB_OUTPUT"
fi
- name: Check if tag already exists
id: tag_check
run: |
if git ls-remote --tags origin "refs/tags/${{ steps.version.outputs.version }}" | grep -q .; then
echo "exists=true" >> "$GITHUB_OUTPUT"
echo "Tag ${{ steps.version.outputs.version }} already exists — skipping."
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Claim git tag (lock against concurrent runs)
if: steps.tag_check.outputs.exists == 'false'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag "${{ steps.version.outputs.version }}"
git push origin "${{ steps.version.outputs.version }}"
# If a concurrent run already pushed this tag, the push above fails
# and the job exits here — before wasting time on the build.
- name: Download build artifact
if: steps.tag_check.outputs.exists == 'false' && github.event_name == 'workflow_run'
uses: actions/download-artifact@v8
with:
name: js-build
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Node
if: steps.tag_check.outputs.exists == 'false'
uses: actions/setup-node@v6
with:
node-version: '20'
cache: 'npm'
- name: Install JS dependencies
if: steps.tag_check.outputs.exists == 'false'
run: npm ci
- name: Install PHP dependencies
if: steps.tag_check.outputs.exists == 'false'
run: composer install --no-dev --optimize-autoloader --ignore-platform-reqs
- name: Start wp-env
if: steps.tag_check.outputs.exists == 'false'
run: npm run wp-env start
- name: Build
if: steps.tag_check.outputs.exists == 'false' && github.event_name == 'workflow_dispatch'
run: npm run build
- name: Extract release notes
if: steps.tag_check.outputs.exists == 'false' && steps.version.outputs.is_prerelease == 'false'
id: release_notes
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
# Strip -rc.N / -beta.N etc. to get the base version for changelog lookup
BASE_VERSION=$(echo "$VERSION" | sed 's/-.*//')
NOTES=$(awk "/^### ${BASE_VERSION}$/{found=1; next} found && /^### /{exit} found{print}" pluginreadme.md | sed '/^[[:space:]]*$/d')
if [ -z "$NOTES" ]; then
NOTES="See [pluginreadme.md](https://github.com/techtimo/Spotmap/blob/main/pluginreadme.md) for the full changelog."
fi
echo "notes<<EOF" >> "$GITHUB_OUTPUT"
echo "$NOTES" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
- name: Package plugin zip
if: steps.tag_check.outputs.exists == 'false'
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
mv pluginreadme.md readme.txt
npx wp-scripts plugin-zip
mv spotmap.zip spotmap-${VERSION}.zip
# Build and composer install are done in prior steps; skip them here
- name: Extract zip for SVN
if: steps.tag_check.outputs.exists == 'false'
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
mkdir -p /tmp/plugin-build
unzip -q spotmap-${VERSION}.zip -d /tmp/plugin-build
- name: Deploy to WordPress.org SVN
if: steps.tag_check.outputs.exists == 'false' && steps.version.outputs.is_prerelease == 'false'
env:
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
VERSION: ${{ steps.version.outputs.version }}
run: |
svn checkout --depth immediates \
"https://plugins.svn.wordpress.org/spotmap" /tmp/svn
# Sync trunk
svn update --set-depth infinity /tmp/svn/trunk
rsync -rc --delete --delete-excluded /tmp/plugin-build/spotmap/ /tmp/svn/trunk/
# Stage all changes
cd /tmp/svn
svn add --force . 2>/dev/null || true
svn status | grep '^!' | awk '{print $2}' | xargs -r svn delete --force
# Create version tag from trunk
if svn info "https://plugins.svn.wordpress.org/spotmap/tags/$VERSION" 2>/dev/null; then
echo "SVN tag $VERSION already exists, skipping tag creation."
else
svn copy trunk "tags/$VERSION"
fi
svn update
svn commit \
--username "$SVN_USERNAME" \
--password "$SVN_PASSWORD" \
--no-auth-cache \
--non-interactive \
-m "Release $VERSION"
- name: Create GitHub release (pre-release)
if: steps.tag_check.outputs.exists == 'false' && steps.version.outputs.is_prerelease == 'true'
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ steps.version.outputs.version }}
name: Spotmap ${{ steps.version.outputs.version }}
prerelease: true
generate_release_notes: true
files: spotmap-${{ steps.version.outputs.version }}.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create GitHub release (stable)
if: steps.tag_check.outputs.exists == 'false' && steps.version.outputs.is_prerelease == 'false'
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ steps.version.outputs.version }}
name: Spotmap ${{ steps.version.outputs.version }}
prerelease: false
body: ${{ steps.release_notes.outputs.notes }}
files: spotmap-${{ steps.version.outputs.version }}.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}