-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #372 from 1AhmedYasser/added-automated-pipelines
Added Automated Pipelines
- Loading branch information
Showing
8 changed files
with
368 additions
and
37 deletions.
There are no files selected for viewing
This file contains 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,73 @@ | ||
name: Check Version | ||
|
||
on: | ||
push: | ||
branches: ["test", "stage", "main"] | ||
workflow_dispatch: | ||
|
||
env: | ||
BRANCH: ${{ github.head_ref || github.ref_name }} | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Docker Setup BuildX | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Bump Patch Version | ||
run: npm run bump-patch | ||
if: ${{ env.BRANCH == 'test' }} | ||
|
||
- name: Sync Version | ||
run: npm run sync-version | ||
if: ${{ env.BRANCH != 'test' }} | ||
|
||
- name: Generate Changelog | ||
run: npm run changelog | ||
|
||
- name: Push changes to repo | ||
run: | | ||
git config --global user.name ${{ secrets.ADMIN_NAME }} | ||
git config --global user.email ${{ secrets.ADMIN_EMAIL }} | ||
git add . | ||
git commit -m "docs: update version" | ||
git push | ||
- name: Load environment variables | ||
run: | | ||
awk -v branch="${{ env.BRANCH }}" ' /^[0-9a-zA-Z]+$/ { current_branch = $0; } current_branch == branch && /^[A-Z_]+=/{ print $0; }' release.env >> $GITHUB_ENV | ||
- name: Set repo | ||
run: | | ||
LOWER_CASE_GITHUB_REPOSITORY=$(echo $GITHUB_REPOSITORY | tr '[:upper:]' '[:lower:]') | ||
echo "DOCKER_TAG_CUSTOM=ghcr.io/${LOWER_CASE_GITHUB_REPOSITORY}:v${{ env.MAJOR }}.${{ env.MINOR }}.${{ env.PATCH }}" >> $GITHUB_ENV | ||
echo "$GITHUB_ENV" | ||
- name: Build Docker image | ||
run: | | ||
echo "Building Docker image for branch: ${{ env.BRANCH }} major: ${{ env.MAJOR }} minor: ${{ env.MINOR }} patch: ${{ env.PATCH }}" | ||
docker image build --tag $DOCKER_TAG_CUSTOM --no-cache . | ||
if: ${{ env.BRANCH == 'test' }} | ||
|
||
- name: Log in to GitHub container registry | ||
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin | ||
|
||
- name: Push Docker image to GitHub Packages | ||
run: | | ||
echo "Pushing Docker image to GitHub Packages" | ||
docker push $DOCKER_TAG_CUSTOM | ||
if: ${{ env.BRANCH == 'test' }} | ||
|
||
- name: Create Release | ||
uses: softprops/action-gh-release@v1 | ||
if: ${{ env.BRANCH == 'main' }} | ||
with: | ||
tag_name: v${{ env.MAJOR }}.${{ env.MINOR }}.${{ env.PATCH }} | ||
generate_release_notes: true | ||
body_path: ${{ github.workspace }}/CHANGELOG.md |
This file was deleted.
Oops, something went wrong.
This file contains 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,24 @@ | ||
# !/bin/bash | ||
|
||
message="$(head -1 $1)" | ||
|
||
message_pattern="^(feat|fix|chore|docs|refactor|style|test)\([0-9]+\):\ .+$" | ||
|
||
if ! [[ $message =~ $message_pattern ]]; | ||
then | ||
echo "---" | ||
echo "Violation of commit message format!" | ||
echo "The commit message must follow the Conventional Commits standard:" | ||
echo "[type(scope): description]" | ||
echo "Example: feat(100): Implement automated pipeline for code commits" | ||
echo "Accepted types: feat, fix, chore, docs, refactor, style, test" | ||
echo "(1) feat: Added a new feature" | ||
echo "(2) fix: Fixed a bug" | ||
echo "(3) chore: Added changes that do not relate to a fix or feature and don't modify src or test files (for example updating dependencies)" | ||
echo "(4) docs: Added updates to documentation such as a the README or other markdown files" | ||
echo "(5) refactor: Refactored code that neither fixes a bug nor adds a feature" | ||
echo "(6) style: Added Changes that do not affect the meaning of the code, likely related to code formatting such as white-space, missing semi-colons, and so on" | ||
echo "(7) test: Included new or corrected previous tests" | ||
echo "---" | ||
exit 1 | ||
fi |
This file contains 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,96 @@ | ||
#!/bin/bash | ||
|
||
# This script is used to bump the version number based on the bump type provided to the current branch. | ||
|
||
# Check if the bump type is provided | ||
if [ "$#" -ne 1 ]; then | ||
echo "Usage: $0 {major|minor|patch}" | ||
exit 1 | ||
fi | ||
|
||
# Get the current branch name | ||
current_branch=$(git branch --show-current) | ||
|
||
# Initialize variables | ||
found_branch=false | ||
bump_type=$1 | ||
|
||
# Read the environment content from the file | ||
env_file=$(<release.env) | ||
|
||
# Get the version based on the current branch | ||
while IFS= read -r line; do | ||
if [ "$line" == "$current_branch" ]; then | ||
found_branch=true | ||
elif [ "$found_branch" == true ]; then | ||
if [[ "$line" == MAJOR=* || "$line" == MINOR=* || "$line" == PATCH=* ]]; then | ||
var_name="${line%%=*}" | ||
var_value="${line#*=}" | ||
|
||
if [[ "$var_name" == "MAJOR" || "$var_name" == "MINOR" || "$var_name" == "PATCH" ]]; then | ||
declare -i "$var_name=$var_value" | ||
fi | ||
else | ||
break | ||
fi | ||
fi | ||
done <<< "$env_file" | ||
|
||
# Increment the version number based on the bump type | ||
if [ "$found_branch" == true ]; then | ||
case "$bump_type" in | ||
major) | ||
MAJOR=$((MAJOR + 1)) | ||
MINOR=0 | ||
PATCH=0 | ||
;; | ||
minor) | ||
MINOR=$((MINOR + 1)) | ||
PATCH=0 | ||
;; | ||
patch) | ||
PATCH=$((PATCH + 1)) | ||
;; | ||
*) | ||
echo "Invalid bump type: $bump_type" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
updated_content=$(awk -v branch="$current_branch" -v major="$MAJOR" -v minor="$MINOR" -v patch="$PATCH" ' | ||
BEGIN { found = 0 } | ||
$0 == branch { | ||
print $0; | ||
found=1; | ||
next | ||
} | ||
# If the branch was found, replace MAJOR, MINOR, and PATCH values | ||
found && $0 ~ /^MAJOR=/ { | ||
print "MAJOR=" major | ||
next | ||
} | ||
found && $0 ~ /^MINOR=/ { | ||
print "MINOR=" minor | ||
next | ||
} | ||
found && $0 ~ /^PATCH=/ { | ||
print "PATCH=" patch | ||
next | ||
} | ||
# Check for the start of a new branch. If a new branch is found, stop processing the values of the previous branch. | ||
/^[a-zA-Z]+$/ { | ||
if (found) { | ||
found = 0 # Reset found when a new branch is encountered | ||
} | ||
} | ||
# If we have not found the branch yet, just print the line | ||
{ print $0 } | ||
' release.env) | ||
|
||
echo -e "$updated_content" > "release.env" | ||
fi |
This file contains 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,105 @@ | ||
#!/bin/bash | ||
|
||
append=${1:-false}; [ "$append" = "true" ] && append=true || append=false | ||
|
||
env_file=$(<release.env) | ||
|
||
REMOTE_URL=$(git config --get remote.origin.url) | ||
|
||
if [[ $REMOTE_URL == git@* ]]; then | ||
REPO_NAME=$(echo "$REMOTE_URL" | sed -E 's/git@([^:]+):(.*).git/\1\/\2/') | ||
REPO_URL="https://$REPO_NAME" | ||
else | ||
REPO_URL=${REMOTE_URL%.git} | ||
fi | ||
|
||
current_branch=$(git branch --show-current) | ||
current_version="" | ||
|
||
# Get version based on current branch | ||
found_branch=false | ||
while IFS= read -r line; do | ||
if [ "$line" == "$current_branch" ]; then | ||
found_branch=true | ||
elif [ "$found_branch" == true ]; then | ||
if [[ "$line" == MAJOR=* || "$line" == MINOR=* || "$line" == PATCH=* ]]; then | ||
var_name="${line%%=*}" | ||
var_value="${line#*=}" | ||
|
||
if [[ "$var_name" == "MAJOR" || "$var_name" == "MINOR" || "$var_name" == "PATCH" ]]; then | ||
declare -i "$var_name=$var_value" | ||
fi | ||
else | ||
break | ||
fi | ||
fi | ||
done <<< "$env_file" | ||
|
||
if [ "$found_branch" == true ]; then | ||
current_version="$MAJOR.$MINOR.$PATCH " | ||
fi | ||
|
||
# Prepare the changelog content | ||
changelog_content=$(cat <<EOF | ||
### $current_version($(date +"%d, %b %Y")) | ||
EOF | ||
) | ||
|
||
features=() | ||
fixes=() | ||
docs=() | ||
styles=() | ||
refactors=() | ||
tests=() | ||
chores=() | ||
others=() | ||
|
||
latest_merge_commit=$(git rev-list --merges --first-parent -n 1 origin/"${current_branch}") | ||
parent1=$(git rev-parse "${latest_merge_commit}"^1) # For Current branch | ||
parent2=$(git rev-parse "${latest_merge_commit}"^2) # For Branch that was merged | ||
common_ancestor=$(git merge-base "${parent1}" "${parent2}") | ||
commit_log=$(git log "${common_ancestor}".."${parent2}" --oneline --pretty=format:"%s by [<u>@%an</u>](https://www.github.com/%an) in [#%h]($REPO_URL/commit/%h)") | ||
|
||
while read -r line; do | ||
pattern="^([^(:]+)\(([^)]+)\): (.*)" | ||
|
||
if [[ $line =~ $pattern ]]; then | ||
type="${BASH_REMATCH[1]}" | ||
scope="${BASH_REMATCH[2]}" | ||
description="${BASH_REMATCH[3]}" | ||
rest_of_line="**$scope**: $description" | ||
else | ||
type="others" | ||
rest_of_line="$line" | ||
fi | ||
|
||
author_link=$(echo "$rest_of_line" | grep -o 'https://www.github.com/[[:alnum:][:space:]]*' | tr -d '[:space:]') | ||
rest_of_line=$(echo "$rest_of_line" | awk -v replacement="$author_link" '{gsub(/https:\/\/www\.github\.com\/[[:alnum:][:space:]]*/, replacement); print}') | ||
|
||
case $type in | ||
"feat") features+=("- $rest_of_line");; | ||
"fix") fixes+=("- $rest_of_line");; | ||
"docs") docs+=("- $rest_of_line");; | ||
"style") styles+=("- $rest_of_line");; | ||
"refactor") refactors+=("- $rest_of_line");; | ||
"test") tests+=("- $rest_of_line");; | ||
"chore") chores+=("- $rest_of_line");; | ||
*) others+=("- $rest_of_line");; | ||
esac | ||
done <<< "$commit_log" | ||
|
||
[[ ${#features[@]} -gt 0 ]] && changelog_content+="\n## Features\n$(printf "%s\n" "${features[@]}")" | ||
[[ ${#fixes[@]} -gt 0 ]] && changelog_content+="\n## Fixes\n$(printf "%s\n" "${fixes[@]}")" | ||
[[ ${#docs[@]} -gt 0 ]] && changelog_content+="\n## Documentation\n$(printf "%s\n" "${docs[@]}")" | ||
[[ ${#styles[@]} -gt 0 ]] && changelog_content+="\n## Style\n$(printf "%s\n" "${styles[@]}")" | ||
[[ ${#refactors[@]} -gt 0 ]] && changelog_content+="\n## Refactor\n$(printf "%s\n" "${refactors[@]}")" | ||
[[ ${#tests[@]} -gt 0 ]] && changelog_content+="\n## Tests\n$(printf "%s\n" "${tests[@]}")" | ||
[[ ${#chores[@]} -gt 0 ]] && changelog_content+="\n## Chores\n$(printf "%s\n" "${chores[@]}")" | ||
[[ ${#others[@]} -gt 0 ]] && changelog_content+="\n## Others\n$(printf "%s\n" "${others[@]}")" | ||
|
||
# Append or overwrite the changelog file based on the append variable | ||
if [ "$append" = "true" ]; then | ||
echo -e "$changelog_content" >> "CHANGELOG.md" | ||
else | ||
echo -e "$changelog_content" > "CHANGELOG.md" | ||
fi |
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,18 +1,19 @@ | ||
BRANCH=test | ||
dev | ||
MAJOR=2 | ||
MINOR=0 | ||
MINOR=1 | ||
PATCH=0 | ||
TYPE=alpha | ||
TYPE_VERSION=1 | ||
|
||
BRANCH=stage | ||
test | ||
MAJOR=2 | ||
MINOR=0 | ||
MINOR=1 | ||
PATCH=0 | ||
TYPE=rc | ||
TYPE_VERSION=1 | ||
|
||
BRANCH=main | ||
stage | ||
MAJOR=2 | ||
MINOR=0 | ||
MINOR=1 | ||
PATCH=0 | ||
|
||
main | ||
MAJOR=2 | ||
MINOR=1 | ||
PATCH=0 |
Oops, something went wrong.