-
Notifications
You must be signed in to change notification settings - Fork 3
RDKEMW-4778 : Automate git flow merges to main branch for entservices repos #209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4ea5e65
Create component-release.yml
ssitar583 84e11ba
Merge branch 'develop' into topic/RDKEMW-4778-tag
ssitar583 c8fd318
Merge pull request #212 from rdkcentral/develop
ssitar583 a083ffb
Update component-release.yml
ssitar583 1e97a01
Update component-release.yml
ssitar583 f80c401
Merge pull request #226 from rdkcentral/develop
ssitar583 da6aaf6
RDKEMW-4778: Update component-release.yml
ssitar583 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
name: Component Release | ||
|
||
on: | ||
pull_request: | ||
types: [closed] | ||
branches: | ||
- develop | ||
|
||
jobs: | ||
release: | ||
if: github.event.pull_request.merged == true | ||
runs-on: comcast-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 "[email protected]" | ||
|
||
- 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 }}" | ||
# Get top tag from CHANGELOG.md | ||
TOP_TAG=$(grep -m 1 -oP '^#### \[\K[^\]]+' CHANGELOG.md) | ||
if [[ -z "$TOP_TAG" ]]; then | ||
echo "No version found in CHANGELOG.md!" | ||
exit 1 | ||
fi | ||
# 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 | ||
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 | ||
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 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.