
Some checks failed
versioning-and-changelog / versioning_and_changelog (pull_request) Failing after 14s
121 lines
3.9 KiB
YAML
121 lines
3.9 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)
|
|
echo "COMMITS=$COMMITS" >> "$GITEA_ENV"
|
|
|
|
- name: Extract current version from pubspec.yaml
|
|
id: versioning
|
|
run: |
|
|
CURRENT_VERSION=$(grep 'version:' pubspec.yaml | 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"
|
|
|
|
- name: Determine increment type
|
|
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"
|
|
fi # Fermeture correcte du if
|
|
|
|
echo "INCREMENT_TYPE=$INCREMENT_TYPE" >> "$GITEA_ENV"
|
|
|
|
- name: Increment version in pubspec.yaml
|
|
id: increment_version
|
|
run: |
|
|
increment_version() {
|
|
local version=$1
|
|
local index=$2
|
|
IFS='.' read -r -a parts <<< "$version"
|
|
parts[$index]=$((parts[$index] + 1))
|
|
for ((i = index + 1; i < ${#parts[@]}; i++)); do parts[$i]=0; done
|
|
echo "${parts[*]}" | tr ' ' '.'
|
|
}
|
|
|
|
VERSION="${{ env.VERSION }}"
|
|
BUILD="${{ env.BUILD }}"
|
|
INCREMENT_TYPE="${{ env.INCREMENT_TYPE }}"
|
|
NEW_BUILD=$((BUILD + 1))
|
|
|
|
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) ;;
|
|
esac
|
|
|
|
sed -i "s/^version: .*/version: $NEW_VERSION+$NEW_BUILD/" pubspec.yaml
|
|
|
|
echo "NEW_VERSION=$NEW_VERSION" >> "$GITEA_ENV"
|
|
echo "NEW_BUILD=$NEW_BUILD" >> "$GITEA_ENV"
|
|
|
|
- name: Generate Changelog
|
|
run: |
|
|
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"
|
|
|
|
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"
|
|
} > "$TEMP_CHANGELOG"
|
|
|
|
mv "$TEMP_CHANGELOG" "$CHANGELOG_FILE"
|
|
|
|
- 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: bump version to $NEW_VERSION+$NEW_BUILD and update changelog" || echo "No changes to commit"
|
|
|
|
echo "🔗 Pushing to remote repository..."
|
|
git push -u origin master
|