-
Notifications
You must be signed in to change notification settings - Fork 109
Fix: Deploy a specific directory within repository #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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}" | ||
|
|
||
|
|
@@ -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 | ||
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be worth ignoring I am undecided, can you tell me why you decided not to do so?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @peterwilsoncc I decided not to use |
||
|
|
||
| # 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 | ||
|
|
||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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/directoryThe empty string case is handled already by
[[ -z "$BUILD_DIR" ]]which returnstrueifBUILD_DIRis unset or set to the empty string.IMO,
BUILD_DIRis 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.