Skip to content
Snippets Groups Projects
Commit 635e9700 authored by Erick Hitter's avatar Erick Hitter
Browse files

Add support for WP.org's static assets

parent b22e190a
No related branches found
No related tags found
1 merge request!7Add support for WP.org's static assets
Pipeline #809 passed
......@@ -40,8 +40,9 @@ Set the following environment variables in the GitLab project's configuration:
* `PLUGIN_SLUG` - plugin's name on WordPress.org
* `PLUGIN_VERSION` - version to tag
* `WP_ORG_RELEASE_REF` - git commit ref (branch or tag) to use for release
* `WP_ORG_ASSETS_DIR` - directory name, relative to repo root, where screenshots and other static assets are held
### Alternatives
### Alternate loading method
A [loader script](./scripts/loader.sh) is available as an alternative to downloading the deploy script during the `before_script` stage.
......@@ -56,6 +57,15 @@ A sample is provided in [examples/gitattributes](./examples/gitattributes). If u
/.gitattributes export-ignore
```
## Deploying assets for WordPress.org
WordPress.org's plugins directory allows plugins to provide various static assets, which are not bundled in the downloadable plugin, rather only being used to enhance the visitor experience when browsing plugins. More details can be found at [https://developer.wordpress.org/plugins/wordpress-org/plugin-assets/](https://developer.wordpress.org/plugins/wordpress-org/plugin-assets/).
As the SVN `assets` directory exists outside of the directories used for plugin files, the handling of static assets in git requires a small bit of setup:
1. In the repository root, create a directory named `.wordpress-org`; alternatively, specify a custom path using the `WP_ORG_ASSETS_DIR` environment variable.
1. Commit to the `WP_ORG_ASSETS_DIR` directory in git any screenshots or other static assets that should be added to the plugin's `assets` directory in SVN.
## Protecting deploys
Choose a `WP_ORG_RELEASE_REF` value that starts with a consistent prefix. Doing so allows that prefix to be protected using GitLab's "Protected Branches" or "Protected Tags" features.
......@@ -6,38 +6,47 @@
# it does not exit with a 0, and I only care about the final exit.
set -eo
# Ensure SVN username and password are set
# IMPORTANT: while secrets are encrypted and not viewable in the GitHub UI,
# they are by necessity provided as plaintext in the context of the Action,
# so do not echo or use debug mode unless you want your secrets exposed!
# Provide a basic version identifier, particularly since this script
# is usually accessed via CDN.
echo "ℹ︎ WP-ORG-PLUGIN-DEPLOY VERSION: 2019041401"
if [[ -z "$CI" ]]; then
echo "Script is only to be run by GitLab CI" 1>&2
echo "𝘅︎ Script is only to be run by GitLab CI" 1>&2
exit 1
fi
# Ensure certain environment variables are set
# IMPORTANT: while access to secrets is restricted in the GitLab UI,
# they are by necessity provided as plaintext in the context of this script,
# so do not echo or use debug mode unless you want your secrets exposed!
if [[ -z "$WP_ORG_USERNAME" ]]; then
echo "WordPress.org username not set" 1>&2
echo "𝘅︎ WordPress.org username not set" 1>&2
exit 1
fi
if [[ -z "$WP_ORG_PASSWORD" ]]; then
echo "WordPress.org password not set" 1>&2
echo "𝘅︎ WordPress.org password not set" 1>&2
exit 1
fi
if [[ -z "$PLUGIN_SLUG" ]]; then
echo "Plugin's SVN slug is not set" 1>&2
echo "𝘅︎ Plugin's SVN slug is not set" 1>&2
exit 1
fi
if [[ -z "$PLUGIN_VERSION" ]]; then
echo "Plugin's version is not set" 1>&2
echo "𝘅︎ Plugin's version is not set" 1>&2
exit 1
fi
if [[ -z "$WP_ORG_ASSETS_DIR" ]]; then
WP_ORG_ASSETS_DIR=".wordpress-org"
fi
echo "ℹ︎ PLUGIN_SLUG: $PLUGIN_SLUG"
echo "ℹ︎ PLUGIN_VERSION: $PLUGIN_VERSION"
echo "ℹ︎ WP_ORG_RELEASE_REF: $WP_ORG_RELEASE_REF"
echo "ℹ︎ WP_ORG_ASSETS_DIR: $WP_ORG_ASSETS_DIR"
SVN_URL="https://plugins.svn.wordpress.org/${PLUGIN_SLUG}/"
SVN_DIR="$CI_BUILDS_DIR/svn-${PLUGIN_SLUG}"
......@@ -47,6 +56,7 @@ TMP_DIR="$CI_BUILDS_DIR/git-archive"
echo "➤ Checking out dotorg repository..."
svn checkout --depth immediates "$SVN_URL" "$SVN_DIR"
cd "$SVN_DIR"
svn update --set-depth infinity assets
svn update --set-depth infinity trunk
svn update --set-depth infinity "tags/${PLUGIN_VERSION}"
......@@ -60,9 +70,10 @@ git config --global user.name "Erick Hitter (GitLab CI)"
# If there's no .gitattributes file, write a default one into place
if [[ ! -e "$CI_PROJECT_DIR/.gitattributes" ]]; then
cat > "$CI_PROJECT_DIR/.gitattributes" <<-EOL
/${WP_ORG_ASSETS_DIR} export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.github export-ignore
/.gitlab-ci.yml export-ignore
EOL
# The .gitattributes file has to be committed to be used
......@@ -80,6 +91,9 @@ cd "$SVN_DIR"
# The --delete flag will delete anything in destination that no longer exists in source
rsync -r "$TMP_DIR/" trunk/ --delete
# Copy dotorg assets to /assets
rsync -r "${CI_PROJECT_DIR}/${WP_ORG_ASSETS_DIR}/" assets/ --delete
# Add everything and commit to SVN
# The force flag ensures we recurse into subdirectories even if they are already added
# Suppress stdout in favor of svn status later for readability
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment