|
4 | 4 | # - Run Qodana inspections. |
5 | 5 | # - Run the 'buildPlugin' task and prepare artifact for further tests. |
6 | 6 | # - Run the 'runPluginVerifier' task. |
7 | | -# - Create a draft release. |
| 7 | +# - Tag a released version, or keep the next release in a pull request. |
8 | 8 | # |
9 | 9 | # The workflow is triggered on push and pull_request events. |
10 | 10 | # |
@@ -234,40 +234,73 @@ jobs: |
234 | 234 | name: pluginVerifier-result-${{ matrix.phpApi }} |
235 | 235 | path: ${{ github.workspace }}/${{ matrix.buildDir }}/reports/pluginVerifier |
236 | 236 |
|
237 | | - # Prepare a draft release for GitHub Releases page for the manual verification |
238 | | - # If accepted and published, the release workflow would be triggered |
239 | | - releaseDraft: |
240 | | - name: Release draft |
| 237 | + # A version whose changelog section is on main gets its tag and GitHub release (which runs release.yml); the rest of |
| 238 | + # [Unreleased] is kept in a "release: <next>" pull request. Versions are <year>.<N>: N grows, a new year starts at 0. |
| 239 | + releasePr: |
| 240 | + name: Release PR |
241 | 241 | if: github.event_name != 'pull_request' |
242 | 242 | needs: [ build, test, inspectCode, verify ] |
243 | 243 | runs-on: ubuntu-latest |
244 | 244 | permissions: |
245 | 245 | contents: write |
| 246 | + pull-requests: write |
| 247 | + env: |
| 248 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 249 | + BRANCH: release/next |
246 | 250 | steps: |
247 | 251 |
|
248 | 252 | # Check out the current repository |
249 | 253 | - name: Fetch Sources |
250 | 254 | uses: actions/checkout@v7 |
251 | 255 |
|
252 | | - # Remove old release drafts by using the curl request for the available releases with a draft flag |
253 | | - - name: Remove Old Release Drafts |
254 | | - env: |
255 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
256 | | - run: | |
257 | | - gh api repos/{owner}/{repo}/releases \ |
258 | | - --jq '.[] | select(.draft == true) | .id' \ |
259 | | - | xargs -I '{}' gh api -X DELETE repos/{owner}/{repo}/releases/{} |
260 | | -
|
261 | | - # Create a new release draft which is not publicly visible and requires manual acceptance |
262 | | - - name: Create Release Draft |
263 | | - env: |
264 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 256 | + # Set up the Java environment for the next steps |
| 257 | + - name: Setup Java |
| 258 | + uses: actions/setup-java@v6 |
| 259 | + with: |
| 260 | + distribution: zulu |
| 261 | + java-version: 21 |
| 262 | + |
| 263 | + # Setup Gradle |
| 264 | + - name: Setup Gradle |
| 265 | + uses: gradle/actions/setup-gradle@v6.4.0 |
| 266 | + with: |
| 267 | + cache-read-only: true |
| 268 | + |
| 269 | + - name: Release or Update Release PR |
265 | 270 | run: | |
266 | | - VERSION=$(./gradlew properties --property version --quiet --console=plain | tail -n 1 | cut -f2- -d ' ') |
267 | | - RELEASE_NOTE="./build/tmp/release_note.txt" |
268 | | - ./gradlew getChangelog --unreleased --no-header --quiet --console=plain --output-file=$RELEASE_NOTE |
269 | | - |
270 | | - gh release create $VERSION \ |
271 | | - --draft \ |
272 | | - --title $VERSION \ |
273 | | - --notes-file $RELEASE_NOTE |
| 271 | + GRADLE="./gradlew --quiet --console=plain" |
| 272 | + NOTES="./build/tmp/release_note.txt" |
| 273 | + mkdir -p "$(dirname "$NOTES")" |
| 274 | + CURRENT=$($GRADLE properties --property pluginVersion | tail -n 1 | cut -f2- -d ' ') |
| 275 | +
|
| 276 | + if grep -Fq "## [$CURRENT]" CHANGELOG.md; then |
| 277 | + if ! git ls-remote --exit-code --tags origin "refs/tags/v$CURRENT" > /dev/null; then |
| 278 | + $GRADLE getChangelog --project-version="$CURRENT" --no-header --no-links --output-file="$NOTES" |
| 279 | + gh release create "v$CURRENT" --target "$GITHUB_SHA" --title "$CURRENT" --notes-file "$NOTES" |
| 280 | + fi |
| 281 | + YEAR=$(date -u +%Y) |
| 282 | + if [ "${CURRENT%%.*}" = "$YEAR" ]; then NEXT="$YEAR.$(( ${CURRENT#*.} + 1 ))"; else NEXT="$YEAR.0"; fi |
| 283 | + else |
| 284 | + NEXT="$CURRENT" |
| 285 | + fi |
| 286 | +
|
| 287 | + $GRADLE getChangelog --unreleased --no-header --no-empty-sections --no-links --output-file="$NOTES" |
| 288 | + if ! grep -q '^- ' "$NOTES"; then |
| 289 | + echo "Nothing unreleased" |
| 290 | + exit 0 |
| 291 | + fi |
| 292 | +
|
| 293 | + sed -i "s/^pluginVersion = .*/pluginVersion = $NEXT/" gradle.properties |
| 294 | + $GRADLE patchChangelog |
| 295 | +
|
| 296 | + git config user.email "action@github.com" |
| 297 | + git config user.name "GitHub Action" |
| 298 | + git checkout -B "$BRANCH" |
| 299 | + git commit -qam "release: $NEXT" |
| 300 | + git push --force origin "$BRANCH" |
| 301 | +
|
| 302 | + if [ "$(gh pr view "$BRANCH" --json state --jq .state 2>/dev/null)" = "OPEN" ]; then |
| 303 | + gh pr edit "$BRANCH" --title "release: $NEXT" --body-file "$NOTES" |
| 304 | + else |
| 305 | + gh pr create --base main --head "$BRANCH" --title "release: $NEXT" --body-file "$NOTES" |
| 306 | + fi |
0 commit comments