11name : Creează lansare de tip draft
22
33on :
4- workflow_dispatch : # Permite rularea manuală a workflow-ului cu parametri
4+ workflow_dispatch :
55 inputs :
66 increment_type :
77 description : " Tipul de incrementare al versiunii (major/minor/patch)"
88 required : true
9- default : " patch" # Implicit se incrementează PATCH
9+ default : " patch"
1010 type : choice
1111 options :
1212 - major
@@ -15,111 +15,178 @@ on:
1515
1616jobs :
1717 release :
18- name : Creează Lansare de tip draft
19- runs-on : ubuntu-22.04 # Ubuntu 22.04 este stabil și suportă Python 3.10
18+ name : Creează lansare de tip draft
19+ runs-on : ubuntu-22.04
2020
2121 steps :
2222 # 1. Checkout repository
2323 - name : Checkout repository
2424 uses : actions/checkout@v4
25+ with :
26+ fetch-depth : 0
2527
26- # 2. Set up Python (versiune compatibilă)
28+ # 2. Set up Python
2729 - name : Set up Python
2830 uses : actions/setup-python@v5
2931 with :
30- python-version : ' 3.10' # Versiune stabilă și compatibilă
32+ python-version : " 3.10"
3133
3234 # 3. Update manifest.json version
3335 - name : Update manifest.json version
3436 id : update_manifest
3537 run : |
36- # Verifică dacă jq este instalat
3738 if ! command -v jq &> /dev/null; then
3839 echo "Installing jq..."
3940 sudo apt-get update && sudo apt-get install -y jq
4041 fi
4142
42- # Definim calea către manifest.json
4343 MANIFEST_PATH="custom_components/erovinieta/manifest.json"
4444
45- # Verificăm dacă fișierul există
4645 if [ ! -f "$MANIFEST_PATH" ]; then
4746 echo "Error: manifest.json not found at $MANIFEST_PATH"
4847 exit 1
4948 fi
5049
51- # Citește versiunea actuală
5250 VERSION=$(jq -r '.version' "$MANIFEST_PATH")
5351 echo "Current version: $VERSION"
54-
55- # Sparge versiunea în MAJOR, MINOR și PATCH
52+
5653 IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
5754
58- # Verificăm tipul de incrementare
5955 INCREMENT_TYPE="${{ github.event.inputs.increment_type }}"
6056 echo "Increment type: $INCREMENT_TYPE"
6157
6258 if [ "$INCREMENT_TYPE" = "major" ]; then
63- MAJOR=$((MAJOR + 1))
64- MINOR=0
65- PATCH=0
59+ MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0
6660 elif [ "$INCREMENT_TYPE" = "minor" ]; then
67- MINOR=$((MINOR + 1))
68- PATCH=0
61+ MINOR=$((MINOR + 1)); PATCH=0
6962 elif [ "$INCREMENT_TYPE" = "patch" ]; then
7063 PATCH=$((PATCH + 1))
7164 else
72- echo "Invalid increment type: $INCREMENT_TYPE. Use 'major', 'minor', or 'patch'. "
65+ echo "Invalid increment type: $INCREMENT_TYPE"
7366 exit 1
7467 fi
7568
76- # Creează noua versiune
7769 NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
7870 echo "New version: $NEW_VERSION"
79-
80- # Actualizează manifest.json
81- jq --arg version "$NEW_VERSION" '.version = $version' "$MANIFEST_PATH" > manifest.tmp && mv manifest.tmp "$MANIFEST_PATH"
82-
83- # Setează noua versiune ca variabilă de mediu
71+ echo "OLD_VERSION=$VERSION" >> $GITHUB_ENV
8472 echo "new_version=$NEW_VERSION" >> $GITHUB_ENV
8573
86- # 4. Commit și push modificările folosind PAT
74+ jq --arg version "$NEW_VERSION" '.version = $version' "$MANIFEST_PATH" > manifest.tmp && mv manifest.tmp "$MANIFEST_PATH"
75+
76+ # 4. Generează body-ul release-ului cu statistici
77+ - name : Generează release body
78+ run : |
79+ python3 << 'PYSCRIPT'
80+ import json
81+ import subprocess
82+ from pathlib import Path
83+
84+ new_version = "${{ env.new_version }}"
85+ old_version = "${{ env.OLD_VERSION }}"
86+
87+ # ── Statistici din stats.json ──
88+ stats_file = Path(".github/analytics/stats.json")
89+ stars, instalari, clone_14z = "—", "—", "—"
90+
91+ if stats_file.exists():
92+ stats = json.loads(stats_file.read_text())
93+ zilnic = stats.get("zilnic", {})
94+
95+ def fmt(n):
96+ if n >= 1_000_000: return f"{n/1_000_000:.1f}M"
97+ if n >= 1_000: return f"{n/1_000:.1f}k"
98+ return str(n)
99+
100+ zile = sorted(zilnic.keys(), reverse=True)
101+ if zile:
102+ stars = zilnic[zile[0]].get("stars", 0)
103+
104+ total_clone = sum(zi.get("clones_total", 0) for zi in zilnic.values())
105+ total_clone_14z = sum(zi.get("clones_unice", 0) for zi in zilnic.values())
106+
107+ instalari = fmt(total_clone)
108+ clone_14z = fmt(total_clone_14z)
109+
110+ # ── Commit-uri de la ultima versiune ──
111+ try:
112+ result = subprocess.run(
113+ ["git", "tag", "-l", old_version],
114+ capture_output=True, text=True
115+ )
116+ if result.stdout.strip():
117+ result = subprocess.run(
118+ ["git", "log", f"{old_version}..HEAD", "--oneline",
119+ "--no-merges", "--pretty=format:- %s"],
120+ capture_output=True, text=True
121+ )
122+ commits = result.stdout.strip()
123+ # Limităm la 20 linii
124+ lines = commits.split("\n")[:20]
125+ commits = "\n".join(lines)
126+ else:
127+ commits = "- Prima lansare sau tag-ul anterior nu a fost găsit"
128+ except Exception:
129+ commits = "- Nu s-au putut extrage commit-urile"
130+
131+ # ── Generează fișierul markdown ──
132+ body = f"""## CNAIR eRovinieta v{new_version}
133+
134+ ### 📋 Modificări
135+
136+ [aici vine textul tău]
137+
138+ ---
139+
140+ ### 📈 Integrarea în cifre
141+
142+ | ⭐ Stars | 📥 Instalări | 🔄 Clone (14z) |
143+ |:--------:|:------------:|:--------------:|
144+ | {stars} | {instalari} | {clone_14z} |
145+
146+ Dacă integrarea **CNAIR eRovinieta** îți este utilă, lasă un ⭐ pe repository — îi ajută și pe alți utilizatori să o descopere.
147+
148+ ---
149+
150+ 💛 Dezvoltarea consumă timp și resurse. Dacă vrei să susții proiectul:
151+ ☕ [Buy Me a Coffee](https://www.buymeacoffee.com/cnecrea) · 💰 [GitHub Sponsors](https://github.com/sponsors/cnecrea)
152+ """
153+
154+ # Curăță indentarea din triple-quote
155+ lines = body.split("\n")
156+ cleaned = "\n".join(line.lstrip() for line in lines)
157+
158+ Path("/tmp/release_body.md").write_text(cleaned)
159+ print(cleaned)
160+ PYSCRIPT
161+
162+ # 5. Commit și push modificările
87163 - name : Commit changes and push
88164 env :
89- PAT : ${{ secrets.PAT_TOKEN }} # Token-ul salvat ca secret
165+ PAT : ${{ secrets.PAT_TOKEN }}
90166 run : |
91- # Configurare GitHub Actions bot
92167 git config user.name "erovinieta-release-bot"
93168 git config user.email "erovinieta-bot@users.noreply.github.com"
94-
95- # Setează URL-ul remote pentru autentificare cu token
96169 git remote set-url origin https://x-access-token:${PAT}@github.com/cnecrea/erovinieta.git
97-
98- # Adaugă și face commit la modificări
170+
99171 git add custom_components/erovinieta/manifest.json
100172 git commit -m "Update version to ${{ env.new_version }}"
101-
102- # Push la modificări
103173 git push origin HEAD
104174
105- # 5 . Creează un fișier .zip doar cu conținutul folderului erovinieta
175+ # 6 . Creează arhiva ZIP
106176 - name : Create ZIP Archive
107177 run : |
108178 mkdir -p dist
109179 cd custom_components/erovinieta
110180 zip -r ../../dist/erovinieta.zip ./*
111181
112- # 6 . Creează un release pe GitHub ca draft
182+ # 7 . Creează release-ul draft cu body generat
113183 - name : Create GitHub Release
114184 uses : softprops/action-gh-release@v1
115185 with :
116- tag_name : " ${{ env.new_version }}" # Creează un tag
117- name : " ${{ env.new_version }}" # Nume pentru release
118- body : |
119- ## Lansare de tip draft
120- - Această lansare a fost generată automat de GitHub Actions.
121- - Verificați conținutul înainte de publicare.
122- files : dist/erovinieta.zip # Include fișierul ZIP în release
123- draft : true # Creează release-ul ca draft
186+ tag_name : " ${{ env.new_version }}"
187+ name : " ${{ env.new_version }}"
188+ body_path : /tmp/release_body.md
189+ files : dist/erovinieta.zip
190+ draft : true
124191 env :
125- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} # Token-ul implicit GitHub
192+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments