|
| 1 | +name: Bump wp-parsely version |
| 2 | +run-name: Bump wp-parsely version to ${{ github.event.inputs.new_version }} |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + new_version: |
| 8 | + description: 'The new plugin version' |
| 9 | + required: true |
| 10 | + type: string |
| 11 | + |
| 12 | +env: |
| 13 | + NEW_VERSION: ${{ github.event.inputs.new_version }} |
| 14 | + |
| 15 | +jobs: |
| 16 | + validate_version: |
| 17 | + name: Validate the new version |
| 18 | + runs-on: ubuntu-latest |
| 19 | + outputs: |
| 20 | + current_version: ${{ steps.get_current_version.outputs.current_version }} |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Checks if the new version is valid |
| 24 | + run: | |
| 25 | + if [[ ! ${{ env.NEW_VERSION }} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 26 | + echo "Invalid version format. Please use the format x.y.z" |
| 27 | + exit 1 |
| 28 | + fi |
| 29 | +
|
| 30 | + - name: Setup PHP 8.1 |
| 31 | + uses: shivammathur/setup-php@v2 |
| 32 | + with: |
| 33 | + php-version: '8.1' |
| 34 | + extensions: mbstring, json |
| 35 | + |
| 36 | + - name: Checkout ${{ github.ref_name }} branch |
| 37 | + uses: actions/checkout@v4 |
| 38 | + with: |
| 39 | + ref: ${{ github.ref_name }} |
| 40 | + fetch-depth: 0 |
| 41 | + |
| 42 | + - name: Get the current version |
| 43 | + id: get_current_version |
| 44 | + run: | |
| 45 | + CURRENT_VERSION=$(grep -E "^ \* Version:" wp-parsely.php | awk '{print $3}') |
| 46 | + echo "Current version is $CURRENT_VERSION" |
| 47 | + echo "New version is ${{ env.NEW_VERSION }}" |
| 48 | +
|
| 49 | + echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_OUTPUT |
| 50 | + echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV |
| 51 | +
|
| 52 | + - name: Check if the new version is greater than the current version |
| 53 | + run: | |
| 54 | + php -r ' |
| 55 | + $current = "${{ env.CURRENT_VERSION }}"; |
| 56 | + $new = "${{ env.NEW_VERSION }}"; |
| 57 | + if ( version_compare( $new, $current, "==" ) ) { |
| 58 | + echo "The new version (${new}) is the same as the current version (${current}).\n"; |
| 59 | + exit( 1 ); |
| 60 | + } |
| 61 | + if ( ! version_compare( $new, $current, ">" ) ) { |
| 62 | + echo "The new version (${new}) must be greater than the current version (${current}).\n"; |
| 63 | + exit( 1 ); |
| 64 | + } |
| 65 | + echo "The new version is greater.\n"; |
| 66 | + ' |
| 67 | +
|
| 68 | + run_release_php_script: |
| 69 | + name: Bump the version and create the PR |
| 70 | + needs: validate_version |
| 71 | + runs-on: ubuntu-latest |
| 72 | + env: |
| 73 | + CURRENT_VERSION: ${{ needs.validate_version.outputs.current_version }} |
| 74 | + GH_TOKEN: ${{ github.token }} |
| 75 | + steps: |
| 76 | + - name: Setup PHP 8.1 |
| 77 | + uses: shivammathur/setup-php@v2 |
| 78 | + with: |
| 79 | + php-version: '8.1' |
| 80 | + extensions: mbstring, json |
| 81 | + |
| 82 | + - name: Configure Git |
| 83 | + run: | |
| 84 | + git config --global user.name 'github-actions[bot]' |
| 85 | + git config --global user.email 'github-actions[bot]@users.noreply.github.com' |
| 86 | +
|
| 87 | + - name: Checkout ${{ github.ref_name }} branch |
| 88 | + uses: actions/checkout@v4 |
| 89 | + with: |
| 90 | + ref: ${{ github.ref_name }} |
| 91 | + fetch-depth: 0 |
| 92 | + |
| 93 | + - name: Install Composer dependencies |
| 94 | + run: composer install --optimize-autoloader --classmap-authoritative |
| 95 | + |
| 96 | + - name: Run bin/release.php script |
| 97 | + run: | |
| 98 | + echo "Running 'php bin/release.php ${{ env.CURRENT_VERSION }} ${{ env.NEW_VERSION }}'" |
| 99 | + echo "n" | php bin/release.php ${{ env.CURRENT_VERSION }} ${{ env.NEW_VERSION }} |
| 100 | + if [ $? -ne 0 ]; then |
| 101 | + echo "Failed to run the release script" |
| 102 | + exit 1 |
| 103 | + fi |
| 104 | + git push --set-upstream origin update/wp-parsely-version-to-${{ env.NEW_VERSION }} |
| 105 | +
|
| 106 | + - name: Format the version changelog |
| 107 | + run: | |
| 108 | + PARSELY_RELEASE_LOG=$(printf '%s' "$PARSELY_RELEASE_LOG" | sed 's/###/##/g') |
| 109 | + echo $PARSELY_RELEASE_LOG |
| 110 | + # Write the multiline variable to $GITHUB_ENV using the correct syntax |
| 111 | + echo "PARSELY_RELEASE_LOG<<EOF" >> $GITHUB_ENV |
| 112 | + echo "$PARSELY_RELEASE_LOG" >> $GITHUB_ENV |
| 113 | + echo "EOF" >> $GITHUB_ENV |
| 114 | + - name: Create PR |
| 115 | + run: | |
| 116 | + gh pr create \ |
| 117 | + --title "Update version number and changelog for ${{ env.NEW_VERSION }} release" \ |
| 118 | + --body "This PR updates the plugin's version number and changelog in preparation for the ${{ env.NEW_VERSION }} release. |
| 119 | +
|
| 120 | + $PARSELY_RELEASE_LOG" \ |
| 121 | + --base ${{ github.ref_name }} \ |
| 122 | + --head update/wp-parsely-version-to-${{ env.NEW_VERSION }} \ |
| 123 | + --assignee ${{ github.actor }} |
0 commit comments