Skip to content

Commit 472a77d

Browse files
committed
Initial commit after split from https://github.com/10up/actions-wordpress
1 parent 47c5a4a commit 472a77d

3 files changed

Lines changed: 186 additions & 2 deletions

File tree

Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM debian:stable-slim
2+
3+
LABEL "com.github.actions.name"="WordPress Plugin Deploy"
4+
LABEL "com.github.actions.description"="Deploy to the WordPress Plugin Repository"
5+
LABEL "com.github.actions.icon"="upload-cloud"
6+
LABEL "com.github.actions.color"="blue"
7+
8+
LABEL maintainer="Helen Hou-Sandí <helen.y.hou@gmail.com>"
9+
LABEL version="1.2.1"
10+
LABEL repository="http://github.com/helen/action-wordpress-plugin-deploy"
11+
12+
RUN apt-get update \
13+
&& apt-get install -y subversion rsync git \
14+
&& apt-get clean -y \
15+
&& rm -rf /var/lib/apt/lists/* \
16+
&& git config --global user.email "10upbot+github@10up.com" \
17+
&& git config --global user.name "10upbot on GitHub"
18+
19+
COPY entrypoint.sh /entrypoint.sh
20+
ENTRYPOINT ["/entrypoint.sh"]

README.md

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,54 @@
1-
# action-wordpress-plugin-deploy
2-
Deploy your plugin to the WordPress.org repository using GitHub Actions
1+
# WordPress.org Plugin Deploy
2+
3+
This Action commits the contents of your Git tag to the WordPress.org plugin repository using the same tag name. It excludes files in `.git` and `.github` subdirectories and moves anything from a `.wordpress-org` subdirectory to the top-level `assets` directory in Subversion (plugin banners, icons, and screenshots).
4+
5+
## Configuration
6+
7+
### Required secrets
8+
* `SVN_USERNAME`
9+
* `SVN_PASSWORD`
10+
* `GITHUB_TOKEN` - you do not need to generate one but you do have to explicitly make it available to the Action
11+
12+
Secrets can be set while editing your workflow or in the repository settings. They cannot be viewed once stored. [GitHub secrets documentation](https://developer.github.com/actions/creating-workflows/storing-secrets/)
13+
14+
### Optional environment variables
15+
* `SLUG` - defaults to the respository name, customizable in case your WordPress repository has a different slug. This should be a very rare case as WordPress assumes that the directory and initial plugin file have the same slug.
16+
* `VERSION` - defaults to the tag name; do not recommend setting this except for testing purposes
17+
* `ASSETS_DIR` - defaults to `.wordpress-org`, customizable for other locations of WordPress.org plugin repository-specific assets that belong in the top-level `assets` directory (the one on the same level as `trunk`)
18+
19+
### Known issues
20+
* Currently the `tags` filter on the `push` action does not seem to work correctly, so we target the `refs/tags/*` naming of a branch instead. Ideally for readability and correctness this would use something like `tags: - *`.
21+
22+
## Example Workflow File
23+
```
24+
name: Deploy to WordPress.org
25+
on:
26+
push:
27+
branches:
28+
- refs/tags/*
29+
jobs:
30+
tag:
31+
name: New tag
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/checkout@master
35+
- name: WordPress Plugin Deploy
36+
uses: 10up/action-wordpress-plugin-deploy@master
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
40+
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
41+
SLUG: my-super-cool-plugin
42+
```
43+
44+
## Contributing
45+
Want to help? Check out our [contributing guidelines](../CONTRIBUTING.md) to get started.
46+
47+
<p align="center">
48+
<a href="http://10up.com/contact/"><img src="https://10updotcom-wpengine.s3.amazonaws.com/uploads/2016/10/10up-Github-Banner.png" width="850"></a>
49+
</p>
50+
51+
## License
52+
53+
Our GitHub Actions are available for use and remix under the MIT license.
54+

entrypoint.sh

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/bin/bash
2+
3+
# Note that this does not use pipefail
4+
# because if the grep later doesn't match any deleted files,
5+
# which is likely the majority case,
6+
# it does not exit with a 0, and I only care about the final exit.
7+
set -eo
8+
9+
# Ensure SVN username and password are set
10+
# IMPORTANT: while secrets are encrypted and not viewable in the GitHub UI,
11+
# they are by necessity provided as plaintext in the context of the Action,
12+
# so do not echo or use debug mode unless you want your secrets exposed!
13+
if [[ -z "$SVN_USERNAME" ]]; then
14+
echo "Set the SVN_USERNAME secret"
15+
exit 1
16+
fi
17+
18+
if [[ -z "$SVN_PASSWORD" ]]; then
19+
echo "Set the SVN_PASSWORD secret"
20+
exit 1
21+
fi
22+
23+
if [[ -z "$GITHUB_TOKEN" ]]; then
24+
echo "Set the GITHUB_TOKEN env variable"
25+
exit 1
26+
fi
27+
28+
# Allow some ENV variables to be customized
29+
if [[ -z "$SLUG" ]]; then
30+
SLUG=${GITHUB_REPOSITORY#*/}
31+
fi
32+
echo "ℹ︎ SLUG is $SLUG"
33+
34+
# Does it even make sense for VERSION to be editable in a workflow definition?
35+
if [[ -z "$VERSION" ]]; then
36+
VERSION=${GITHUB_REF#refs/tags/}
37+
fi
38+
echo "ℹ︎ VERSION is $VERSION"
39+
40+
if [[ -z "$ASSETS_DIR" ]]; then
41+
ASSETS_DIR=".wordpress-org"
42+
fi
43+
echo "ℹ︎ ASSETS_DIR is $ASSETS_DIR"
44+
45+
SVN_URL="http://plugins.svn.wordpress.org/${SLUG}/"
46+
SVN_DIR="/github/svn-${SLUG}"
47+
48+
# Checkout just trunk and assets for efficiency
49+
# Tagging will be handled on the SVN level
50+
echo "➤ Checking out .org repository..."
51+
svn checkout --depth immediates "$SVN_URL" "$SVN_DIR"
52+
cd "$SVN_DIR"
53+
svn update --set-depth infinity assets
54+
svn update --set-depth infinity trunk
55+
56+
echo "➤ Copying files..."
57+
cd "$GITHUB_WORKSPACE"
58+
59+
# "Export" a cleaned copy to a temp directory
60+
TMP_DIR="/github/archivetmp"
61+
mkdir "$TMP_DIR"
62+
63+
git config --global user.email "10upbot+github@10up.com"
64+
git config --global user.name "10upbot on GitHub"
65+
66+
# If there's no .gitattributes file, write a default one into place
67+
if [[ ! -e "$GITHUB_WORKSPACE/.gitattributes" ]]; then
68+
cat > "$GITHUB_WORKSPACE/.gitattributes" <<-EOL
69+
/$ASSETS_DIR export-ignore
70+
/.gitattributes export-ignore
71+
/.gitignore export-ignore
72+
/.github export-ignore
73+
EOL
74+
75+
# Ensure we are in the $GITHUB_WORKSPACE directory, just in case
76+
# The .gitattributes file has to be committed to be used
77+
# Just don't push it to the origin repo :)
78+
git add .gitattributes && git commit -m "Add .gitattributes file"
79+
fi
80+
81+
# This will exclude everything in the .gitattributes file with the export-ignore flag
82+
git archive HEAD | tar x --directory="$TMP_DIR"
83+
84+
cd "$SVN_DIR"
85+
86+
# Copy from clean copy to /trunk, excluding dotorg assets
87+
# The --delete flag will delete anything in destination that no longer exists in source
88+
rsync -rc "$TMP_DIR/" trunk/ --delete
89+
90+
# Copy dotorg assets to /assets
91+
rsync -rc "$GITHUB_WORKSPACE/$ASSETS_DIR/" assets/ --delete
92+
93+
# Add everything and commit to SVN
94+
# The force flag ensures we recurse into subdirectories even if they are already added
95+
# Suppress stdout in favor of svn status later for readability
96+
echo "➤ Preparing files..."
97+
svn add . --force > /dev/null
98+
99+
# SVN delete all deleted files
100+
# Also suppress stdout here
101+
svn status | grep '^\!' | sed 's/! *//' | xargs -I% svn rm % > /dev/null
102+
103+
# Copy tag locally to make this a single commit
104+
echo "➤ Copying tag..."
105+
svn cp "trunk" "tags/$VERSION"
106+
107+
svn status
108+
109+
echo "➤ Committing files..."
110+
svn commit -m "Update to version $VERSION from GitHub" --no-auth-cache --non-interactive --username "$SVN_USERNAME" --password "$SVN_PASSWORD"
111+
112+
echo "✓ Plugin deployed!"

0 commit comments

Comments
 (0)