Skip to content

Commit ad542e0

Browse files
woody-appleksperling-applerestyled-commits
authored
Workflow to tag releases, and generate release notes (project-chip#29834)
Co-authored-by: Karsten Sperling <113487422+ksperling-apple@users.noreply.github.com> Co-authored-by: Restyled.io <commits@restyled.io>
1 parent f08756a commit ad542e0

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed

.github/workflows/tag-releases.yaml

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright (c) 2020-2023 Project CHIP Authors
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+
name: "Tag Releases"
15+
16+
on:
17+
workflow_dispatch:
18+
# inputs:
19+
# draft_release:
20+
# description: 'Create Draft'
21+
# required: true
22+
# default: true
23+
# type: boolean
24+
# branch:
25+
# description: 'Branch'
26+
# required: false
27+
# type: string
28+
jobs:
29+
tag_main_release:
30+
name: Tag Current Release
31+
runs-on: ubuntu-latest
32+
steps:
33+
- name: Checkout
34+
uses: actions/checkout@v4
35+
- name: Install gh tool
36+
run: |
37+
type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y)
38+
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
39+
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
40+
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
41+
&& sudo apt update \
42+
&& sudo apt install gh -y
43+
44+
- name: Tag Release & Generate Notes
45+
run: |
46+
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
47+
echo "Tagging against branch: $BRANCH_NAME"
48+
./scripts/tagging/tag_new_release.sh --generate-notes --target $BRANCH_NAME -d # Note this is a draft for now.
49+
50+

SPECIFICATION_VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.2.0

scripts/tagging/tag_new_release.sh

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#
2+
# Copyright (c) 2023 Project CHIP Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
#!/bin/bash
18+
19+
CURRENT_SPEC_VERSION=$(cat SPECIFICATION_VERSION)
20+
21+
# Pulls the most recent release from gihub, matching the spec version on the current tree
22+
CURRENT_RELEASE=$(gh release list --exclude-pre-releases | grep -Fi "$CURRENT_SPEC_VERSION" | awk '{print $1}' | head -n1)
23+
24+
if [ -z "$CURRENT_RELEASE" ]; then
25+
# If there are no releases, this is our first one for this Spec version
26+
SDK_RELEASE_REVISIONS=0
27+
echo "No revision found for current release"
28+
else
29+
# Otherwise pull the SDK revision (4th item) from the release
30+
SDK_RELEASE_REVISIONS="$(echo "$CURRENT_RELEASE" | cut -d'.' -f4)"
31+
fi
32+
33+
if [ ! -z "$CURRENT_RELEASE" ]; then
34+
# If there is current release, construct a string like 1.2.0.0 based o the current one
35+
CURRENT_RELEASE="v$CURRENT_SPEC_VERSION.$SDK_RELEASE_REVISIONS"
36+
# Then revise the SDK release to be +1
37+
SDK_RELEASE_REVISIONS=$(($SDK_RELEASE_REVISIONS + 1))
38+
fi
39+
40+
# Construct a final tag, eg: 1.2.0.5 (MAJOR.MINOR.PATCH.SDK_REVISION)
41+
NEW_RELEASE_TAG="v$CURRENT_SPEC_VERSION.$SDK_RELEASE_REVISIONS"
42+
43+
ADDITIONAL_ARGS=""
44+
45+
# Look for any prerelease information in the spec version (eg: 1.3.0-sve), and target the prerelease channel
46+
case "$NEW_RELEASE_TAG" in
47+
*alpha* | *beta* | *prerelease* | *testevent* | *te* | *sve*)
48+
ADDITIONAL_ARGS="$ADDITIONAL_ARGS --prerelease"
49+
;;
50+
esac
51+
52+
echo "Current release: $CURRENT_RELEASE"
53+
echo "SDK release revisions: $SDK_RELEASE_REVISIONS"
54+
echo "New release: $NEW_RELEASE_TAG"
55+
echo "Additional arguments: $ADDITIONAL_ARGS"
56+
57+
gh release create "$ADDITIONAL_ARGS" --notes-start-tag "$CURRENT_RELEASE" "$NEW_RELEASE_TAG" "$@"

0 commit comments

Comments
 (0)