Skip to content

Commit

Permalink
fix: workflow (#26)
Browse files Browse the repository at this point in the history
* fix: workflow

* feat: changelog

* fix: Update Notify workflow

* git: Update Notify.yml

* git: Update changelog.yml
  • Loading branch information
Shebyyy authored Dec 3, 2024
1 parent c063159 commit 6992528
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 65 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/Notify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ name: Notify Release
on:
workflow_run:
workflows:
- "Build and Release AnymeX" # Name of the triggering workflow
- "changelog" # Name of the triggering workflow
types:
- completed
workflow_dispatch: # Allow manual triggering of this workflow

jobs:
notify:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
Expand Down
120 changes: 57 additions & 63 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,61 @@ on:
- "v*"
workflow_dispatch:


jobs:
generate-changelog:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate Changelog
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
#!/bin/bash
PREVIOUS_TAG=$(git tag --sort=-v:refname | grep -vE '(-alpha|-beta|-rc)' | head -n 2 | tail -n 1)
CURRENT_TAG=${GITHUB_REF#refs/tags/}
if [ -z "$PREVIOUS_TAG" ]; then
PREVIOUS_TAG=$(git rev-list --max-parents=0 HEAD)
fi
# Initialize changelog with the current tag as the version
echo "## $CURRENT_TAG" >> CHANGELOG.md
echo "" >> CHANGELOG.md
# Function to add section if commits exist
add_section() {
local section_title="$1"
local grep_pattern="$2"
local commits=$(git log $PREVIOUS_TAG..$CURRENT_TAG --grep="$grep_pattern" --pretty=format:'* [`%h`](https://github.com/RyanYuuki/AnymeX/commit/%h): %s')
if [ ! -z "$commits" ]; then
echo "## $section_title" >> CHANGELOG.md
echo "$commits" >> CHANGELOG.md
echo "" >> CHANGELOG.md
fi
}
# Add sections dynamically
add_section "🎉 New Features" "^feat:"
add_section "🛠️ Bug Fixes & Improvements" "^fix:"
add_section "🔧 Refactors" "^refactor:"
add_section "🎨 Style Changes" "^style:"
add_section "🚀 Performance Improvements" "^perf:"
add_section "🧹 Chores & Documentation" "^(chore|docs):"
# Output the generated changelog
cat CHANGELOG.md
# Step 1: Upload Changelog.md as Artifact
- name: Upload Changelog.md as Artifact
id: upload-artifact
uses: actions/upload-artifact@v4
with:
name: Changelog
path: Changelog.md # Path to your Changelog.md

build-android:
runs-on: ubuntu-latest
needs: generate-changelog
steps:
- name: Checkout Code
uses: actions/checkout@v3
Expand All @@ -35,7 +87,6 @@ jobs:
mv build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk build/app/outputs/flutter-apk/AnymeX-Android-armeabi-v7a.apk
mv build/app/outputs/flutter-apk/app-arm64-v8a-release.apk build/app/outputs/flutter-apk/AnymeX-Android-arm64.apk
mv build/app/outputs/flutter-apk/app-x86_64-release.apk build/app/outputs/flutter-apk/AnymeX-Android-x86_64.apk
- name: Build Universal APK
run: flutter build apk --release

Expand All @@ -52,6 +103,7 @@ jobs:

build-ios:
runs-on: macos-latest
needs: generate-changelog
steps:
- name: Checkout Code
uses: actions/checkout@v3
Expand All @@ -74,7 +126,7 @@ jobs:
cd ..
zip -r AnymeX-iOS-${{ github.ref_name }}.ipa Payload
mv AnymeX-iOS-${{ github.ref_name }}.ipa ../../../
- name: Release iOS IPA
uses: ncipollo/release-action@v1
with:
Expand All @@ -85,6 +137,7 @@ jobs:

build-linux:
runs-on: ubuntu-latest
needs: generate-changelog
steps:
- name: Checkout Code
uses: actions/checkout@v3
Expand All @@ -93,7 +146,6 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install -y ninja-build cmake clang mpv libgtk-3-dev libblkid-dev liblzma-dev pkg-config libmpv-dev webkit2gtk-4.1 dpkg-dev
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
Expand All @@ -109,7 +161,6 @@ jobs:
run: |
mv lib/pages/Desktop/video_controls.darts lib/pages/Desktop/video_controls.dart
mv lib/pages/Desktop/watch_page.darts lib/pages/Desktop/watch_page.dart
- name: Replace main.dart with Desktop Version
run: mv lib/main.darts lib/main.dart

Expand All @@ -121,7 +172,6 @@ jobs:
cd build/linux/x64/release
cp ../../../../linuxLibs/* bundle/lib/
zip -r ../../../../AnymeX-Linux.zip .
- name: Release Linux Build
uses: ncipollo/release-action@v1
with:
Expand All @@ -132,6 +182,7 @@ jobs:

build-windows:
runs-on: windows-latest
needs: generate-changelog
steps:
- name: Checkout Code
uses: actions/checkout@v3
Expand All @@ -151,7 +202,6 @@ jobs:
run: |
Move-Item -Path lib\pages\Desktop\video_controls.darts -Destination lib\pages\Desktop\video_controls.dart -Force
Move-Item -Path lib\pages\Desktop\watch_page.darts -Destination lib\pages\Desktop\watch_page.dart -Force
- name: Get Dependencies
run: flutter pub get

Expand All @@ -162,14 +212,12 @@ jobs:
run: |
cd build/windows/x64/runner/Release
Compress-Archive -Path * -DestinationPath AnymeX-Windows.zip
- name: Setup Inno Setup
run: choco install innosetup -y

- name: Build Installer with Inno Setup
run: |
& "C:\Program Files (x86)\Inno Setup 6\ISCC.exe" inno.iss
- name: Release Windows Builds
uses: ncipollo/release-action@v1
with:
Expand All @@ -180,6 +228,7 @@ jobs:

build-macos:
runs-on: macos-latest
needs: generate-changelog
steps:
- name: Checkout Code
uses: actions/checkout@v3
Expand All @@ -200,7 +249,6 @@ jobs:
mv lib/pages/Desktop/video_controls.darts lib/pages/Desktop/video_controls.dart
mv lib/pages/Desktop/watch_page.darts lib/pages/Desktop/watch_page.dart
mv lib/auth/auth_provider_macos.dart lib/auth/auth_provider.dart
- name: Get Dependencies
run: flutter pub get

Expand All @@ -211,64 +259,10 @@ jobs:
run: |
mkdir -p build/macos/Release
hdiutil create -volname "AnymeX" -srcfolder build/macos/Build/Products/Release/AnymeX.app -ov -format UDZO build/macos/Release/AnymeX.dmg
- name: Release macOS Builds
uses: ncipollo/release-action@v1
with:
artifacts: "build/macos/Release/AnymeX.dmg"
token: ${{ secrets.GITHUB_TOKEN }}
allowUpdates: true
tag: ${{ github.ref_name }}

generate-changelog:
runs-on: ubuntu-latest
needs: [build-android, build-ios, build-macos, build-linux, build-windows]
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate Changelog
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
#!/bin/bash
PREVIOUS_TAG=$(git tag --sort=-v:refname | grep -vE '(-alpha|-beta|-rc)' | head -n 2 | tail -n 1)
CURRENT_TAG=${GITHUB_REF#refs/tags/}
if [ -z "$PREVIOUS_TAG" ]; then
PREVIOUS_TAG=$(git rev-list --max-parents=0 HEAD)
fi
# Initialize changelog with the current tag as the version
echo "## $CURRENT_TAG" >> CHANGELOG.md
echo "" >> CHANGELOG.md
# Function to add section if commits exist
add_section() {
local section_title="$1"
local grep_pattern="$2"
local commits=$(git log $PREVIOUS_TAG..$CURRENT_TAG --grep="$grep_pattern" --pretty=format:'* [`%h`](https://github.com/RyanYuuki/AnymeX/commit/%h): %s')
if [ ! -z "$commits" ]; then
echo "## $section_title" >> CHANGELOG.md
echo "$commits" >> CHANGELOG.md
echo "" >> CHANGELOG.md
fi
}
# Add sections dynamically
add_section "🎉 New Features" "^feat:"
add_section "🛠️ Bug Fixes & Improvements" "^fix:"
add_section "🔧 Refactors" "^refactor:"
add_section "🎨 Style Changes" "^style:"
add_section "🚀 Performance Improvements" "^perf:"
add_section "🧹 Chores & Documentation" "^(chore|docs):"
# Output the generated changelog
cat CHANGELOG.md
- name: Update Release with Changelog
uses: ncipollo/release-action@v1
with:
bodyFile: "CHANGELOG.md"
token: ${{ secrets.GITHUB_TOKEN }}
allowUpdates: true
128 changes: 128 additions & 0 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: changelog

on:
workflow_run:
workflows:
- "Build and Release AnymeX" # Name of the triggering workflow
types:
- completed
workflow_dispatch: # Allow manual triggering of this workflow

jobs:
notify:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Get previous tag
id: get_prev_tag
run: |
echo "Getting the previous tag..."
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
echo "Previous tag retrieved: $PREV_TAG"
if [ -z "$PREV_TAG" ]; then
echo "No previous tag found, using the initial commit."
PREV_TAG=$(git rev-list --max-parents=0 HEAD)
fi
echo "prev_tag=$PREV_TAG" >> $GITHUB_ENV
echo "Previous tag: $PREV_TAG"
- name: Get commit messages between tags
id: get_commits
run: |
echo "Getting commit messages between tags..."
COMMITS=$(git log ${{ env.prev_tag }}..HEAD --pretty=format:'%h %s' | tr '\n' '|')
echo "Commits retrieved: $COMMITS"
echo "commits=$COMMITS" >> $GITHUB_ENV
- name: Categorize commits
id: categorize
run: |
echo "Categorizing commits..."
FEATURES=""
BUG_FIXES=""
REFACTORS=""
STYLE_CHANGES=""
PERFORMANCE=""
CHORES=""
REPO_URL="https://github.com/${{ github.repository }}"
IFS='|' read -ra COMMIT_LIST <<< "${{ env.commits }}"
echo "Commit list: ${COMMIT_LIST[@]}"
for LINE in "${COMMIT_LIST[@]}"; do
HASH=$(echo "$LINE" | awk '{print $1}')
MESSAGE=$(echo "$LINE" | cut -d' ' -f2-)
LINK="[$HASH]($REPO_URL/commit/$HASH)"

FORMATTED_COMMIT="* $LINK: $MESSAGE"
echo "Processing commit: $FORMATTED_COMMIT"
if [[ $MESSAGE == feat* ]]; then
FEATURES+="$FORMATTED_COMMIT\n"
elif [[ $MESSAGE == fix* || $MESSAGE == bug* || $MESSAGE == improvement* || $MESSAGE == patch* ]]; then
BUG_FIXES+="$FORMATTED_COMMIT\n"
elif [[ $MESSAGE == refactor* ]]; then
REFACTORS+="$FORMATTED_COMMIT\n"
elif [[ $MESSAGE == style* ]]; then
STYLE_CHANGES+="$FORMATTED_COMMIT\n"
elif [[ $MESSAGE == perf* ]]; then
PERFORMANCE+="$FORMATTED_COMMIT\n"
elif [[ $MESSAGE == chore* || $MESSAGE == docs* || $MESSAGE == build* || $MESSAGE == ci* ]]; then
CHORES+="$FORMATTED_COMMIT\n"
fi
done

if [ -n "$FEATURES" ]; then
echo "### 🎉 New Features" >> CHANGELOG.md
echo -e "$FEATURES" >> CHANGELOG.md
fi
if [ -n "$BUG_FIXES" ]; then
echo "### 🛠️ Bug Fixes & Improvements" >> CHANGELOG.md
echo -e "$BUG_FIXES" >> CHANGELOG.md
fi
if [ -n "$REFACTORS" ]; then
echo "### 🔧 Refactors" >> CHANGELOG.md
echo -e "$REFACTORS" >> CHANGELOG.md
fi
if [ -n "$STYLE_CHANGES" ]; then
echo "### 🎨 Style Changes" >> CHANGELOG.md
echo -e "$STYLE_CHANGES" >> CHANGELOG.md
fi
if [ -n "$PERFORMANCE" ]; then
echo "### 🚀 Performance Improvements" >> CHANGELOG.md
echo -e "$PERFORMANCE" >> CHANGELOG.md
fi
if [ -n "$CHORES" ]; then
echo "### 🧹 Chores & Documentation" >> CHANGELOG.md
echo -e "$CHORES" >> CHANGELOG.md
fi

- name: Commit and push changelog
run: |
echo "Committing and pushing changelog..."
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
git add CHANGELOG.md
git commit -m "Update changelog for version ${{ github.ref_name }}"
git push origin HEAD:main
# Step 2: Get the latest tag
- name: Get latest tag
id: get_tag
run: |
# Fetch all tags
git fetch --tags
# Get the latest tag
TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
echo "latest_tag=$TAG" >> $GITHUB_ENV
# Step 4: Run release action with the latest tag
- name: Create or Update Release
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
bodyFile: CHANGELOG.md
tag: ${{ env.latest_tag }} # Use the latest tag
allowUpdates: true

0 comments on commit 6992528

Please sign in to comment.