|
| 1 | +name: Prepare release |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [created, edited] |
| 6 | + |
| 7 | +concurrency: |
| 8 | + group: release-prepare-${{ github.event.release.tag_name }} |
| 9 | + cancel-in-progress: false |
| 10 | + |
| 11 | +jobs: |
| 12 | + prepare-release: |
| 13 | + name: Prepare release PR and build plugin zip |
| 14 | + if: >- |
| 15 | + github.repository == 'WordPress/sqlite-database-integration' |
| 16 | + && github.event.release.draft == true |
| 17 | + runs-on: ubuntu-latest |
| 18 | + permissions: |
| 19 | + contents: write |
| 20 | + pull-requests: write |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Checkout repository |
| 24 | + uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + ref: trunk |
| 27 | + |
| 28 | + - name: Extract version and changelog |
| 29 | + id: release_info |
| 30 | + env: |
| 31 | + RELEASE_TAG: ${{ github.event.release.tag_name }} |
| 32 | + RELEASE_BODY: ${{ github.event.release.body }} |
| 33 | + run: | |
| 34 | + # Extract version from tag (strip leading "v" if present). |
| 35 | + VERSION="${RELEASE_TAG#v}" |
| 36 | + if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then |
| 37 | + echo "::error::Invalid version format: '$VERSION' (expected semver like '1.2.3')" |
| 38 | + exit 1 |
| 39 | + fi |
| 40 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 41 | +
|
| 42 | + # Extract changelog, converting markdown list items to WP readme format. |
| 43 | + CHANGELOG=$(echo "$RELEASE_BODY" | sed 's/^- /* /' | sed 's/^[[:space:]]*- /* /') |
| 44 | + { |
| 45 | + echo "changelog<<CHANGELOG_EOF" |
| 46 | + echo "$CHANGELOG" |
| 47 | + echo "CHANGELOG_EOF" |
| 48 | + } >> $GITHUB_OUTPUT |
| 49 | +
|
| 50 | + # Branch name for the release PR. |
| 51 | + echo "branch=release/v$VERSION" >> $GITHUB_OUTPUT |
| 52 | +
|
| 53 | + - name: Create release branch |
| 54 | + env: |
| 55 | + BRANCH: ${{ steps.release_info.outputs.branch }} |
| 56 | + run: | |
| 57 | + git checkout -B "$BRANCH" |
| 58 | +
|
| 59 | + - name: Bump version numbers |
| 60 | + env: |
| 61 | + VERSION: ${{ steps.release_info.outputs.version }} |
| 62 | + run: | |
| 63 | + # Update version.php |
| 64 | + sed -i "s/define( 'SQLITE_DRIVER_VERSION', '.*' );/define( 'SQLITE_DRIVER_VERSION', '$VERSION' );/" \ |
| 65 | + packages/mysql-on-sqlite/src/version.php |
| 66 | +
|
| 67 | + # Update plugin header |
| 68 | + sed -i "s/^\( \* Version:\).*/\1 $VERSION/" \ |
| 69 | + packages/plugin-sqlite-database-integration/load.php |
| 70 | +
|
| 71 | + # Update readme.txt stable tag |
| 72 | + sed -i "s/^Stable tag:.*/Stable tag: $VERSION/" \ |
| 73 | + packages/plugin-sqlite-database-integration/readme.txt |
| 74 | +
|
| 75 | + - name: Update changelog in readme.txt |
| 76 | + env: |
| 77 | + VERSION: ${{ steps.release_info.outputs.version }} |
| 78 | + CHANGELOG: ${{ steps.release_info.outputs.changelog }} |
| 79 | + run: | |
| 80 | + README="packages/plugin-sqlite-database-integration/readme.txt" |
| 81 | +
|
| 82 | + # Build the new changelog entry. |
| 83 | + ENTRY=$(printf "= %s =\n\n%s\n" "$VERSION" "$CHANGELOG") |
| 84 | +
|
| 85 | + if grep -q "^== Changelog ==" "$README"; then |
| 86 | + # Insert the new entry after the == Changelog == header. |
| 87 | + awk -v entry="$ENTRY" ' |
| 88 | + /^== Changelog ==/ { print; print ""; print entry; next } |
| 89 | + { print } |
| 90 | + ' "$README" > "$README.tmp" && mv "$README.tmp" "$README" |
| 91 | + else |
| 92 | + # Add a changelog section at the end. |
| 93 | + printf "\n== Changelog ==\n\n%s\n" "$ENTRY" >> "$README" |
| 94 | + fi |
| 95 | +
|
| 96 | + - name: Commit version bump |
| 97 | + env: |
| 98 | + VERSION: ${{ steps.release_info.outputs.version }} |
| 99 | + BRANCH: ${{ steps.release_info.outputs.branch }} |
| 100 | + run: | |
| 101 | + git config user.name "github-actions[bot]" |
| 102 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 103 | + git add -A |
| 104 | + git commit -m "Bump version to $VERSION" |
| 105 | + git push -f origin "$BRANCH" |
| 106 | +
|
| 107 | + - name: Build plugin zip |
| 108 | + run: composer run build |
| 109 | + |
| 110 | + - name: Upload zip to draft release |
| 111 | + env: |
| 112 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 113 | + RELEASE_TAG: ${{ github.event.release.tag_name }} |
| 114 | + run: | |
| 115 | + # Remove any previously uploaded zip. |
| 116 | + gh release delete-asset "$RELEASE_TAG" "sqlite-database-integration.zip" --yes 2>/dev/null || true |
| 117 | + # Upload the new zip. |
| 118 | + gh release upload "$RELEASE_TAG" "build/sqlite-database-integration.zip" |
| 119 | +
|
| 120 | + - name: Create or update pull request |
| 121 | + id: pr |
| 122 | + env: |
| 123 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 124 | + VERSION: ${{ steps.release_info.outputs.version }} |
| 125 | + BRANCH: ${{ steps.release_info.outputs.branch }} |
| 126 | + run: | |
| 127 | + # Check if a PR already exists for this branch. |
| 128 | + EXISTING_PR=$(gh pr list --head "$BRANCH" --base trunk --json number --jq '.[0].number // empty') |
| 129 | +
|
| 130 | + if [ -n "$EXISTING_PR" ]; then |
| 131 | + PR_URL=$(gh pr view "$EXISTING_PR" --json url --jq '.url') |
| 132 | + echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT |
| 133 | + else |
| 134 | + PR_URL=$(gh pr create \ |
| 135 | + --base trunk \ |
| 136 | + --head "$BRANCH" \ |
| 137 | + --title "Release $VERSION" \ |
| 138 | + --body "Version bump and changelog update for release $VERSION.") |
| 139 | + echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT |
| 140 | + fi |
| 141 | +
|
| 142 | + - name: Add PR link to draft release |
| 143 | + env: |
| 144 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 145 | + RELEASE_TAG: ${{ github.event.release.tag_name }} |
| 146 | + RELEASE_BODY: ${{ github.event.release.body }} |
| 147 | + PR_URL: ${{ steps.pr.outputs.pr_url }} |
| 148 | + run: | |
| 149 | + PR_NOTE="> To publish the release, review and merge: $PR_URL" |
| 150 | +
|
| 151 | + # Remove any existing PR note, then append the new one. |
| 152 | + CLEAN_BODY=$(echo "$RELEASE_BODY" | grep -v "^> To publish the release, review and merge:") |
| 153 | + NEW_BODY=$(printf "%s\n\n%s" "$CLEAN_BODY" "$PR_NOTE") |
| 154 | +
|
| 155 | + gh release edit "$RELEASE_TAG" --notes "$NEW_BODY" |
0 commit comments