Merge pull request #409 from wpengine/chore-wpgraphql-logging-fixes-s… #58
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
| # This creates a release branch for a plugin when changes are pushed to the main branch. | |
| # We cannot commit to a protected branch directly, so we create a new branch to make these changes. | |
| name: Create Release Branch | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - "plugins/*/**" | |
| permissions: | |
| contents: write # Allow actions to read and write repository contents | |
| pull-requests: write # Allow actions to create and manage pull requests | |
| actions: read # Allow actions to read repository metadata but not write to it | |
| jobs: | |
| create-release-branch: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: '8.2' # Note all plugins are compatible with PHP 8.2 | |
| extensions: mbstring, json, zip | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 18.x # Min version required by the repo | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v3 | |
| with: | |
| version: 10 # Min version required by the repo | |
| - name: Get changed plugin directory | |
| id: plugin | |
| run: | | |
| bash .github/scripts/get_plugin_slug.sh release | |
| - name: Validate plugin detection | |
| continue-on-error: false | |
| run: | | |
| if [ ! -d "plugins/${{ steps.plugin.outputs.slug }}" ]; then | |
| echo "Plugin directory does not exist" | |
| exit 1 | |
| fi | |
| - name: Install dependencies | |
| run: pnpm install | |
| - name: Create release branch and apply changesets | |
| run: | | |
| # Create a unique branch name with timestamp | |
| BRANCH_NAME="release/${{ steps.plugin.outputs.slug }}-$(date +%Y%m%d-%H%M%S)" | |
| echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV | |
| # Create and switch to release branch | |
| git checkout -b "$BRANCH_NAME" | |
| # Apply version bumps from changesets | |
| pnpm changeset version | |
| # Only run if both package.json and composer.json exist for the plugin | |
| if [ -f "plugins/${{ steps.plugin.outputs.slug }}/package.json" ] && [ -f "plugins/${{ steps.plugin.outputs.slug }}/composer.json" ]; then | |
| echo "Both package.json and composer.json found for ${{ steps.plugin.outputs.slug }}" | |
| # Run version script for the plugin if it exists | |
| if cat "plugins/${{ steps.plugin.outputs.slug }}/package.json" | grep -q '"version".*:'; then | |
| echo "Running version script for ${{ steps.plugin.outputs.slug }}" | |
| cd "plugins/${{ steps.plugin.outputs.slug }}" | |
| npm run version | |
| cd ../.. | |
| else | |
| echo "No version script found for ${{ steps.plugin.outputs.slug }}" | |
| fi | |
| # Get new version from plugin's package.json | |
| NEW_VERSION=$(jq -r '.version' "plugins/${{ steps.plugin.outputs.slug }}/package.json") | |
| # Build the download URL | |
| # e.g. https://github.com/wpengine/hwptoolkit/releases/download/%40wpengine%2Fhwp-previews-wordpress-plugin-0.0.5/hwp-previews.zip | |
| # Get the "name" field from plugin's package.json and URL encode it | |
| PKG_NAME=$(jq -r '.name' "plugins/${{ steps.plugin.outputs.slug }}/package.json") | |
| ENCODED_PKG_NAME=$(python3 -c "import urllib.parse,sys; print(urllib.parse.quote(sys.argv[1], safe=''))" "$PKG_NAME") | |
| # Format is [github-repository]/releases/download/[encoded-package-name]-[version]/[plugin-slug].zip | |
| RELEASE_URL="https://github.com/wpengine/hwptoolkit/releases/download/${ENCODED_PKG_NAME}-${NEW_VERSION}/${{ steps.plugin.outputs.slug }}.zip" | |
| # Get plugin description from plugin's composer.json | |
| DESCRIPTION=$(jq -r '.description // empty' "plugins/${{ steps.plugin.outputs.slug }}/composer.json") | |
| # Run the composer package update script | |
| # Get the "name" field from plugin's composer.json | |
| COMPOSER_NAME=$(jq -r '.name' "plugins/${{ steps.plugin.outputs.slug }}/composer.json") | |
| if [ -n "$NEW_VERSION" ] && [ -n "$RELEASE_URL" ] && [ -n "$COMPOSER_NAME" ] && [ -n "$DESCRIPTION" ]; then | |
| .github/scripts/update_composer_package.sh "$NEW_VERSION" "$RELEASE_URL" "$COMPOSER_NAME" "$DESCRIPTION" | |
| else | |
| echo "Error: Missing required values for update_composer_package.sh" | |
| echo "NEW_VERSION: $NEW_VERSION" | |
| echo "RELEASE_URL: $RELEASE_URL" | |
| echo "COMPOSER_NAME: $COMPOSER_NAME" | |
| echo "DESCRIPTION: $DESCRIPTION" | |
| exit 1 | |
| fi | |
| else | |
| echo "package.json and/or composer.json not found for plugin ${{ steps.plugin.outputs.slug }}. Skipping version and composer update steps." | |
| fi | |
| # Configure git | |
| git config user.name "github-actions" | |
| git config user.email "[email protected]" | |
| # Commit changes | |
| git add . | |
| if git diff --staged --quiet; then | |
| echo "No changes to commit" | |
| else | |
| git commit -m "chore: apply version bump from changesets for ${{ steps.plugin.outputs.slug }}" | |
| git push origin "$BRANCH_NAME" | |
| # Create PR | |
| gh pr create \ | |
| --title "Release: ${{ steps.plugin.outputs.slug }} version bump" \ | |
| --body "Automated release PR for ${{ steps.plugin.outputs.slug }} plugin. | |
| This PR applies version bumps from changesets. Once merged, it will trigger the pre-release creation workflow. | |
| Plugin: ${{ steps.plugin.outputs.slug }}" \ | |
| --base main \ | |
| --head "$BRANCH_NAME" | |
| fi | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |