From 1082038af907e58272c3476e3846e6723c7915e3 Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Mon, 23 Oct 2023 22:10:00 -0700 Subject: [PATCH] Workflow to tag releases, and generate release notes (#29834) Co-authored-by: Karsten Sperling <113487422+ksperling-apple@users.noreply.github.com> Co-authored-by: Restyled.io --- .github/workflows/tag-releases.yaml | 50 +++++++++++++++++++++++++ SPECIFICATION_VERSION | 1 + scripts/tagging/tag_new_release.sh | 57 +++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 .github/workflows/tag-releases.yaml create mode 100644 SPECIFICATION_VERSION create mode 100755 scripts/tagging/tag_new_release.sh diff --git a/.github/workflows/tag-releases.yaml b/.github/workflows/tag-releases.yaml new file mode 100644 index 00000000000000..ff0971e11c2a22 --- /dev/null +++ b/.github/workflows/tag-releases.yaml @@ -0,0 +1,50 @@ +# Copyright (c) 2020-2023 Project CHIP Authors +# +# 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 +# +# 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. +name: "Tag Releases" + +on: + workflow_dispatch: + # inputs: + # draft_release: + # description: 'Create Draft' + # required: true + # default: true + # type: boolean + # branch: + # description: 'Branch' + # required: false + # type: string +jobs: + tag_main_release: + name: Tag Current Release + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Install gh tool + run: | + type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y) + curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \ + && sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \ + && 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 \ + && sudo apt update \ + && sudo apt install gh -y + + - name: Tag Release & Generate Notes + run: | + BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) + echo "Tagging against branch: $BRANCH_NAME" + ./scripts/tagging/tag_new_release.sh --generate-notes --target $BRANCH_NAME -d # Note this is a draft for now. + + diff --git a/SPECIFICATION_VERSION b/SPECIFICATION_VERSION new file mode 100644 index 00000000000000..26aaba0e86632e --- /dev/null +++ b/SPECIFICATION_VERSION @@ -0,0 +1 @@ +1.2.0 diff --git a/scripts/tagging/tag_new_release.sh b/scripts/tagging/tag_new_release.sh new file mode 100755 index 00000000000000..0e26c26de4cfb2 --- /dev/null +++ b/scripts/tagging/tag_new_release.sh @@ -0,0 +1,57 @@ +# +# Copyright (c) 2023 Project CHIP Authors +# +# 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 +# +# 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. +# + +#!/bin/bash + +CURRENT_SPEC_VERSION=$(cat SPECIFICATION_VERSION) + +# Pulls the most recent release from gihub, matching the spec version on the current tree +CURRENT_RELEASE=$(gh release list --exclude-pre-releases | grep -Fi "$CURRENT_SPEC_VERSION" | awk '{print $1}' | head -n1) + +if [ -z "$CURRENT_RELEASE" ]; then + # If there are no releases, this is our first one for this Spec version + SDK_RELEASE_REVISIONS=0 + echo "No revision found for current release" +else + # Otherwise pull the SDK revision (4th item) from the release + SDK_RELEASE_REVISIONS="$(echo "$CURRENT_RELEASE" | cut -d'.' -f4)" +fi + +if [ ! -z "$CURRENT_RELEASE" ]; then + # If there is current release, construct a string like 1.2.0.0 based o the current one + CURRENT_RELEASE="v$CURRENT_SPEC_VERSION.$SDK_RELEASE_REVISIONS" + # Then revise the SDK release to be +1 + SDK_RELEASE_REVISIONS=$(($SDK_RELEASE_REVISIONS + 1)) +fi + +# Construct a final tag, eg: 1.2.0.5 (MAJOR.MINOR.PATCH.SDK_REVISION) +NEW_RELEASE_TAG="v$CURRENT_SPEC_VERSION.$SDK_RELEASE_REVISIONS" + +ADDITIONAL_ARGS="" + +# Look for any prerelease information in the spec version (eg: 1.3.0-sve), and target the prerelease channel +case "$NEW_RELEASE_TAG" in + *alpha* | *beta* | *prerelease* | *testevent* | *te* | *sve*) + ADDITIONAL_ARGS="$ADDITIONAL_ARGS --prerelease" + ;; +esac + +echo "Current release: $CURRENT_RELEASE" +echo "SDK release revisions: $SDK_RELEASE_REVISIONS" +echo "New release: $NEW_RELEASE_TAG" +echo "Additional arguments: $ADDITIONAL_ARGS" + +gh release create "$ADDITIONAL_ARGS" --notes-start-tag "$CURRENT_RELEASE" "$NEW_RELEASE_TAG" "$@"