Skip to content

Commit 2a5e2c1

Browse files
authored
Merge pull request #83 from 10up/fix/custom-build-dir
Fix: Deploy a specific directory within repository
2 parents d515ea0 + 43e313a commit 2a5e2c1

2 files changed

Lines changed: 60 additions & 40 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ This Action commits the contents of your Git tag to the WordPress.org plugin rep
2222
* `SLUG` - defaults to the repository name, customizable in case your WordPress repository has a different slug or is capitalized differently.
2323
* `VERSION` - defaults to the tag name; do not recommend setting this except for testing purposes.
2424
* `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`).
25+
* `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.
2526

2627
### Inputs
2728
* `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.

deploy.sh

Lines changed: 59 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ if [[ -z "$ASSETS_DIR" ]]; then
3838
fi
3939
echo "ℹ︎ ASSETS_DIR is $ASSETS_DIR"
4040

41+
if [[ -z "$BUILD_DIR" ]] || [[ $BUILD_DIR == "./" ]]; then
42+
BUILD_DIR=false
43+
elif [[ $BUILD_DIR == ./* ]]; then
44+
BUILD_DIR=${BUILD_DIR:2}
45+
fi
46+
47+
if [[ "$BUILD_DIR" != false ]]; then
48+
if [[ $BUILD_DIR != /* ]]; then
49+
BUILD_DIR="${GITHUB_WORKSPACE%/}/${BUILD_DIR}"
50+
fi
51+
echo "ℹ︎ BUILD_DIR is $BUILD_DIR"
52+
fi
53+
4154
SVN_URL="https://plugins.svn.wordpress.org/${SLUG}/"
4255
SVN_DIR="${HOME}/svn-${SLUG}"
4356

@@ -49,47 +62,53 @@ cd "$SVN_DIR"
4962
svn update --set-depth infinity assets
5063
svn update --set-depth infinity trunk
5164

52-
echo "➤ Copying files..."
53-
if [[ -e "$GITHUB_WORKSPACE/.distignore" ]]; then
54-
echo "ℹ︎ Using .distignore"
55-
# Copy from current branch to /trunk, excluding dotorg assets
56-
# The --delete flag will delete anything in destination that no longer exists in source
57-
rsync -rc --exclude-from="$GITHUB_WORKSPACE/.distignore" "$GITHUB_WORKSPACE/" trunk/ --delete --delete-excluded
58-
else
59-
echo "ℹ︎ Using .gitattributes"
60-
61-
cd "$GITHUB_WORKSPACE"
62-
63-
# "Export" a cleaned copy to a temp directory
64-
TMP_DIR="${HOME}/archivetmp"
65-
mkdir "$TMP_DIR"
66-
67-
git config --global user.email "10upbot+github@10up.com"
68-
git config --global user.name "10upbot on GitHub"
69-
70-
# If there's no .gitattributes file, write a default one into place
71-
if [[ ! -e "$GITHUB_WORKSPACE/.gitattributes" ]]; then
72-
cat > "$GITHUB_WORKSPACE/.gitattributes" <<-EOL
73-
/$ASSETS_DIR export-ignore
74-
/.gitattributes export-ignore
75-
/.gitignore export-ignore
76-
/.github export-ignore
77-
EOL
78-
79-
# Ensure we are in the $GITHUB_WORKSPACE directory, just in case
80-
# The .gitattributes file has to be committed to be used
81-
# Just don't push it to the origin repo :)
82-
git add .gitattributes && git commit -m "Add .gitattributes file"
83-
fi
84-
85-
# This will exclude everything in the .gitattributes file with the export-ignore flag
86-
git archive HEAD | tar x --directory="$TMP_DIR"
87-
88-
cd "$SVN_DIR"
8965

90-
# Copy from clean copy to /trunk, excluding dotorg assets
91-
# The --delete flag will delete anything in destination that no longer exists in source
92-
rsync -rc "$TMP_DIR/" trunk/ --delete --delete-excluded
66+
if [[ "$BUILD_DIR" = false ]]; then
67+
echo "➤ Copying files..."
68+
if [[ -e "$GITHUB_WORKSPACE/.distignore" ]]; then
69+
echo "ℹ︎ Using .distignore"
70+
# Copy from current branch to /trunk, excluding dotorg assets
71+
# The --delete flag will delete anything in destination that no longer exists in source
72+
rsync -rc --exclude-from="$GITHUB_WORKSPACE/.distignore" "$GITHUB_WORKSPACE/" trunk/ --delete --delete-excluded
73+
else
74+
echo "ℹ︎ Using .gitattributes"
75+
76+
cd "$GITHUB_WORKSPACE"
77+
78+
# "Export" a cleaned copy to a temp directory
79+
TMP_DIR="${HOME}/archivetmp"
80+
mkdir "$TMP_DIR"
81+
82+
git config --global user.email "10upbot+github@10up.com"
83+
git config --global user.name "10upbot on GitHub"
84+
85+
# If there's no .gitattributes file, write a default one into place
86+
if [[ ! -e "$GITHUB_WORKSPACE/.gitattributes" ]]; then
87+
cat > "$GITHUB_WORKSPACE/.gitattributes" <<-EOL
88+
/$ASSETS_DIR export-ignore
89+
/.gitattributes export-ignore
90+
/.gitignore export-ignore
91+
/.github export-ignore
92+
EOL
93+
94+
# Ensure we are in the $GITHUB_WORKSPACE directory, just in case
95+
# The .gitattributes file has to be committed to be used
96+
# Just don't push it to the origin repo :)
97+
git add .gitattributes && git commit -m "Add .gitattributes file"
98+
fi
99+
100+
# This will exclude everything in the .gitattributes file with the export-ignore flag
101+
git archive HEAD | tar x --directory="$TMP_DIR"
102+
103+
cd "$SVN_DIR"
104+
105+
# Copy from clean copy to /trunk, excluding dotorg assets
106+
# The --delete flag will delete anything in destination that no longer exists in source
107+
rsync -rc "$TMP_DIR/" trunk/ --delete --delete-excluded
108+
fi
109+
else
110+
echo "ℹ︎ Copying files from build directory..."
111+
rsync -rc "$BUILD_DIR" trunk/ --delete --delete-excluded
93112
fi
94113

95114
# Copy dotorg assets to /assets

0 commit comments

Comments
 (0)