Skip to content

Commit 4ea5e65

Browse files
authored
Create component-release.yml
1 parent 024be52 commit 4ea5e65

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Component Release
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches:
7+
- develop
8+
9+
jobs:
10+
release:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v3
16+
17+
- name: Set up Git
18+
run: |
19+
git config --global user.name "GitHub Actions"
20+
git config --global user.email "[email protected]"
21+
22+
- name: Install git-flow and auto-changelog
23+
run: |
24+
sudo apt-get update
25+
sudo apt-get install -y git-flow
26+
npm install -g auto-changelog
27+
28+
- name: Clone the project and start release
29+
run: |
30+
set -e
31+
git clone https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} project
32+
cd project
33+
git fetch --all
34+
git checkout main || git checkout -b main origin/main
35+
git checkout develop || git checkout -b develop origin/develop
36+
37+
git config gitflow.branch.master main
38+
git config gitflow.branch.develop develop
39+
git config gitflow.prefix.feature feature/
40+
git config gitflow.prefix.bugfix bugfix/
41+
git config gitflow.prefix.release release/
42+
git config gitflow.prefix.hotfix hotfix/
43+
git config gitflow.prefix.support support/
44+
git config gitflow.prefix.versiontag ''
45+
46+
echo "git config completed"
47+
# Extract version from PR description
48+
PR_DESC="${{ github.event.pull_request.body }}"
49+
50+
VERSION_FROM_PR=$(echo "$PR_DESC" | grep -oiP 'version\s*:\s*\K[0-9]+\.[0-9]+\.[0-9]+(?=)' || true)
51+
52+
echo "Extracted version from PR: $VERSION_FROM_PR"
53+
54+
# Get top tag from CHANGELOG.md
55+
TOP_TAG=$(grep -m 1 -oP '^#### \[\K[^\]]+' CHANGELOG.md)
56+
if [[ -z "$VERSION_FROM_PR" ]]; then
57+
echo "Version not found in PR description"
58+
exit 1
59+
fi
60+
if [[ -z "$TOP_TAG" ]]; then
61+
echo "No version found in CHANGELOG.md!"
62+
exit 1
63+
fi
64+
# Compare PR version and top tag
65+
if [[ "$VERSION_FROM_PR" == "$TOP_TAG" || $(printf '%s\n%s' "$VERSION_FROM_PR" "$TOP_TAG" | sort -V | head -n1) != "$TOP_TAG" ]]; then
66+
echo "Invalid version provided"
67+
exit 1
68+
fi
69+
RELEASE_VERSION="$VERSION_FROM_PR"
70+
echo "Using version from PR description: $RELEASE_VERSION"
71+
echo "RELEASE_VERSION=$RELEASE_VERSION"
72+
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
73+
# # Check if tag already exists
74+
if git rev-parse "refs/tags/$RELEASE_VERSION" >/dev/null 2>&1; then
75+
echo "Tag $RELEASE_VERSION already exists. Skipping release."
76+
exit 0
77+
fi
78+
git flow release start $RELEASE_VERSION
79+
auto-changelog -v $RELEASE_VERSION
80+
git add CHANGELOG.md
81+
git commit -m "$RELEASE_VERSION release changelog updates"
82+
git flow release publish
83+
- name: Finish release and push (default git-flow messages)
84+
run: |
85+
set -e
86+
cd project
87+
git flow release finish -m "$RELEASE_VERSION release" $RELEASE_VERSION
88+
git push origin main
89+
git push origin --tags
90+
git push origin develop
91+
- name: Cleanup tag if workflow fails
92+
if: failure()
93+
run: |
94+
cd project
95+
git tag -d $RELEASE_VERSION || true
96+
git push origin :refs/tags/$RELEASE_VERSION || true

0 commit comments

Comments
 (0)