Skip to content

Commit

Permalink
Configurable deploy excludes (#7)
Browse files Browse the repository at this point in the history
Uses `git archive` to respect excludes specified in a `.gitattributes` file. A default `.gitattributes` file with some very basic excludes is temporarily written into place if one is not provided.

Fixes #1
  • Loading branch information
helen authored Mar 30, 2019
1 parent 4f0a053 commit 598b157
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
6 changes: 4 additions & 2 deletions dotorg-plugin-deploy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ LABEL version="1.0.0"
LABEL repository="http://github.com/helen/actions-wordpress"

RUN apt-get update \
&& apt-get install -y subversion rsync \
&& apt-get install -y subversion rsync git \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*
&& rm -rf /var/lib/apt/lists/* \
&& git config --global user.email "[email protected]" \
&& git config --global user.name "10upbot on GitHub"

COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
5 changes: 3 additions & 2 deletions dotorg-plugin-deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ This Action commits the contents of your Git tag to the WordPress.org plugin rep
### Required secrets
* `SVN_USERNAME`
* `SVN_PASSWORD`
* `GITHUB_TOKEN` - you do not need to generate one but you do have to explicitly make it available to the Action

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/)

### Optional environment variables
* `SLUG` - defaults to the respository name, customizable in case your WordPress repository has a different slug
* `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.
* `VERSION` - defaults to the tag name; do not recommend setting this except for testing purposes
* `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`)

Expand All @@ -31,7 +32,7 @@ action "tag" {
action "WordPress Plugin Deploy" {
needs = ["tag"]
uses = "10up/actions-wordpress/dotorg-plugin-deploy@master"
secrets = ["SVN_PASSWORD", "SVN_USERNAME"]
secrets = ["SVN_USERNAME", "SVN_PASSWORD", "GITHUB_TOKEN"]
env = {
SLUG = "my-super-cool-plugin"
}
Expand Down
37 changes: 35 additions & 2 deletions dotorg-plugin-deploy/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ if [[ -z "$SVN_PASSWORD" ]]; then
exit 1
fi

if [[ -z "$GITHUB_TOKEN" ]]; then
echo "Set the GITHUB_TOKEN env variable"
exit 1
fi

# Allow some ENV variables to be customized
if [[ -z "$SLUG" ]]; then
SLUG=${GITHUB_REPOSITORY#*/}
Expand Down Expand Up @@ -49,10 +54,38 @@ svn update --set-depth infinity assets
svn update --set-depth infinity trunk

echo "➤ Copying files..."
cd "$GITHUB_WORKSPACE"

# "Export" a cleaned copy to a temp directory
TMP_DIR="/github/archivetmp"
mkdir "$TMP_DIR"

git config --global user.email "[email protected]"
git config --global user.name "10upbot on GitHub"

# If there's no .gitattributes file, write a default one into place
if [[ ! -e "$GITHUB_WORKSPACE/.gitattributes" ]]; then
cat > "$GITHUB_WORKSPACE/.gitattributes" <<-EOL
/$ASSETS_DIR export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.github export-ignore
EOL

# Ensure we are in the $GITHUB_WORKSPACE directory, just in case
# The .gitattributes file has to be committed to be used
# Just don't push it to the origin repo :)
git add .gitattributes && git commit -m "Add .gitattributes file"
fi

# This will exclude everything in the .gitattributes file with the export-ignore flag
git archive HEAD | tar x --directory="$TMP_DIR"

cd "$SVN_DIR"

# Copy from current branch to /trunk, excluding dotorg assets
# Copy from clean copy to /trunk, excluding dotorg assets
# The --delete flag will delete anything in destination that no longer exists in source
rsync -r --exclude "/$ASSETS_DIR/" --exclude ".git/" --exclude ".github/" "$GITHUB_WORKSPACE/" trunk/ --delete
rsync -r "$TMP_DIR/" trunk/ --delete

# Copy dotorg assets to /assets
rsync -r "$GITHUB_WORKSPACE/$ASSETS_DIR/" assets/ --delete
Expand Down

0 comments on commit 598b157

Please sign in to comment.