image: alpine

pipelines:
  branches:
    main:
      - step:
          name: Deploy to WordPress SVN
          script:
            - apk add --no-cache subversion rsync  # Install SVN & rsync
            - svn checkout --username $SVN_USERNAME $SVN_DEPLOY_URL svn
            - rsync -r --delete --exclude=".git" --exclude=".bitbucket" --exclude="*/bitbucket-pipelines.yml" ./ svn/trunk/
            - mkdir -p svn/assets  # Make sure assets folder exists
            - rsync -r public/images/plugin_page_images/ svn/assets/  # Copy plugin_page_images content to assets
            - cd svn
            - svn add --force trunk/* assets/*
            - svn commit -m "Deploying new version from Bitbucket" --username $SVN_USERNAME --password $SVN_PASSWORD
            - if svn info "$SVN_DEPLOY_URL/tags/1.0.1" --username $SVN_USERNAME --password $SVN_PASSWORD > /dev/null 2>&1; then svn delete "$SVN_DEPLOY_URL/tags/1.0.1" -m "Deleting old tag 1.0.1" --username $SVN_USERNAME --password $SVN_PASSWORD; fi
            - svn copy "$SVN_DEPLOY_URL/trunk" "$SVN_DEPLOY_URL/tags/1.0.1" --username $SVN_USERNAME --password $SVN_PASSWORD -m "Tagging version 1.0.1"