Skip to content

Commit 365a9c8

Browse files
authored
chore: Github action to help with release freezes (#12731)
1 parent df47cd1 commit 365a9c8

File tree

3 files changed

+129
-0
lines changed

3 files changed

+129
-0
lines changed

.github/workflows/release-freeze.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Freeze releases
2+
on:
3+
workflow_dispatch:
4+
5+
jobs:
6+
generate-updates:
7+
if: ${{ github.repository == 'googleapis/elixir-google-api' }}
8+
runs-on: ubuntu-latest
9+
env:
10+
GITHUB_TOKEN: ${{ secrets.YOSHI_CODE_BOT_TOKEN }}
11+
steps:
12+
- name: Checkout repo
13+
uses: actions/checkout@v4
14+
- name: Install Ruby 3.3
15+
uses: ruby/setup-ruby@v1
16+
with:
17+
ruby-version: "3.3"
18+
- name: Install tools
19+
run: |
20+
gem install --no-document toys
21+
- name: execute
22+
run: |
23+
toys freeze-releases -v --fork --on
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Unfreeze releases
2+
on:
3+
workflow_dispatch:
4+
5+
jobs:
6+
generate-updates:
7+
if: ${{ github.repository == 'googleapis/elixir-google-api' }}
8+
runs-on: ubuntu-latest
9+
env:
10+
GITHUB_TOKEN: ${{ secrets.YOSHI_CODE_BOT_TOKEN }}
11+
steps:
12+
- name: Checkout repo
13+
uses: actions/checkout@v4
14+
- name: Install Ruby 3.3
15+
uses: ruby/setup-ruby@v1
16+
with:
17+
ruby-version: "3.3"
18+
- name: Install tools
19+
run: |
20+
gem install --no-document toys
21+
- name: execute
22+
run: |
23+
toys freeze-releases -v --fork --off

.toys/freeze-releases.rb

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
require "uri"
16+
17+
desc "Freeze or unfreeze releases."
18+
19+
flag :git_remote, "--remote=NAME" do
20+
desc "The name of the git remote to use as the pull request head. If omitted, does not open a pull request."
21+
end
22+
flag :enable_fork, "--fork" do
23+
desc "The github user for whom to create/use a fork"
24+
end
25+
26+
exactly_one desc: "Operations" do
27+
flag :on, desc: "Turn on the release freeze"
28+
flag :off, desc: "Turn off the release freeze"
29+
end
30+
31+
include :exec, e: true
32+
include :terminal
33+
34+
include "yoshi-pr-generator"
35+
36+
def run
37+
setup
38+
result = pr_update_freeze
39+
check_result result
40+
end
41+
42+
def setup
43+
yoshi_utils.git_ensure_identity
44+
if enable_fork
45+
set :git_remote, "pull-request-fork" unless git_remote
46+
yoshi_utils.gh_ensure_fork remote: git_remote
47+
end
48+
end
49+
50+
def pr_update_freeze
51+
timestamp = Time.now.utc.strftime("%Y%m%d-%H%M%S")
52+
file_path = "#{context_directory}/.kokoro/release.sh"
53+
branch_name = "pr/freeze-update-#{timestamp}"
54+
commit_message = "chore: #{on ? 'Activate' : 'Deactivate'} release freeze"
55+
yoshi_pr_generator.capture enabled: !git_remote.nil?,
56+
remote: git_remote,
57+
branch_name: branch_name,
58+
commit_message: commit_message do
59+
content = File.read file_path
60+
new_line = on ? "FREEZE_RELEASES=true" : "FREEZE_RELEASES="
61+
new_content = content.gsub(/FREEZE_RELEASES=.*$/, new_line)
62+
if content == new_content
63+
puts "No changes for release freeze", :yellow, :bold
64+
exit 1
65+
end
66+
File.write file_path, new_content
67+
end
68+
end
69+
70+
def check_result result
71+
case result
72+
when Integer
73+
puts "Opened pull request #{result}", :green, :bold
74+
when :unchanged
75+
puts "No changes for release freeze", :yellow, :bold
76+
exit 1
77+
when :aborted
78+
puts "Error when modifying scripts for release freeze", :red, :bold
79+
exit 1
80+
else
81+
puts "Modified scripts for release freeze", :cyan
82+
end
83+
end

0 commit comments

Comments
 (0)