Skip to content

Commit

Permalink
Workflow to tag releases, and generate release notes (#29834)
Browse files Browse the repository at this point in the history
Co-authored-by: Karsten Sperling <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
3 people authored and pull[bot] committed Dec 7, 2023
1 parent ee7789a commit 1082038
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/tag-releases.yaml
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions SPECIFICATION_VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.2.0
57 changes: 57 additions & 0 deletions scripts/tagging/tag_new_release.sh
Original file line number Diff line number Diff line change
@@ -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" "$@"

0 comments on commit 1082038

Please sign in to comment.