From 49211610372c4b92593a5ed9b7626ebdf74b6b0c Mon Sep 17 00:00:00 2001 From: Mark Jaquith Date: Wed, 27 Oct 2021 02:13:18 -0400 Subject: [PATCH 1/3] If IGNORE_OTHER_FILES is true, only copy readme.txt --- deploy.sh | 89 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 38 deletions(-) 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 From e0e94680cb2cccfb2f3d2c8e027121190ccb43f5 Mon Sep 17 00:00:00 2001 From: Mark Jaquith Date: Wed, 27 Oct 2021 03:04:12 -0400 Subject: [PATCH 2/3] Document IGNORE_OTHER_FILES --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 2c7cb0e..f1cb523 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 `.gitignore`), 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 From e0c0505457e36ef72df705739e33423bf403f00b Mon Sep 17 00:00:00 2001 From: Mark Jaquith Date: Fri, 7 Jan 2022 16:58:39 -0500 Subject: [PATCH 3/3] Fix mistaken reference to .gitignore --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f1cb523..d43f4e9 100644 --- a/README.md +++ b/README.md @@ -28,7 +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 `.gitignore`), 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. +* `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