Repository navigation
Deploy to WordPress.org Repository #5
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy to WordPress.org Repository | |
| on: | |
| # The action will run when a release or a pre-release is created. | |
| # | |
| # In case of a pre-release, the action will not commit to WP.org (dry-run). However, it will still | |
| # create a zip file and upload it to the release. Note that a pre-release (release candidate) | |
| # should not be changed to a release but rather a new release should be created. | |
| # | |
| # The "prereleased" type will not trigger for pre-releases published from draft releases, but | |
| # the "published" type will trigger. Since we want a workflow to run when stable and pre-releases | |
| # publish, we subscribe to "published" instead of "released" and "prereleased". | |
| # | |
| # See: https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#release | |
| release: | |
| types: [ published ] | |
| # Allows running the workflow manually (e.g. against a branch or tag) without publishing a | |
| # real GitHub release, so the pipeline can be exercised safely. Defaults to a dry-run. | |
| workflow_dispatch: | |
| inputs: | |
| dry_run: | |
| description: 'Skip the actual WP.org SVN commit (still builds, verifies, and uploads a zip artifact)' | |
| type: boolean | |
| default: true | |
| jobs: | |
| lint_and_test: | |
| uses: ./.github/workflows/ci.yml | |
| secrets: inherit | |
| deploy_to_wp_repository: | |
| needs: lint_and_test | |
| name: Deploy to WP.org | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version-file: '.nvmrc' | |
| cache: 'npm' | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: '8.3' | |
| tools: composer:v2 | |
| - name: Get Composer cache directory | |
| id: composer-cache | |
| run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | |
| - name: Cache Composer packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ steps.composer-cache.outputs.dir }} | |
| key: ${{ runner.os }}-php-${{ hashFiles( 'composer.lock' ) }} | |
| restore-keys: ${{ runner.os }}-php- | |
| # Install dependencies. | |
| - name: Install NPM dependencies | |
| run: npm ci | |
| - name: Install Composer dependencies | |
| run: composer install --no-dev | |
| # Build. | |
| - name: Build | |
| run: npm run build | |
| - name: Prepare build directory | |
| run: npx grunt prepare | |
| # Read once so both the tag check and the deploy step use the exact same value, rather | |
| # than letting the deploy action derive its own version from GITHUB_REF - that only works | |
| # when triggered from a tag push, and yields a bogus value like "refs/heads/master" (which | |
| # SVN then can't use as a tag path) on a workflow_dispatch run against a branch. | |
| - name: Read plugin version | |
| run: echo "PLUGIN_VERSION=$(cat .version | tr -d '[:space:]')" >> "$GITHUB_ENV" | |
| # Ensure the version in the .version file matches the tag of the release. | |
| # Skipped for manual runs, which may not be run against a release tag. | |
| - name: Verify version matches tag | |
| if: github.event_name == 'release' | |
| run: | | |
| TAG="${GITHUB_REF_NAME#v}" | |
| if [ "$TAG" != "$PLUGIN_VERSION" ]; then | |
| echo "::error::Tag $TAG does not match .version $PLUGIN_VERSION" | |
| exit 1 | |
| fi | |
| - name: WordPress Plugin Deploy | |
| # This is used to get the zip-path later. | |
| id: deploy | |
| uses: 10up/action-wordpress-plugin-deploy@stable | |
| with: | |
| generate-zip: true | |
| # In case of a pre-release, do not commit to WP.org. Manual runs default to a dry-run too. | |
| dry-run: ${{ github.event_name == 'release' && github.event.release.prerelease || inputs.dry_run }} | |
| env: | |
| BUILD_DIR: 'build' | |
| SLUG: 'cloudinary-image-management-and-manipulation-in-the-cloud-cdn' | |
| VERSION: ${{ env.PLUGIN_VERSION }} | |
| # Use secrets to authenticate with WP.org. | |
| SVN_USERNAME: ${{ secrets.SVN_USERNAME }} | |
| SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} | |
| # Makes the zip downloadable from the run's Artifacts panel regardless of trigger, so | |
| # manual/dry-run dispatches can be inspected without publishing a release. | |
| - name: Upload build artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ env.PLUGIN_VERSION }}.zip | |
| path: ${{ steps.deploy.outputs.zip-path }} | |
| retention-days: 7 | |
| - name: Upload release asset | |
| if: github.event_name == 'release' | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: ${{ steps.deploy.outputs.zip-path }} |