diff --git a/README.md b/README.md index 2c7cb0e..d43f4e9 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ Because the WordPress.org plugin repository shows information from the readme in * `SLUG` - defaults to the respository name, customizable in case your WordPress repository has a different slug or is capitalized differently. * `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`). * `README_NAME` - defaults to `readme.txt`, customizable in case you use `README.md` instead, which is now quietly supported in the WordPress.org plugin repository. +* `IGNORE_OTHER_FILES` - defaults to `false`, which means that all your files are copied (as in [WordPress.org Plugin Deploy Action](https://github.com/10up/action-wordpress-plugin-deploy), respecting `.distignore` and `.gitattributes`), and the Action will bail if anything except assets and `readme.txt` are modified. See "Important note" above. If you set this variable to `true`, then only assets and `readme.txt` will be copied, and changes to other files will be ignored and not committed. ## Example Workflow File diff --git a/deploy.sh b/deploy.sh index 81f0ff8..5066eb6 100755 --- a/deploy.sh +++ b/deploy.sh @@ -34,6 +34,11 @@ if [[ -z "$README_NAME" ]]; then fi echo "ℹ︎ README_NAME is $README_NAME" +if [[ -z "$IGNORE_OTHER_FILES" ]]; then + IGNORE_OTHER_FILES=false +fi +echo "ℹ︎ IGNORE_OTHER_FILES is $IGNORE_OTHER_FILES" + SVN_URL="https://plugins.svn.wordpress.org/${SLUG}/" SVN_DIR="${HOME}/svn-${SLUG}" @@ -46,50 +51,58 @@ svn update --set-depth infinity assets svn update --set-depth infinity trunk echo "➤ Copying files..." -if [[ -e "$GITHUB_WORKSPACE/.distignore" ]]; then - echo "ℹ︎ Using .distignore" - +if [ "$IGNORE_OTHER_FILES" = true ]; then + # Copy readme.txt to /trunk + cp "$GITHUB_WORKSPACE/$README_NAME" trunk/$README_NAME + # Use $TMP_DIR as the source of truth TMP_DIR=$GITHUB_WORKSPACE - - # 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 "10upbot+github@10up.com" - 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 + if [[ -e "$GITHUB_WORKSPACE/.distignore" ]]; then + echo "ℹ︎ Using .distignore" + + # Use $TMP_DIR as the source of truth + TMP_DIR=$GITHUB_WORKSPACE + + # 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 "10upbot+github@10up.com" + git config --global user.name "10upbot on GitHub" - # This will exclude everything in the .gitattributes file with the export-ignore flag - git archive HEAD | tar x --directory="$TMP_DIR" + # 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 - cd "$SVN_DIR" + # 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 - # 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 + # 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 fi # Copy dotorg assets to /assets