diff --git a/.github/actions/release-plugin/action.yml b/.github/actions/release-plugin/action.yml index 8655a8c68..4bb0fd7c3 100644 --- a/.github/actions/release-plugin/action.yml +++ b/.github/actions/release-plugin/action.yml @@ -1,22 +1,41 @@ -name: 'WordPress Plugin Deploy' -description: 'Deploy to the WordPress Plugin Repository' -author: '10up' +name: 'Plugin Deploy' +description: 'Upload zip file to releases tab' branding: icon: 'upload-cloud' color: 'blue' -inputs: - generate-zip: - description: 'Generate package zip file?' - default: false + outputs: zip-path: description: 'Path to zip file' - value: ${{ steps.deploy.outputs.zip-path }} + value: ${{ steps.zip.outputs.zip-path }} + runs: using: 'composite' steps: - - id: deploy - env: - INPUT_GENERATE_ZIP: ${{ inputs.generate-zip }} - run: ${{ github.action_path }}/deploy.sh + - id: prepare + name: Prepare Environment + run: | + sudo apt-get update && sudo apt-get install zip rsync -y + - id: zip + name: Zip Plugin (optional) + run: | + # Create dist folder and copy files while excluding .distignore items + mkdir -p dist + rsync -av --exclude-from="${{ env.PLUGIN_DIR }}/.distignore" ${{ env.PLUGIN_DIR }}/ dist/${{ env.SLUG }} + + # Zip the plugin directory + zip_file="faustwp-${{ env.VERSION }}.zip" + zip -r $zip_file dist/${{ env.SLUG }} + + # Save zip path to output + echo "::set-output name=zip-path::$PWD/$zip_file" shell: bash + + - id: upload + name: Upload Zip File to Release + uses: softprops/action-gh-release@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + files: ${{ steps.zip.outputs.zip-path }} # Updated to use zip-path output + asset_name: faustwp-${{ env.VERSION }}.zip # Set asset name to the correct versioned name + overwrite: true \ No newline at end of file diff --git a/.github/actions/release-plugin/deploy.sh b/.github/actions/release-plugin/deploy.sh deleted file mode 100755 index bff08c7d2..000000000 --- a/.github/actions/release-plugin/deploy.sh +++ /dev/null @@ -1,108 +0,0 @@ -#!/bin/bash - -# Note that this does not use pipefail -# because if the grep later doesn't match any deleted files, -# which is likely the majority case, -# it does not exit with a 0, and I only care about the final exit. -set -eo - -# Ensure SVN username and password are set -# IMPORTANT: while secrets are encrypted and not viewable in the GitHub UI, -# they are by necessity provided as plaintext in the context of the Action, -# so do not echo or use debug mode unless you want your secrets exposed! -if [[ -z "$SVN_USERNAME" ]]; then - echo "Set the SVN_USERNAME secret" - exit 1 -fi - -if [[ -z "$SVN_PASSWORD" ]]; then - echo "Set the SVN_PASSWORD secret" - exit 1 -fi - -# Require the PLUGIN_DIR environment variable to be set -if [[ -z "$PLUGIN_DIR" ]]; then - echo "Set the PLUGIN_DIR environment variable" - exit 1 -fi -echo "ℹ︎ PLUGIN_DIR is $PLUGIN_DIR" - -# Allow some ENV variables to be customized -if [[ -z "$SLUG" ]]; then - SLUG=${GITHUB_REPOSITORY#*/} -fi -echo "ℹ︎ SLUG is $SLUG" - -# Does it even make sense for VERSION to be editable in a workflow definition? -if [[ -z "$VERSION" ]]; then - VERSION="${GITHUB_REF#refs/tags/}" - VERSION="${VERSION#@faustwp/wordpress-plugin@}" # Strip the @faustwp/wordpress-plugin@ prefix from the version -fi -echo "ℹ︎ VERSION is $VERSION" - -if [[ -z "$ASSETS_DIR" ]]; then - ASSETS_DIR=".wordpress-org" -fi -echo "ℹ︎ ASSETS_DIR is $ASSETS_DIR" - -SVN_URL="https://plugins.svn.wordpress.org/${SLUG}/" -SVN_DIR="${HOME}/svn-${SLUG}" - -# Checkout just trunk and assets for efficiency -# Tagging will be handled on the SVN level -echo "➤ Checking out .org repository..." -svn checkout --depth immediates "$SVN_URL" "$SVN_DIR" -cd "$SVN_DIR" -svn update --set-depth infinity assets -svn update --set-depth infinity trunk - -echo "➤ Copying files..." -if [[ -e "$GITHUB_WORKSPACE/$PLUGIN_DIR/.distignore" ]]; then - echo "ℹ︎ Using .distignore" - # Copy from PLUGIN_DIR 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/$PLUGIN_DIR/.distignore" "$GITHUB_WORKSPACE/$PLUGIN_DIR/" trunk/ --delete --delete-excluded -else - rsync -rc "$GITHUB_WORKSPACE/$PLUGIN_DIR/" trunk --delete --delete-excluded -fi - -# Copy dotorg assets to /assets -if [[ -d "$GITHUB_WORKSPACE/$PLUGIN_DIR/$ASSETS_DIR/" ]]; then - rsync -rc "$GITHUB_WORKSPACE/$PLUGIN_DIR/$ASSETS_DIR/" assets/ --delete -else - echo "ℹ︎ No assets directory found; skipping asset copy" -fi - -# Add everything and commit to SVN -# The force flag ensures we recurse into subdirectories even if they are already added -# Suppress stdout in favor of svn status later for readability -echo "➤ Preparing files..." -svn add . --force > /dev/null - -# SVN delete all deleted files -# Also suppress stdout here -svn status | grep '^\!' | sed 's/! *//' | xargs -I% svn rm %@ > /dev/null - -# Copy tag locally to make this a single commit -echo "➤ Copying tag..." -svn cp "trunk" "tags/$VERSION" - -# Fix screenshots getting force downloaded when clicking them -# https://developer.wordpress.org/plugins/wordpress-org/plugin-assets/ -svn propset svn:mime-type image/png assets/*.png || true -svn propset svn:mime-type image/jpeg assets/*.jpg || true - -svn status - -echo "➤ Committing files..." -svn commit -m "Update to version $VERSION from GitHub" --no-auth-cache --non-interactive --username "$SVN_USERNAME" --password "$SVN_PASSWORD" - -if $INPUT_GENERATE_ZIP; then - echo "Generating zip file..." - cd "$SVN_DIR/trunk" || exit - zip -r "${GITHUB_WORKSPACE}/${PLUGIN_DIR}/${SLUG}.zip" . - echo "::set-output name=zip-path::${GITHUB_WORKSPACE}/${PLUGIN_DIR}/${SLUG}.zip" - echo "✓ Zip file generated!" -fi - -echo "✓ Plugin deployed!" diff --git a/.github/workflows/release-packages.yml b/.github/workflows/release-packages.yml index 6a523dc23..48e79b14d 100644 --- a/.github/workflows/release-packages.yml +++ b/.github/workflows/release-packages.yml @@ -52,12 +52,8 @@ jobs: # Then deploy the WordPress plugin # https://github.com/changesets/action#outputs if: steps.changesets.outputs.published && contains(steps.changesets.outputs.publishedPackages, '"@faustwp/wordpress-plugin"') - # Use a variant of 10up/action-wordpress-plugin-deploy that allows us to specify a PLUGIN_DIR - # to support our monorepo structure. uses: ./.github/actions/release-plugin env: - SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} - SVN_USERNAME: ${{ secrets.SVN_USERNAME }} PLUGIN_DIR: plugins/faustwp SLUG: faustwp VERSION: ${{ env.PLUGIN_VERSION }} diff --git a/.github/workflows/release-plugin.yml b/.github/workflows/release-plugin.yml deleted file mode 100644 index 44f120384..000000000 --- a/.github/workflows/release-plugin.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Deploy to WordPress.org -on: - push: - tags: - - "@faustwp/wordpress-plugin@*" -jobs: - release_plugin: - runs-on: ubuntu-22.04 - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: WordPress Plugin Deploy - # Use a variant of 10up/action-wordpress-plugin-deploy that allows us to specify a PLUGIN_DIR - # to support our monorepo structure. - uses: ./.github/actions/release-plugin - env: - SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} - SVN_USERNAME: ${{ secrets.SVN_USERNAME }} - PLUGIN_DIR: plugins/faustwp - SLUG: faustwp