Skip to content
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ This Action commits the contents of your Git tag to the WordPress.org plugin rep
* `SLUG` - defaults to the repository name, customizable in case your WordPress repository has a different slug or is capitalized differently.
* `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`).
* `BUILD_DIR` - defaults to `false`. Set this flag to the directory where you build your plugins files into, then the action will copy and deploy files from that directory. Both absolute and relative paths are supported. The relative path if provided will be concatenated with the repository root directory. All files and folders in the build directory will be deployed, `.disignore` or `.gitattributes` will be ignored.

### Inputs
* `generate-zip` - Generate a ZIP file from the SVN `trunk` directory. Outputs a `zip-path` variable for use in further workflow steps. Defaults to false.
Expand Down
99 changes: 59 additions & 40 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ if [[ -z "$ASSETS_DIR" ]]; then
fi
echo "ℹ︎ ASSETS_DIR is $ASSETS_DIR"

if [[ -z "$BUILD_DIR" ]] || [[ $BUILD_DIR == "./" ]]; then
BUILD_DIR=false
elif [[ $BUILD_DIR == ./* ]]; then
BUILD_DIR=${BUILD_DIR:2}
fi

if [[ "$BUILD_DIR" != false ]]; then
if [[ $BUILD_DIR != /* ]]; then
BUILD_DIR="${GITHUB_WORKSPACE%/}/${BUILD_DIR}"
fi
echo "ℹ︎ BUILD_DIR is $BUILD_DIR"
fi

SVN_URL="https://plugins.svn.wordpress.org/${SLUG}/"
SVN_DIR="${HOME}/svn-${SLUG}"

Expand All @@ -49,47 +62,53 @@ cd "$SVN_DIR"
svn update --set-depth infinity assets
svn update --set-depth infinity trunk

echo "➤ Copying files..."
if [[ -e "$GITHUB_WORKSPACE/.distignore" ]]; then
echo "ℹ︎ Using .distignore"
# Copy from current branch to /trunk, excluding dotorg assets
# The --delete flag will delete anything in destination that no longer exists in source
rsync -rc --exclude-from="$GITHUB_WORKSPACE/.distignore" "$GITHUB_WORKSPACE/" trunk/ --delete --delete-excluded
else
echo "ℹ︎ Using .gitattributes"

cd "$GITHUB_WORKSPACE"

# "Export" a cleaned copy to a temp directory
TMP_DIR="${HOME}/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 clean copy to /trunk, excluding dotorg assets
# The --delete flag will delete anything in destination that no longer exists in source
rsync -rc "$TMP_DIR/" trunk/ --delete --delete-excluded
if [[ "$BUILD_DIR" = false ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if BUILD_DIR = `` (empty string) or ./ (relative directory same as github repo's root directory?

What should happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In 43e313a I cover more possible value of BUILD_DIR:

  • ./
  • ./some/directory

The empty string case is handled already by [[ -z "$BUILD_DIR" ]] which returns true if BUILD_DIR is unset or set to the empty string.

IMO, BUILD_DIR is set by users so ultimately, it's users' responsibility to set the correct value for it. We already cover common use-cases in this PR.

echo "➤ Copying files..."
if [[ -e "$GITHUB_WORKSPACE/.distignore" ]]; then
echo "ℹ︎ Using .distignore"
# Copy from current branch to /trunk, excluding dotorg assets
# The --delete flag will delete anything in destination that no longer exists in source
rsync -rc --exclude-from="$GITHUB_WORKSPACE/.distignore" "$GITHUB_WORKSPACE/" trunk/ --delete --delete-excluded
else
echo "ℹ︎ Using .gitattributes"

cd "$GITHUB_WORKSPACE"

# "Export" a cleaned copy to a temp directory
TMP_DIR="${HOME}/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
Comment on lines +86 to +98
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be worth ignoring .gitignore and .gitattributes in the build directory. They can be placed anywhere in a repo.

I am undecided, can you tell me why you decided not to do so?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@peterwilsoncc I decided not to use .disignore or .gitattributes because I assume that if plugin authors use BUILD_DIR, they are using a command/script to build the plugin, so anything inside BUILD_DIR is meant to be deployed. They have control over any files copied to that folder. Using .disignore or .gitattributes here can cause confusions IMO.


# 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 clean copy to /trunk, excluding dotorg assets
# The --delete flag will delete anything in destination that no longer exists in source
rsync -rc "$TMP_DIR/" trunk/ --delete --delete-excluded
fi
else
echo "ℹ︎ Copying files from build directory..."
rsync -rc "$BUILD_DIR" trunk/ --delete --delete-excluded
fi

# Copy dotorg assets to /assets
Expand Down