|
| 1 | +name: Deploy to WordPress.org Repository |
| 2 | + |
| 3 | +on: |
| 4 | + |
| 5 | + # The action will run when a release or a pre-release is created. |
| 6 | + # |
| 7 | + # In case of a pre-release, the action will not commit to WP.org (dry-run). However, it will still |
| 8 | + # create a zip file and upload it to the release. Note that a pre-release (release candidate) |
| 9 | + # should not be changed to a release but rather a new release should be created. |
| 10 | + # |
| 11 | + # The "prereleased" type will not trigger for pre-releases published from draft releases, but |
| 12 | + # the "published" type will trigger. Since we want a workflow to run when stable and pre-releases |
| 13 | + # publish, we subscribe to "published" instead of "released" and "prereleased". |
| 14 | + # |
| 15 | + # See: https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#release |
| 16 | + release: |
| 17 | + types: [ published ] |
| 18 | + |
| 19 | + # Allows running the workflow manually (e.g. against a branch or tag) without publishing a |
| 20 | + # real GitHub release, so the pipeline can be exercised safely. Defaults to a dry-run. |
| 21 | + workflow_dispatch: |
| 22 | + inputs: |
| 23 | + dry_run: |
| 24 | + description: 'Skip the actual WP.org SVN commit (still builds, verifies, and uploads a zip artifact)' |
| 25 | + type: boolean |
| 26 | + default: true |
| 27 | + |
| 28 | +jobs: |
| 29 | + lint_and_test: |
| 30 | + uses: ./.github/workflows/ci.yml |
| 31 | + secrets: inherit |
| 32 | + |
| 33 | + deploy_to_wp_repository: |
| 34 | + needs: lint_and_test |
| 35 | + name: Deploy to WP.org |
| 36 | + runs-on: ubuntu-latest |
| 37 | + permissions: |
| 38 | + contents: write |
| 39 | + |
| 40 | + steps: |
| 41 | + - name: Checkout |
| 42 | + uses: actions/checkout@v4 |
| 43 | + |
| 44 | + - name: Setup Node |
| 45 | + uses: actions/setup-node@v4 |
| 46 | + with: |
| 47 | + node-version-file: '.nvmrc' |
| 48 | + cache: 'npm' |
| 49 | + |
| 50 | + - name: Setup PHP |
| 51 | + uses: shivammathur/setup-php@v2 |
| 52 | + with: |
| 53 | + php-version: '8.3' |
| 54 | + tools: composer:v2 |
| 55 | + |
| 56 | + - name: Get Composer cache directory |
| 57 | + id: composer-cache |
| 58 | + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT |
| 59 | + |
| 60 | + - name: Cache Composer packages |
| 61 | + uses: actions/cache@v4 |
| 62 | + with: |
| 63 | + path: ${{ steps.composer-cache.outputs.dir }} |
| 64 | + key: ${{ runner.os }}-php-${{ hashFiles( 'composer.lock' ) }} |
| 65 | + restore-keys: ${{ runner.os }}-php- |
| 66 | + |
| 67 | + # Install dependencies. |
| 68 | + - name: Install NPM dependencies |
| 69 | + run: npm ci |
| 70 | + |
| 71 | + - name: Install Composer dependencies |
| 72 | + run: composer install --no-dev |
| 73 | + |
| 74 | + # Build. |
| 75 | + - name: Build |
| 76 | + run: npm run build |
| 77 | + |
| 78 | + - name: Prepare build directory |
| 79 | + run: npx grunt prepare |
| 80 | + |
| 81 | + # Ensure the version in the .version file matches the tag of the release. |
| 82 | + # Skipped for manual runs, which may not be run against a release tag. |
| 83 | + - name: Verify version matches tag |
| 84 | + if: github.event_name == 'release' |
| 85 | + run: | |
| 86 | + TAG="${GITHUB_REF_NAME#v}" |
| 87 | + FILE_VERSION=$(cat .version | tr -d '[:space:]') |
| 88 | + if [ "$TAG" != "$FILE_VERSION" ]; then |
| 89 | + echo "::error::Tag $TAG does not match .version $FILE_VERSION" |
| 90 | + exit 1 |
| 91 | + fi |
| 92 | +
|
| 93 | + - name: WordPress Plugin Deploy |
| 94 | + # This is used to get the zip-path later. |
| 95 | + id: deploy |
| 96 | + uses: 10up/action-wordpress-plugin-deploy@stable |
| 97 | + with: |
| 98 | + generate-zip: true |
| 99 | + # In case of a pre-release, do not commit to WP.org. Manual runs default to a dry-run too. |
| 100 | + dry-run: ${{ github.event_name == 'release' && github.event.release.prerelease || inputs.dry_run }} |
| 101 | + |
| 102 | + env: |
| 103 | + BUILD_DIR: 'build' |
| 104 | + SLUG: 'cloudinary-image-management-and-manipulation-in-the-cloud-cdn' |
| 105 | + # Use secrets to authenticate with WP.org. |
| 106 | + SVN_USERNAME: ${{ secrets.SVN_USERNAME }} |
| 107 | + SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} |
| 108 | + |
| 109 | + - name: Upload release asset |
| 110 | + if: github.event_name == 'release' |
| 111 | + uses: softprops/action-gh-release@v2 |
| 112 | + with: |
| 113 | + files: ${{ steps.deploy.outputs.zip-path }} |
0 commit comments