Skip to content
Snippets Groups Projects

Introduce automated deploy to WP.org

Merged Erick Hitter requested to merge add/wp-org-deploy into master
Files
2
+ 15
13
@@ -39,7 +39,7 @@ if [[ -z "$CI" ]]; then
fi
if [[ -z "$WP_ORG_USERNAME" ]]; then
echo "WordPress.org password not set" 1>&2
echo "WordPress.org username not set" 1>&2
exit 1
fi
@@ -58,17 +58,12 @@ if [[ -z "$PLUGIN_VERSION" ]]; then
exit 1
fi
if [[ -z "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" || "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" != "master" ]]; then
echo "Build branch is required and must be 'master'" 1>&2
exit 0
fi
echo "ℹ︎ PLUGIN_SLUG is $PLUGIN_SLUG"
echo "ℹ︎ PLUGIN_VERSION is $PLUGIN_VERSION"
SVN_URL="https://plugins.svn.wordpress.org/${PLUGIN_SLUG}/"
SVN_DIR="/tmp/svn-${PLUGIN_SLUG}"
TMP_DIR="/tmp/git-archive"
SVN_DIR="$CI_BUILDS_DIR/svn-${PLUGIN_SLUG}"
TMP_DIR="$CI_BUILDS_DIR/git-archive"
# Checkout just trunk for efficiency
# Tagging will be handled on the SVN level
@@ -77,27 +72,28 @@ svn checkout --depth immediates "$SVN_URL" "$SVN_DIR"
cd "$SVN_DIR"
svn update --set-depth infinity trunk
# Ensure we are in the $CI_PROJECT_DIR directory, just in case
echo "➤ Copying files..."
cd "$CI_BUILDS_DIR"
cd "$CI_PROJECT_DIR"
git config --global user.email "git-contrib+ci@ethitter.com"
git config --global user.name "Erick Hitter (GitLab CI)"
# If there's no .gitattributes file, write a default one into place
if [[ ! -e "$CI_BUILDS_DIR/.gitattributes" ]]; then
cat > "$CI_BUILDS_DIR/.gitattributes" <<-EOL
if [[ ! -e "$CI_PROJECT_DIR/.gitattributes" ]]; then
cat > "$CI_PROJECT_DIR/.gitattributes" <<-EOL
/.gitattributes export-ignore
/.gitignore export-ignore
/.github export-ignore
EOL
# Ensure we are in the $CI_BUILDS_DIR 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
mkdir "$TMP_DIR"
git archive HEAD | tar x --directory="$TMP_DIR"
cd "$SVN_DIR"
@@ -122,7 +118,13 @@ svn cp "trunk" "tags/$PLUGIN_VERSION"
svn status
# Stop here unless this is a merge into master.
if [[ -z "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" || "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" != "master" ]]; then
echo "𝘅︎ EXITING before commit step as this is the '${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}' branch, not the 'master' branch." 1>&2
exit 0
fi
echo "➤ Committing files..."
svn commit -m "Update to version $PLUGIN_VERSION from GitLab ($CI_PROJECT_URL)" --no-auth-cache --non-interactive --username "$SVN_USERNAME" --password "$SVN_PASSWORD"
svn commit -m "Update to version ${PLUGIN_VERSION} from GitLab (${CI_PROJECT_URL}; ${CI_JOB_URL})" --no-auth-cache --non-interactive --username "$SVN_USERNAME" --password "$SVN_PASSWORD"
echo "✓ Plugin deployed!"
Loading