Skip to content

Commit

Permalink
Review GitHub action deploy script
Browse files Browse the repository at this point in the history
  • Loading branch information
Ars92 committed Jul 15, 2024
1 parent 1601931 commit 77ba3a9
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 54 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/deploy-wp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash

if [[ -z "$SVN_USERNAME" ]] && [[ -z "$BUILD_ONLY" ]]; then
echo "x Missing SVN_USERNAME env variable"
exit 1
fi

if [[ -z "$SVN_PASSWORD" ]] && [[ -z "$BUILD_ONLY" ]]; then
echo "x Missing SVN_PASSWORD env variable"
exit 1
fi

if [[ -z "$VERSION" ]]; then
VERSION="${GITHUB_REF#refs/tags/}"
VERSION="${VERSION#v}"
fi

rx='^([0-9]+\.){2}(\*|[0-9]+)(-.*)?$'
if [[ $VERSION =~ $rx ]]; then
echo "ℹ VERSION is $VERSION"
elif [[ -z "$BUILD_ONLY" ]]; then
echo "x Unable to validate version: '$VERSION'"
exit 1
fi

CURRENT_DIR=$(pwd)
SLUG="xcloner-backup-and-restore"

SVN_URL="https://plugins.svn.wordpress.org/${SLUG}/"
SVN_DIR="${CURRENT_DIR}/${SLUG}-svn"
BUILD_DIR="${CURRENT_DIR}/${SLUG}-build"

echo "➤ Building Webpack bundle"
export NODE_OPTIONS=--openssl-legacy-provider
npm install || exit 1
npm run build-prod || exit 1

echo "➤ Copying files to build directory"
rsync -av --delete "${CURRENT_DIR}/${SLUG}/" "${BUILD_DIR}/"

echo "➤ Install composer dependencies without dev dependencies"
cd "${BUILD_DIR}" || exit 1
composer install --no-dev --prefer-dist -o --no-interaction || exit 1
cd "${CURRENT_DIR}" || exit 1

if [[ -n "$BUILD_ONLY" ]]; then
echo "✓ Plugin built!"
exit 0
fi

echo "➤ Checking out SVN repository..."
svn checkout "${SVN_URL}/trunk/" "${SVN_DIR}/trunk/"
cd "${CURRENT_DIR}" || exit 1

echo "➤ Coping files to SVN repository..."
rsync -r --exclude-from=".distignore" "${BUILD_DIR}/" "${SVN_DIR}/trunk/"

echo "➤ Adding files to SVN repository..."
cd "${SVN_DIR}/trunk" || exit 1
svn st | grep '^?' | awk '{print $2}' | xargs -r svn add
svn st | grep '^!' | awk '{print $2}' | xargs -r svn rm

echo "➤ Committing files to SVN repository..."
svn commit -m "v${VERSION}" --no-auth-cache --non-interactive --username "${SVN_USERNAME}" --password "${SVN_PASSWORD}" --config-option=servers:global:http-timeout=300 || exit 1

echo "➤ Coping tag to SVN repository..."
cd "${SVN_DIR}" || exit 1
svn cp "${SVN_URL}/trunk" "${SVN_URL}/tags/${VERSION}" -m "Tagging v${VERSION}" --no-auth-cache --non-interactive --username "${SVN_USERNAME}" --password "${SVN_PASSWORD}" --config-option=servers:global:http-timeout=300 || exit 1

echo "✓ Plugin deployed!"
38 changes: 5 additions & 33 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,16 @@
name: Deploy to WordPress.org
on:
push:
tags:
- "*"
workflow_dispatch:
jobs:
tag:
name: New tag
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Build npm dependencies
run: |
export NODE_OPTIONS=--openssl-legacy-provider
npm install
npm run build-prod
- name: Setup PHP with composer
uses: shivammathur/setup-php@v2
- uses: shivammathur/setup-php@v2
with:
php-version: '7.3'
tools: composer

- name: Build composer dependencies
run: |
cd xcloner-backup-and-restore
composer install --no-dev --prefer-dist -o
- name: Remove unneeded files
run: |
rsync --exclude-from=".distignore" -av --delete "${SRC_DIR}/" "${BUILD_DIR}/"
run: ${{ github.workspace }}/.github/workflows/deploy-wp.sh
env:
BUILD_DIR: xcloner-backup-and-restore-build
SRC_DIR: xcloner-backup-and-restore

- name: WordPress Plugin Deploy
uses: 10up/action-wordpress-plugin-deploy@develop
env:
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
SLUG: xcloner-backup-and-restore
BUILD_DIR: xcloner-backup-and-restore-build
with:
generate-zip: true
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ xcloner-backup-and-restore/vendor/
docker-compose.override.yml

/xcloner-backup-and-restore-build/
/xcloner-backup-and-restore-svn/
/xcloner-backup-and-restore*.zip

.env
31 changes: 11 additions & 20 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
SCRIPT_DIR="$( dirname -- "$0"; )"
SRC_DIR="${SCRIPT_DIR}/xcloner-backup-and-restore"
BUILD_DIR="${SCRIPT_DIR}/xcloner-backup-and-restore-build"

DATE=$(date +"%Y%m%d%H%M")
SLUG="xcloner-backup-and-restore"
BUILD_ONLY="true"
BUILD_SCRIPT_PATH="./.github/workflows/deploy-wp.sh"
BUILD_DIR="xcloner-backup-and-restore-build"

echo "Building Webpack bundle"

npm i
npm run build-prod

echo "Moving source files to build directory"
export BUILD_ONLY

rsync --exclude-from=".distignore" -av --delete "${SRC_DIR}/" "${BUILD_DIR}/"

echo "Install composer dependencies without dev dependencies"
cd "${BUILD_DIR}"
/bin/php7.3 /usr/local/bin/composer install --no-dev --prefer-dist -o --no-interaction
cd ..
echo "Building plugin"

echo "Removing unnecessary files from vendor directory"
rsync --exclude-from=".distignore" -av --delete "${BUILD_DIR}/" "${BUILD_DIR}/xcloner-backup-and-restore/"
bash "${BUILD_SCRIPT_PATH}"

echo "Creating archive"
cd "${BUILD_DIR}"
zip -r "xcloner-backup-and-restore-${DATE}.zip" "xcloner-backup-and-restore"
cd "${BUILD_DIR}" || exit 1
mkdir "${SLUG}"
mv ./* "${SLUG}"
zip -r "xcloner-backup-and-restore-${DATE}.zip" "${SLUG}" || exit 1
mv "xcloner-backup-and-restore-${DATE}.zip" ../
cd ..

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static function prevent_vendor_direct_access()
continue;
}

$contents = preg_replace('/^namespace\s+([a-zA-Z0-9_\\\\]+);/m', "namespace $1;\n\n$check_to_add\n", $contents, 1);
$contents = preg_replace('/namespace\s+([a-zA-Z0-9_\\\\]+);/m', "namespace $1;\n\n$check_to_add\n", $contents, 1);

if (
strpos($contents, $check_to_add) === false
Expand Down

0 comments on commit 77ba3a9

Please sign in to comment.