From 4ea5e656b8065cb855ab0b8d30a41cefa029620e Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Wed, 23 Jul 2025 21:39:42 +0530 Subject: [PATCH 1/4] Create component-release.yml --- .github/workflows/component-release.yml | 96 +++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 .github/workflows/component-release.yml diff --git a/.github/workflows/component-release.yml b/.github/workflows/component-release.yml new file mode 100644 index 00000000..baa7ec56 --- /dev/null +++ b/.github/workflows/component-release.yml @@ -0,0 +1,96 @@ +name: Component Release + +on: + pull_request: + types: [closed] + branches: + - develop + +jobs: + release: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Git + run: | + git config --global user.name "GitHub Actions" + git config --global user.email "actions@github.com" + + - name: Install git-flow and auto-changelog + run: | + sudo apt-get update + sudo apt-get install -y git-flow + npm install -g auto-changelog + + - name: Clone the project and start release + run: | + set -e + git clone https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} project + cd project + git fetch --all + git checkout main || git checkout -b main origin/main + git checkout develop || git checkout -b develop origin/develop + + git config gitflow.branch.master main + git config gitflow.branch.develop develop + git config gitflow.prefix.feature feature/ + git config gitflow.prefix.bugfix bugfix/ + git config gitflow.prefix.release release/ + git config gitflow.prefix.hotfix hotfix/ + git config gitflow.prefix.support support/ + git config gitflow.prefix.versiontag '' + + echo "git config completed" + # Extract version from PR description + PR_DESC="${{ github.event.pull_request.body }}" + + VERSION_FROM_PR=$(echo "$PR_DESC" | grep -oiP 'version\s*:\s*\K[0-9]+\.[0-9]+\.[0-9]+(?=)' || true) + + echo "Extracted version from PR: $VERSION_FROM_PR" + + # Get top tag from CHANGELOG.md + TOP_TAG=$(grep -m 1 -oP '^#### \[\K[^\]]+' CHANGELOG.md) + if [[ -z "$VERSION_FROM_PR" ]]; then + echo "Version not found in PR description" + exit 1 + fi + if [[ -z "$TOP_TAG" ]]; then + echo "No version found in CHANGELOG.md!" + exit 1 + fi + # Compare PR version and top tag + if [[ "$VERSION_FROM_PR" == "$TOP_TAG" || $(printf '%s\n%s' "$VERSION_FROM_PR" "$TOP_TAG" | sort -V | head -n1) != "$TOP_TAG" ]]; then + echo "Invalid version provided" + exit 1 + fi + RELEASE_VERSION="$VERSION_FROM_PR" + echo "Using version from PR description: $RELEASE_VERSION" + echo "RELEASE_VERSION=$RELEASE_VERSION" + echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV + # # Check if tag already exists + if git rev-parse "refs/tags/$RELEASE_VERSION" >/dev/null 2>&1; then + echo "Tag $RELEASE_VERSION already exists. Skipping release." + exit 0 + fi + git flow release start $RELEASE_VERSION + auto-changelog -v $RELEASE_VERSION + git add CHANGELOG.md + git commit -m "$RELEASE_VERSION release changelog updates" + git flow release publish + - name: Finish release and push (default git-flow messages) + run: | + set -e + cd project + git flow release finish -m "$RELEASE_VERSION release" $RELEASE_VERSION + git push origin main + git push origin --tags + git push origin develop + - name: Cleanup tag if workflow fails + if: failure() + run: | + cd project + git tag -d $RELEASE_VERSION || true + git push origin :refs/tags/$RELEASE_VERSION || true From a083ffbbb4ac7a9449ef425d9e755bbeb0d33bba Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Mon, 28 Jul 2025 16:43:46 +0530 Subject: [PATCH 2/4] Update component-release.yml --- .github/workflows/component-release.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/component-release.yml b/.github/workflows/component-release.yml index baa7ec56..04f4f9cc 100644 --- a/.github/workflows/component-release.yml +++ b/.github/workflows/component-release.yml @@ -8,6 +8,7 @@ on: jobs: release: + if: github.event.pull_request.merged == true runs-on: ubuntu-latest steps: @@ -70,7 +71,7 @@ jobs: echo "Using version from PR description: $RELEASE_VERSION" echo "RELEASE_VERSION=$RELEASE_VERSION" echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV - # # Check if tag already exists + # Check if tag already exists if git rev-parse "refs/tags/$RELEASE_VERSION" >/dev/null 2>&1; then echo "Tag $RELEASE_VERSION already exists. Skipping release." exit 0 From 1e97a012856cd5bd60548fd47d24ce3537e1a305 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 5 Aug 2025 23:04:47 +0530 Subject: [PATCH 3/4] Update component-release.yml --- .github/workflows/component-release.yml | 41 ++++++++++++++++--------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/.github/workflows/component-release.yml b/.github/workflows/component-release.yml index 04f4f9cc..544bc091 100644 --- a/.github/workflows/component-release.yml +++ b/.github/workflows/component-release.yml @@ -9,7 +9,7 @@ on: jobs: release: if: github.event.pull_request.merged == true - runs-on: ubuntu-latest + runs-on: comcast-ubuntu-latest steps: - name: Checkout repository @@ -47,28 +47,37 @@ jobs: echo "git config completed" # Extract version from PR description PR_DESC="${{ github.event.pull_request.body }}" - - VERSION_FROM_PR=$(echo "$PR_DESC" | grep -oiP 'version\s*:\s*\K[0-9]+\.[0-9]+\.[0-9]+(?=)' || true) - - echo "Extracted version from PR: $VERSION_FROM_PR" - # Get top tag from CHANGELOG.md TOP_TAG=$(grep -m 1 -oP '^#### \[\K[^\]]+' CHANGELOG.md) - if [[ -z "$VERSION_FROM_PR" ]]; then - echo "Version not found in PR description" - exit 1 - fi if [[ -z "$TOP_TAG" ]]; then echo "No version found in CHANGELOG.md!" exit 1 fi - # Compare PR version and top tag - if [[ "$VERSION_FROM_PR" == "$TOP_TAG" || $(printf '%s\n%s' "$VERSION_FROM_PR" "$TOP_TAG" | sort -V | head -n1) != "$TOP_TAG" ]]; then - echo "Invalid version provided" + # Validate TOP_TAG format (semantic versioning: major.minor.patch) + if [[ ! "$TOP_TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Invalid version format in CHANGELOG.md: $TOP_TAG. Expected format: major.minor.patch" exit 1 fi - RELEASE_VERSION="$VERSION_FROM_PR" - echo "Using version from PR description: $RELEASE_VERSION" + IFS='.' read -r major minor patch <<< "$TOP_TAG" + VERSION_TYPE=$(echo "$PR_DESC" | grep -oiP 'version\s*:\s*\K(major|minor|patch)' | tr '[:upper:]' '[:lower:]') + if [[ -z "$VERSION_TYPE" ]]; then + echo "No version type found in PR description, defaulting to PATCH increment." + patch=$((patch + 1)) + elif [[ "$VERSION_TYPE" == "major" ]]; then + major=$((major + 1)) + minor=0 + patch=0 + elif [[ "$VERSION_TYPE" == "minor" ]]; then + minor=$((minor + 1)) + patch=0 + elif [[ "$VERSION_TYPE" == "patch" ]]; then + patch=$((patch + 1)) + else + echo "Invalid version type in PR description: $VERSION_TYPE" + exit 1 + fi + RELEASE_VERSION="$major.$minor.$patch" + echo "Using calculated version: $RELEASE_VERSION" echo "RELEASE_VERSION=$RELEASE_VERSION" echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV # Check if tag already exists @@ -81,6 +90,7 @@ jobs: git add CHANGELOG.md git commit -m "$RELEASE_VERSION release changelog updates" git flow release publish + - name: Finish release and push (default git-flow messages) run: | set -e @@ -89,6 +99,7 @@ jobs: git push origin main git push origin --tags git push origin develop + - name: Cleanup tag if workflow fails if: failure() run: | From da6aaf64121f72cbf1af250877a3d6b3dff3749b Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Wed, 6 Aug 2025 00:06:06 +0530 Subject: [PATCH 4/4] RDKEMW-4778: Update component-release.yml --- .github/workflows/component-release.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/component-release.yml b/.github/workflows/component-release.yml index 544bc091..541cb73b 100644 --- a/.github/workflows/component-release.yml +++ b/.github/workflows/component-release.yml @@ -1,5 +1,8 @@ name: Component Release +permissions: + contents: write + on: pull_request: types: [closed] @@ -9,7 +12,7 @@ on: jobs: release: if: github.event.pull_request.merged == true - runs-on: comcast-ubuntu-latest + runs-on: ubuntu-latest steps: - name: Checkout repository