blob: ff939990acb5a2e4eb6e1eace996c26a97b8c48e [file]
# Copyright 2025 Google LLC
#
# Licensed 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
#
# https://www.apache.0rg/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.
name: Release Project
permissions:
contents: read
# TODO(b/452391493): Consider triggering the workflow on git release creation instead.
# This workflow is triggered manually from the Actions tab.
on:
workflow_dispatch:
inputs:
version:
description: 'The version to release'
required: false
type: string
base_rc_version:
description: 'The base RC version to use to create the final release. Should be formatted as X.Y.Z-RC.N'
type: string
required: false
push:
branches:
- master
paths:
- 'oss_version.txt'
jobs:
get_version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.version }}
base_rc_version: ${{ steps.get_version.outputs.base_rc_version }}
steps:
- uses: actions/checkout@v4
- id: get_version
run: |
if [ -f "oss_version.txt" ]; then
# Read version from oss_version.txt and prevent manual override.
if [[ "${{ github.event.inputs.version }}" != "" ]]; then
echo "Error: The 'version' input field must not be set for repositories using 'oss_version.txt' (like j2cl)."
exit 1
fi
version=$(xargs < oss_version.txt)
echo "Using version from oss_version.txt: ${version}."
echo "version=${version}" >> "$GITHUB_OUTPUT"
if [[ "${{ github.event.inputs.base_rc_version }}" != "" ]]; then
echo "Error: The 'base_rc_version' input field must not be set for repositories using 'oss_version.txt'."
exit 1
fi
# Auto-detect base_rc_version for final semantic releases by finding the last RC tag.
repo_name="${{ github.event.repository.name }}"
RC_REGEX='^([0-9]+\.[0-9]+\.[0-9]+)-RC\.?[0-9]+$'
VERSION_REGEX='^[0-9]+\.[0-9]+\.[0-9]+$'
base_rc_version=""
if [[ "$version" =~ $VERSION_REGEX ]] && [[ ! "$version" =~ $RC_REGEX ]]; then
echo "This is a final release for a semantic versioned project. Finding last RC tag."
tags=$(git ls-remote --tags --refs ${{ github.server_url }}/${{ github.repository }} "${version}-RC*" | awk -F'refs/tags/' '{print $2}')
if [[ -z "$tags" ]]; then
echo "Error: No tags found starting with ${version}-RC"
exit 1
fi
base_rc_version=$(echo "$tags" | sort -V | tail -n 1)
echo "Found last RC tag: $base_rc_version"
fi
echo "base_rc_version=$base_rc_version" >> "$GITHUB_OUTPUT"
else
echo "version=${{ github.event.inputs.version }}" >> "$GITHUB_OUTPUT"
echo "base_rc_version=${{ github.event.inputs.base_rc_version }}" >> "$GITHUB_OUTPUT"
fi
validate_inputs:
needs: get_version
runs-on: ubuntu-latest
steps:
- name: Validate version
run: |
version="${{ needs.get_version.outputs.version }}"
repo_name="${{ github.event.repository.name }}"
if [[ -z "$version" ]]; then
echo "Error: Release version is missing."
exit 1
fi
if [[ "$repo_name" == "j2cl" || "$repo_name" == "jsinterop-generator" ]]; then
if [[ ! "$version" =~ ^v[0-9]{8}$ ]]; then
echo "Error: Invalid date-based version format. Expected vYYYYMMDD, but got '${version}'."
exit 1
fi
else
if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-RC[0-9]+)?$ ]]; then
echo "Error: Invalid semantic version format. Expected X.Y.Z or X.Y.Z-RCN, but got '${version}'."
exit 1
fi
fi
- name: Validate base RC version
# TODO(dramaix): remove this step when base_rc_version cannot be passed manually
if: github.event.inputs.base_rc_version != ''
run: |
version="${{ needs.get_version.outputs.version }}"
base_rc_version="${{ needs.get_version.outputs.base_rc_version }}"
repo_name="${{ github.event.repository.name }}"
RC_REGEX='^([0-9]+\.[0-9]+\.[0-9]+)-RC[0-9]+$'
# Ensure base_rc_version is not set for repositories that do not use semantic versionning
if [[ "$repo_name" == "jsinterop-generator" || "$repo_name" == "j2cl" ]]; then
echo "Error: The base RC version field should not be set for repository '${repo_name}'."
exit 1
fi
# Ensure base_rc_version is not set for for RC releases.
if [[ "$version" =~ $RC_REGEX ]]; then
echo "Error: If the version '${version}' is an RC version, the base RC version must be empty."
exit 1
fi
# Validate base_rc_version format
if [[ ! "$base_rc_version" =~ $RC_REGEX ]]; then
echo "Error: Invalid base_rc_version format. Expected X.Y.Z-RCN, but got '${base_rc_version}'."
exit 1
fi
# Extract the base version from base_rc_version using the first captured group from the regex match.
# TODO(dramaix): remove when base_rc_version cannot be passed manually
base_version_from_rc="${BASH_REMATCH[1]}"
if [[ "$base_version_from_rc" != "$version" ]]; then
echo "Error: The base_rc_version '${base_rc_version}' does not match the version '${version}'."
exit 1
fi
# Check if the base version is an existing git tag
if ! git ls-remote ${{ github.server_url }}/${{ github.repository }} "refs/tags/${base_rc_version}" | grep -q "refs/tags/${base_rc_version}"; then
echo "Error: The base version '${base_rc_version}' is not a valid tag in the repository."
exit 1
fi
release:
needs: [validate_inputs, get_version]
uses: google/j2cl/.github/workflows/release_common.yaml@master
permissions:
# Permissions for creating a github release.
contents: write
# Permissions for publishing to bcr.
id-token: write
attestations: write
# Pass the inputs from the trigger to the reusable workflow.
with:
version: ${{ needs.get_version.outputs.version }}
git_ref: ${{ needs.get_version.outputs.base_rc_version && format('refs/tags/{0}', needs.get_version.outputs.base_rc_version) || github.ref }}
publish_to_sonatype: ${{ github.event.repository.name != 'jsinterop-generator' && github.event.repository.name != 'j2cl' }}
publish_to_bcr: ${{ github.event.repository.name != 'jsinterop-annotations' }}
# Allow the reusable workflow to access the secrets.
secrets: inherit