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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ This Action commits the contents of your Git tag to the WordPress.org plugin rep

* `generate-zip` - Defaults to `false`. Generate a ZIP file from the SVN `trunk` directory. Outputs a `zip-path` variable for use in further workflow steps.
* `dry-run` - Defaults to `false`. Set this to `true` if you want to skip the final Subversion commit step (e.g., to debug prior to a non-dry-run commit). `dry-run` - `true` Doesn't require SVN secret.
* `trunk-only` - Defaults to `false`. When set to `true`, deploys only to the WordPress.org `trunk` and `assets` directories without creating a new tag in the plugin repository. Useful for updating `readme.txt` (for example, the `Tested up to` value) or assets between full releases.

### Outputs

Expand Down Expand Up @@ -84,6 +85,7 @@ Current set of example workflow files:
```

* [Deploy on pushing a new tag and create release with attached ZIP](examples/deploy-on-pushing-a-new-tag-and-create-release-with-attached-zip.yml)
* [Deploy to both trunk and tag during release, and only to trunk during commits to the main branch](examples/deploy-on-tag-and-branch.yml)

## Contributing

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ inputs:
dry-run:
description: 'Run the deployment process without committing.'
default: false
trunk-only:
description: 'Deploy only to trunk/assets without creating a new tag.'
default: false
outputs:
zip-path:
description: 'Path to zip file'
Expand All @@ -22,5 +25,6 @@ runs:
env:
INPUT_GENERATE_ZIP: ${{ inputs.generate-zip }}
INPUT_DRY_RUN: ${{ inputs.dry-run }}
INPUT_TRUNK_ONLY: ${{ inputs.trunk-only }}
run: ${{ github.action_path }}/deploy.sh
shell: bash
38 changes: 30 additions & 8 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,23 @@ if [[ -z "$SLUG" ]]; then
fi
echo "ℹ︎ SLUG is $SLUG"

# Allow setting custom version number in advanced workflows
if [[ -z "$VERSION" ]]; then
# Allow setting custom version number in advanced workflows.
# By default, only derive VERSION from tag refs; branch refs will
# result in an empty VERSION so we can support trunk-only deployments.
if [[ -z "$VERSION" && "$GITHUB_REF" == refs/tags/* ]]; then
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attempt to resolve the version from tag name only if this is a tag CI run.

VERSION="${GITHUB_REF#refs/tags/}"
VERSION="${VERSION#v}"
fi
echo "ℹ︎ VERSION is $VERSION"
if [[ -n "$VERSION" ]]; then
echo "ℹ︎ VERSION is $VERSION"
else
echo "ℹ︎ VERSION is not set; trunk-only deployment assumed unless overridden."
fi

# Cast to empty string when not set for easier -n checks.
if [[ "$INPUT_TRUNK_ONLY" != "true" ]]; then
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid repeating "$INPUT_TRUNK_ONLY" != "true" on every conditional we normalize this to an empty string if the value is NOT true.

INPUT_TRUNK_ONLY=""
fi

if [[ -z "$ASSETS_DIR" ]]; then
ASSETS_DIR=".wordpress-org"
Expand Down Expand Up @@ -118,7 +129,9 @@ generate_zip() {
}

# Bail early if the plugin version is already published.
if [[ -d "tags/$VERSION" ]]; then
# Only relevant when we are creating a new tag, not for
# trunk-only deployments where VERSION may be empty.
if [[ -n "$VERSION" && -d "tags/$VERSION" && -z "$INPUT_TRUNK_ONLY" ]]; then
echo "ℹ︎ Version $VERSION of plugin $SLUG was already published";

generate_zip
Expand Down Expand Up @@ -203,9 +216,12 @@ svn add . --force > /dev/null
# Also suppress stdout here
svn status | grep '^\!' | sed 's/! *//' | xargs -I% svn rm %@ > /dev/null

# Copy tag locally to make this a single commit
echo "➤ Copying tag..."
svn cp "trunk" "tags/$VERSION"
# Copy tag locally to make this a single commit when not
# doing a trunk-only deployment.
if [[ -n "$VERSION" && -z "$INPUT_TRUNK_ONLY" ]]; then
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the core change -- we only add a tag if this is not a trunk-only release.

echo "➤ Copying tag..."
svn cp "trunk" "tags/$VERSION"
fi

# Fix screenshots getting force downloaded when clicking them
# https://developer.wordpress.org/plugins/wordpress-org/plugin-assets/
Expand All @@ -231,7 +247,13 @@ if $INPUT_DRY_RUN; then
echo "➤ Dry run: Files not committed."
else
echo "➤ Committing files..."
svn commit -m "Update to version $VERSION from GitHub" --no-auth-cache --non-interactive --username "$SVN_USERNAME" --password "$SVN_PASSWORD"

COMMIT_MSG="Update from GitHub"
if [[ -n "$VERSION" && -z "$INPUT_TRUNK_ONLY" ]]; then
COMMIT_MSG="Update to version $VERSION from GitHub"
fi

svn commit -m "$COMMIT_MSG" --no-auth-cache --non-interactive --username "$SVN_USERNAME" --password "$SVN_PASSWORD"
fi

generate_zip
Expand Down
28 changes: 28 additions & 0 deletions examples/deploy-on-tag-and-branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Deploy readme and assets to WordPress.org
on:
push:
branches:
# Or use your primary branch name, e.g. main, trunk, master
- main
tags:
# On all tags.
jobs:
trunk_only_deploy:
name: Trunk-only deploy
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
# Optional build step; remove or customize as needed.
- name: Build
run: |
npm install
npm run build
# Deploy to both tags and trunk on tag, or only to trunk on main branch.
- name: WordPress Plugin Deploy
uses: 10up/action-wordpress-plugin-deploy@stable
with:
trunk-only: ${{ github.ref_name == 'main' }}
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we use the same deploy step on both branch and tag runs:

  1. Tag CI runs will set trunk-only to false which enables regular deploys.
  2. Branch CI runs on trunk branch will deploy to trunk/assets only.

env:
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}