blob: ae74750c5249f03c8a77ba4070b46644cf074dca [file]
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# GitHub Actions Workflow created for handling the release process based on the release draft
# prepared with the Build workflow. Running the publishPlugin task requires the PUBLISH_TOKEN secret
# provided.
name: Release
on:
release:
types: [released]
jobs:
release:
name: Publish Plugin
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
# Free GitHub Actions Environment Disk Space
- name: Maximize Build Space
uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # v1.3.1
with:
tool-cache: false
large-packages: false
# Check out the current repository
# fetch-depth: 0 is required so the post-release version-bump step can
# walk tag history (counting nightlies between releases).
- name: Fetch Sources
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ github.event.release.tag_name }}
fetch-depth: 0
# Set up Java environment for the next steps
- name: Setup Java
uses: actions/setup-java@0f481fcb613427c0f801b606911222b5b6f3083a # v5
with:
distribution: zulu
java-version: 21
# Setup Gradle
- name: Setup Gradle
uses: gradle/actions/setup-gradle@3f131e8634966bd73d06cc69884922b02e6faf92 # v6.2.0
with:
cache-cleanup: always
# Set environment variables
- name: Export Properties
id: properties
shell: bash
run: |
PROPERTIES="$(./gradlew properties --console=plain -q)"
VERSION="$(echo "$PROPERTIES" | grep "^version:" | cut -f2- -d ' ')"
CHANGELOG="$(./gradlew getChangelog --unreleased --no-header --console=plain -q)"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "changelog<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
# Update Unreleased section with the current release note
- name: Patch Changelog
if: ${{ steps.properties.outputs.changelog != '' }}
run: |
./gradlew patchChangelog
# Publish the plugin to JetBrains Marketplace
# The release zip is already attached to the GitHub release by the
# Prepare Release workflow (the artifact PMC voted on); no upload here.
- name: Publish Plugin
env:
PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }}
CERTIFICATE_CHAIN: ${{ secrets.CERTIFICATE_CHAIN }}
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
PRIVATE_KEY_PASSWORD: ${{ secrets.PRIVATE_KEY_PASSWORD }}
run: ./gradlew publishPlugin
# Bump pluginVersion in gradle.properties for the next release cycle.
# BUILD increment = number of nightly tags (= code changes) since the
# previous release. BRANCH and FIX are preserved.
- name: Bump pluginVersion
id: bump
shell: bash
run: |
set -euo pipefail
CURRENT_TAG="${{ github.event.release.tag_name }}"
CURRENT_VERSION="${CURRENT_TAG#v}"
BRANCH_SEG="$(echo "$CURRENT_VERSION" | cut -d. -f1)"
BUILD_SEG="$(echo "$CURRENT_VERSION" | cut -d. -f2)"
FIX_SEG="$(echo "$CURRENT_VERSION" | cut -d. -f3)"
# Previous release tag = newest semver tag (vX.Y.Z) excluding the
# current one and any -nightly.* pre-releases.
PREV_TAG="$(git tag --list 'v*.*.*' --sort=-version:refname \
| grep -v -- '-nightly\.' \
| grep -vF "$CURRENT_TAG" \
| head -1 || true)"
if [ -n "$PREV_TAG" ]; then
NIGHTLY_COUNT="$(git tag --list 'v*-nightly.*' \
--merged "$CURRENT_TAG" \
--no-merged "$PREV_TAG" \
| wc -l | tr -d ' ')"
else
NIGHTLY_COUNT=0
fi
# Always advance BUILD by at least 1 even if no nightlies were tagged.
if [ "$NIGHTLY_COUNT" -lt 1 ]; then
NIGHTLY_COUNT=1
fi
NEW_BUILD=$((BUILD_SEG + NIGHTLY_COUNT))
NEW_VERSION="${BRANCH_SEG}.${NEW_BUILD}.${FIX_SEG}"
echo "Previous release: ${PREV_TAG:-<none>}"
echo "Nightly tags since previous release: ${NIGHTLY_COUNT}"
echo "Bumping pluginVersion: ${CURRENT_VERSION} -> ${NEW_VERSION}"
sed -i "s/^pluginVersion = .*/pluginVersion = ${NEW_VERSION}/" gradle.properties
echo "new_version=${NEW_VERSION}" >> $GITHUB_OUTPUT
echo "nightly_count=${NIGHTLY_COUNT}" >> $GITHUB_OUTPUT
echo "prev_tag=${PREV_TAG:-<none>}" >> $GITHUB_OUTPUT
# Open a single post-release PR with the patched changelog and the
# bumped pluginVersion for the next cycle.
- name: Create Pull Request
if: ${{ steps.properties.outputs.changelog != '' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CHANGELOG: ${{ steps.properties.outputs.changelog }}
run: |
VERSION="${{ steps.properties.outputs.version }}"
NEW_VERSION="${{ steps.bump.outputs.new_version }}"
NIGHTLY_COUNT="${{ steps.bump.outputs.nightly_count }}"
PREV_TAG="${{ steps.bump.outputs.prev_tag }}"
BRANCH="post-release-$VERSION"
git config user.email "action@github.com"
git config user.name "GitHub Action"
git checkout -b $BRANCH
git commit -am "Post-release $VERSION: changelog + bump to $NEW_VERSION"
git push --set-upstream origin $BRANCH
gh pr create \
--title "Post-release \`$VERSION\`: changelog + bump to \`$NEW_VERSION\`" \
--body "Post-release housekeeping for \`$VERSION\`:
- Patched \`CHANGELOG.md\` (move Unreleased → \`$VERSION\`).
- Bumped \`pluginVersion\` in \`gradle.properties\` to \`$NEW_VERSION\` (BUILD +$NIGHTLY_COUNT, counting nightly tags since \`$PREV_TAG\`).
## Changes included in this release
$CHANGELOG" \
--head $BRANCH