Mandresy Randrianarinjaka a8860b7cb9
Some checks failed
versioning-and-changelog / versioning_and_changelog (pull_request) Failing after 14s
chore: Update workflows
2025-02-06 14:17:29 +03:00

204 lines
7.0 KiB
YAML

name: versioning-and-changelog
on:
pull_request:
types:
- closed # Gitea utilise 'merged' et non 'closed'
branches:
- master
jobs:
versioning_and_changelog:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
channel: stable
flutter-version-file: pubspec.yaml
- name: Find commits from merged pull request
id: get_commits
run: |
COMMITS=$(git log HEAD^..HEAD --oneline --no-merges)
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: |
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: $VERSION+$BUILD"
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 }}"
INCREMENT_TYPE="patch"
if echo "$COMMITS" | grep -iq "breaking:"; then
INCREMENT_TYPE="major"
elif echo "$COMMITS" | grep -iq "feat:"; then
INCREMENT_TYPE="minor"
elif echo "$COMMITS" | grep -iq "fix:"; then
INCREMENT_TYPE="patch"
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
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
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)
;;
*)
echo "Error: Unknown increment type: $INCREMENT_TYPE"
exit 1
;;
esac
sed -i.bak "s/^version: .*/version: $NEW_VERSION+$NEW_BUILD/" pubspec.yaml
echo "NEW_VERSION=$NEW_VERSION" >> "$GITHUB_ENV"
echo "NEW_BUILD=$NEW_BUILD" >> "$GITHUB_ENV"
echo "New Version: $NEW_VERSION+$NEW_BUILD"
- 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 }}"
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 "### 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: |
# Remplacer (ou mettre à jour) l'origin avec l'URL incluant le token
git remote set-url origin https://${{ secrets.GITEAACCESSTOKEN }}@${{ secrets.GITEAURL#https:// }}/mobiles/flutter-mobile.git
git remote -v
- name: Commit and Push Changes
run: |
git config --global user.email "gitea-actions@bot.com"
git config --global user.name "Gitea Actions"
git add pubspec.yaml CHANGELOG.md
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
git push origin HEAD:master