Merge pull request 'chore: Update workflows' (#18) from dev into master

Reviewed-on: #18
This commit is contained in:
fanantenana 2025-02-06 11:18:28 +00:00
commit c48fdc6acd

View File

@ -26,20 +26,40 @@ jobs:
id: get_commits
run: |
COMMITS=$(git log HEAD^..HEAD --oneline --no-merges)
echo "COMMITS=$COMMITS" >> "$GITEA_ENV"
- name: Extract current version from pubspec.yaml
if [ -z "$COMMITS" ]; then
echo "No commits found in the merged PR."
exit 0
fi
echo "Commits from merged PR:"
echo "$COMMITS"
echo "COMMITS<<EOF" >> "$GITHUB_ENV"
echo "$COMMITS" >> "$GITHUB_ENV"
echo "EOF" >> "$GITHUB_ENV"
- name: Extract current version
id: versioning
run: |
CURRENT_VERSION=$(grep 'version:' pubspec.yaml | awk -F ': ' '{print $2}')
PUBSPEC_FILE="pubspec.yaml"
if [ ! -f "$PUBSPEC_FILE" ]; then
echo "Error: $PUBSPEC_FILE not found."
exit 1
fi
CURRENT_VERSION=$(grep 'version:' $PUBSPEC_FILE | awk -F ': ' '{print $2}')
VERSION=$(echo "$CURRENT_VERSION" | cut -d'+' -f1)
BUILD=$(echo "$CURRENT_VERSION" | cut -d'+' -f2)
echo "CURRENT_VERSION=$CURRENT_VERSION" >> "$GITEA_ENV"
echo "VERSION=$VERSION" >> "$GITEA_ENV"
echo "BUILD=$BUILD" >> "$GITEA_ENV"
echo "Current version: $VERSION+$BUILD"
- name: Determine increment type
echo "CURRENT_VERSION=$CURRENT_VERSION" >> "$GITHUB_ENV"
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
echo "BUILD=$BUILD" >> "$GITHUB_ENV"
- name: Determine increment type from commits
id: increment_type
run: |
COMMITS="${{ env.COMMITS }}"
@ -51,62 +71,118 @@ jobs:
INCREMENT_TYPE="minor"
elif echo "$COMMITS" | grep -iq "fix:"; then
INCREMENT_TYPE="patch"
fi # Fermeture correcte du if
echo "INCREMENT_TYPE=$INCREMENT_TYPE" >> "$GITEA_ENV"
elif echo "$COMMITS" | grep -iq "refactor:"; then
INCREMENT_TYPE="patch"
elif echo "$COMMITS" | grep -iq "style:"; then
INCREMENT_TYPE="patch"
elif echo "$COMMITS" | grep -iq "chore:"; then
INCREMENT_TYPE="patch"
else
INCREMENT_TYPE="patch"
fi
- name: Increment version in pubspec.yaml
echo "INCREMENT_TYPE=$INCREMENT_TYPE" >> "$GITHUB_ENV"
- name: Increment version and update pubspec.yaml
id: increment_version
run: |
increment_version() {
local version=$1
local index=$2
IFS='.' read -r -a parts <<< "$version"
if [[ ${#parts[@]} -le $index ]]; then
echo "Error: Invalid version format or index."
exit 1
fi
parts[$index]=$((parts[$index] + 1))
for ((i = index + 1; i < ${#parts[@]}; i++)); do parts[$i]=0; done
for ((i = index + 1; i < ${#parts[@]}; i++)); do
parts[$i]=0
done
echo "${parts[*]}" | tr ' ' '.'
}
CURRENT_VERSION="${{ env.CURRENT_VERSION }}"
VERSION="${{ env.VERSION }}"
BUILD="${{ env.BUILD }}"
INCREMENT_TYPE="${{ env.INCREMENT_TYPE }}"
NEW_BUILD=$((BUILD + 1))
echo "Incrementing version using type: $INCREMENT_TYPE"
echo "Old Version: $CURRENT_VERSION"
case $INCREMENT_TYPE in
major) NEW_VERSION=$(increment_version "$VERSION" 0) ;;
minor) NEW_VERSION=$(increment_version "$VERSION" 1) ;;
patch) NEW_VERSION=$(increment_version "$VERSION" 2) ;;
major)
NEW_VERSION=$(increment_version "$VERSION" 0)
;;
minor)
NEW_VERSION=$(increment_version "$VERSION" 1)
;;
patch)
NEW_VERSION=$(increment_version "$VERSION" 2)
;;
*)
echo "Error: Unknown increment type: $INCREMENT_TYPE"
exit 1
;;
esac
sed -i "s/^version: .*/version: $NEW_VERSION+$NEW_BUILD/" pubspec.yaml
sed -i.bak "s/^version: .*/version: $NEW_VERSION+$NEW_BUILD/" pubspec.yaml
echo "NEW_VERSION=$NEW_VERSION" >> "$GITEA_ENV"
echo "NEW_BUILD=$NEW_BUILD" >> "$GITEA_ENV"
echo "NEW_VERSION=$NEW_VERSION" >> "$GITHUB_ENV"
echo "NEW_BUILD=$NEW_BUILD" >> "$GITHUB_ENV"
echo "New Version: $NEW_VERSION+$NEW_BUILD"
- name: Generate Changelog
- name: Generate Changelog for merged PR
run: |
CHANGELOG_FILE="CHANGELOG.md"
DATE=$(date +"%Y-%m-%d")
COMMITS="${{ env.COMMITS }}"
NEW_VERSION="${{ env.NEW_VERSION }}"
NEW_BUILD="${{ env.NEW_BUILD }}"
CHANGELOG_FILE="CHANGELOG.md"
[ ! -f "$CHANGELOG_FILE" ] && echo "# Changelog" > "$CHANGELOG_FILE"
if [ ! -f "$CHANGELOG_FILE" ]; then
touch "$CHANGELOG_FILE"
echo "# Changelog" > "$CHANGELOG_FILE"
fi
TEMP_CHANGELOG="CHANGELOG_TEMP.md"
{
echo "## $NEW_VERSION+$NEW_BUILD ($DATE)"
echo ""
echo "### Features"
echo "$COMMITS" | grep "feat:" || echo "No new features"
echo ""
echo "### Bug Fixes"
echo "$COMMITS" | grep "fix:" || echo "No bug fixes"
echo ""
cat "$CHANGELOG_FILE"
echo "## $NEW_VERSION+$NEW_BUILD ($DATE)"
echo ""
echo "### Breaking Changes"
BREAKING=$(echo "$COMMITS" | grep "breaking:" | sed -E 's/^([a-f0-9]+) breaking: /- (#\1) /g')
echo "${BREAKING:-No breaking changes found.}"
echo ""
echo "### Features"
FEATURES=$(echo "$COMMITS" | grep "feat:" | sed -E 's/^([a-f0-9]+) feat: /- (#\1) /g')
echo "${FEATURES:-No features found.}"
echo ""
echo "### Bug Fixes"
BUG_FIXES=$(echo "$COMMITS" | grep "fix:" | sed -E 's/^([a-f0-9]+) fix: /- (#\1) /g')
echo "${BUG_FIXES:-No bug fixes found.}"
echo ""
echo "### Refactors"
REFACTOR=$(echo "$COMMITS" | grep "refactor:" | sed -E 's/^([a-f0-9]+) refactor: /- (#\1) /g')
echo "${REFACTOR:-No refactors found.}"
echo ""
echo "### Style Changes"
STYLE=$(echo "$COMMITS" | grep "style:" | sed -E 's/^([a-f0-9]+) style: /- (#\1) /g')
echo "${STYLE:-No style changes found.}"
echo ""
echo "### Chores"
CHORES=$(echo "$COMMITS" | grep "chore:" | sed -E 's/^([a-f0-9]+) chore: /- (#\1) /g')
echo "${CHORES:-No chores found.}"
echo ""
echo "### Miscellaneous"
MISC=$(echo "$COMMITS" | grep -v -E "breaking:|feat:|fix:|refactor:|style:|chore:" | sed -E 's/^([a-f0-9]+) /- (#\1) /g')
echo "${MISC:-No miscellaneous changes found.}"
echo ""
cat "$CHANGELOG_FILE"
} > "$TEMP_CHANGELOG"
mv "$TEMP_CHANGELOG" "$CHANGELOG_FILE"
echo "Changelog updated."
- name: Set remote URL
run: |
@ -120,7 +196,7 @@ jobs:
git config --global user.name "Gitea Actions"
git add pubspec.yaml CHANGELOG.md
git commit -m "chore: bump version to $NEW_VERSION+$NEW_BUILD and update changelog" || echo "No changes to commit"
git commit -m "chore: increment version $NEW_VERSION+$NEW_BUILD and update changelog"
echo "🔗 Pushing changes..."
# Ici, on pousse la branche courante (HEAD) vers la branche master sur l'origine