-
Notifications
You must be signed in to change notification settings - Fork 18
172 lines (152 loc) · 7.12 KB
/
release.yaml
File metadata and controls
172 lines (152 loc) · 7.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# 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