|
| 1 | +name: Release WordPress Plugin to SVN |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*.*.*' # Matches version tags like v1.0.0, v2.1.3, etc. |
| 7 | + |
| 8 | +jobs: |
| 9 | + build-and-release: |
| 10 | + name: Build and Release The Plugin to SVN |
| 11 | + runs-on: ubuntu-latest |
| 12 | + |
| 13 | + steps: |
| 14 | + - name: Checkout code |
| 15 | + uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - name: Set up PHP |
| 18 | + uses: shivammathur/setup-php@v2 |
| 19 | + with: |
| 20 | + php-version: '8.0' # Adjust this to your PHP version if necessary |
| 21 | + tools: composer |
| 22 | + |
| 23 | + - name: Set up Node.js |
| 24 | + uses: actions/setup-node@v3 |
| 25 | + with: |
| 26 | + node-version: '14' # Adjust this to your Node.js version if necessary. Latest node v21.7.1 |
| 27 | + |
| 28 | + - name: Install SSH key |
| 29 | + run: | |
| 30 | + mkdir -p ~/.ssh |
| 31 | + echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa |
| 32 | + chmod 600 ~/.ssh/id_rsa |
| 33 | + ssh-keyscan github.com >> ~/.ssh/known_hosts |
| 34 | +
|
| 35 | + - name: Install PHP dependencies |
| 36 | + run: | |
| 37 | + composer config --global github-protocols ssh |
| 38 | + composer install |
| 39 | + composer update --no-dev --no-scripts |
| 40 | +
|
| 41 | + - name: Install Node.js dependencies |
| 42 | + run: npm install |
| 43 | + |
| 44 | + - name: Run build script |
| 45 | + run: npm run build |
| 46 | + |
| 47 | + - name: Checkout SVN repository |
| 48 | + run: svn checkout ${{ secrets.SVN_REPOSITORY_URL }} svn |
| 49 | + |
| 50 | + - name: Sync files to SVN trunk |
| 51 | + run: | |
| 52 | + rsync -r --delete --exclude-from='.distignore' --exclude='svn/' ./ svn/trunk/ |
| 53 | + cd svn |
| 54 | + svn add --force trunk |
| 55 | + svn commit -m "Release version ${{ github.ref }}" --username ${{ secrets.SVN_USERNAME }} --password ${{ secrets.SVN_PASSWORD }} --no-auth-cache --non-interactive |
| 56 | +
|
| 57 | + - name: Sync assets to SVN assets |
| 58 | + run: | |
| 59 | + mkdir -p svn/assets |
| 60 | + rsync -r --delete --include '*/' --include '*.png' --include '*.jpg' --include '*.jpeg' --include '*.gif' --include '*.svg' --exclude '*' .wordpress-org/ svn/assets/ |
| 61 | + cd svn |
| 62 | + svn add --force assets |
| 63 | + svn commit -m "Update assets for version ${{ github.ref }}" --username ${{ secrets.SVN_USERNAME }} --password ${{ secrets.SVN_PASSWORD }} --no-auth-cache --non-interactive |
| 64 | +
|
| 65 | + - name: Delete existing SVN tag if it exists |
| 66 | + run: | |
| 67 | + TAG_NAME=${GITHUB_REF#refs/tags/} |
| 68 | + TAG_NAME=${TAG_NAME#v} |
| 69 | + svn delete ${{ secrets.SVN_REPOSITORY_URL }}/tags/${TAG_NAME} -m "Deleting existing tag ${TAG_NAME}" --username ${{ secrets.SVN_USERNAME }} --password ${{ secrets.SVN_PASSWORD }} --no-auth-cache --non-interactive || true |
| 70 | +
|
| 71 | + - name: Create SVN tag # For removing tag: svn delete ${{ secrets.SVN_REPOSITORY_URL }}/tags/${TAG_NAME} -m "Removing unwanted tag ${TAG_NAME}" --username ${{ secrets.SVN_USERNAME }} --password ${{ secrets.SVN_PASSWORD }} --non-interactive |
| 72 | + run: | |
| 73 | + TAG_NAME=${GITHUB_REF#refs/tags/} |
| 74 | + TAG_NAME=${TAG_NAME#v} |
| 75 | + cd svn |
| 76 | + svn copy ${{ secrets.SVN_REPOSITORY_URL }}/trunk ${{ secrets.SVN_REPOSITORY_URL }}/tags/${TAG_NAME} -m "Tagging version ${TAG_NAME}" --username ${{ secrets.SVN_USERNAME }} --password ${{ secrets.SVN_PASSWORD }} --no-auth-cache --non-interactive |
| 77 | +
|
| 78 | + notifications: |
| 79 | + needs: build-and-release |
| 80 | + runs-on: ubuntu-latest |
| 81 | + if: always() |
| 82 | + |
| 83 | + steps: |
| 84 | + - name: Send Slack notification on success |
| 85 | + if: success() |
| 86 | + uses: slackapi/slack-github-action@v1.18.0 |
| 87 | + with: |
| 88 | + payload: | |
| 89 | + { |
| 90 | + "channel": "#announcements", |
| 91 | + "text": "The release of version ${{ github.ref }} was successful.", |
| 92 | + "attachments": [ |
| 93 | + { |
| 94 | + "color": "good", |
| 95 | + "text": "Release version ${{ github.ref }} has been successfully deployed." |
| 96 | + } |
| 97 | + ] |
| 98 | + } |
| 99 | + env: |
| 100 | + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} |
| 101 | + |
| 102 | + - name: Send Slack notification on failure |
| 103 | + if: failure() |
| 104 | + uses: slackapi/slack-github-action@v1.18.0 |
| 105 | + with: |
| 106 | + payload: | |
| 107 | + { |
| 108 | + "channel": "#announcements", |
| 109 | + "text": "The release of version ${{ github.ref }} failed.", |
| 110 | + "attachments": [ |
| 111 | + { |
| 112 | + "color": "danger", |
| 113 | + "text": "There was an error in releasing version ${{ github.ref }}. Please check the GitHub Actions logs for details." |
| 114 | + } |
| 115 | + ] |
| 116 | + } |
| 117 | + env: |
| 118 | + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} |
0 commit comments