Skip to content

Commit c31faa3

Browse files
committed
Add Sync to Codeberg action
1 parent fd10530 commit c31faa3

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Mirror Release to Codeberg
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
sync-to-codeberg:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout Code
12+
uses: actions/checkout@v3
13+
with:
14+
fetch-depth: 0
15+
16+
- name: Sync Code and Tags
17+
run: |
18+
git remote add codeberg "https://M-Rajabi-Dev:${{ secrets.CODEBERG_TOKEN }}@codeberg.org/M-Rajabi-Dev/AudioShelf.git"
19+
git push -f codeberg main
20+
git push -f codeberg --tags
21+
22+
- name: Download Assets from GitHub
23+
env:
24+
GH_TOKEN: ${{ github.token }}
25+
run: |
26+
mkdir assets
27+
gh release download ${{ github.event.release.tag_name }} -D assets --pattern "*Setup.exe" --pattern "*Portable.zip"
28+
29+
- name: Create Release and Upload to Codeberg
30+
uses: appleboy/gitea-release-action@v1
31+
with:
32+
base_url: https://codeberg.org
33+
owner: M-Rajabi-Dev
34+
repo: AudioShelf
35+
token: ${{ secrets.CODEBERG_TOKEN }}
36+
tag_name: ${{ github.event.release.tag_name }}
37+
name: ${{ github.event.release.name }}
38+
body: ${{ github.event.release.body }}
39+
files: "assets/*"
40+
draft: false
41+
prerelease: ${{ github.event.release.prerelease }}

.github/workflows/test-fake.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Test Fake Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
fake_version:
7+
description: 'Fake Version Name'
8+
required: true
9+
default: 'v-test-final-2'
10+
11+
jobs:
12+
test-fix-upload:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout Code
16+
uses: actions/checkout@v3
17+
with:
18+
fetch-depth: 0 # <--- این همون خطیه که نبود و باعث بدبختی شد!
19+
20+
- name: Create Dummy Assets
21+
run: |
22+
mkdir assets
23+
echo "Final Test File" > assets/Fake-Setup.exe
24+
echo "Final Test Zip" > assets/Fake-Portable.zip
25+
26+
- name: Push Tag to Codeberg (Auth Fix)
27+
run: |
28+
git config --global user.name "GitHub Action"
29+
git config --global user.email "[email protected]"
30+
31+
# احراز هویت با هدر (بدون گیر کردن)
32+
git config --global http.extraheader "AUTHORIZATION: basic $(echo -n "M-Rajabi-Dev:${{ secrets.CODEBERG_TOKEN }}" | base64)"
33+
34+
git remote add codeberg "https://codeberg.org/M-Rajabi-Dev/AudioShelf.git"
35+
36+
# ساخت تگ و ارسال
37+
git tag -f ${{ inputs.fake_version }}
38+
git push -f codeberg ${{ inputs.fake_version }}
39+
40+
- name: Create Release & Upload (Curl)
41+
env:
42+
CB_TOKEN: ${{ secrets.CODEBERG_TOKEN }}
43+
REPO: 'M-Rajabi-Dev/AudioShelf'
44+
TAG: ${{ inputs.fake_version }}
45+
run: |
46+
API_URL="https://codeberg.org/api/v1/repos/$REPO/releases"
47+
48+
# حذف ریلیز تستی قدیمی اگر مونده باشه
49+
OLD_ID=$(curl -s "$API_URL" | jq -r ".[] | select(.tag_name==\"$TAG\") | .id")
50+
if [ ! -z "$OLD_ID" ] && [ "$OLD_ID" != "null" ]; then
51+
curl -X DELETE "$API_URL/$OLD_ID" -H "Authorization: token $CB_TOKEN"
52+
fi
53+
54+
# ساخت ریلیز جدید
55+
RESPONSE=$(curl -s -X POST "$API_URL" \
56+
-H "Authorization: token $CB_TOKEN" \
57+
-H "Content-Type: application/json" \
58+
-d "{ \"tag_name\": \"$TAG\", \"name\": \"FINAL TEST $TAG\", \"body\": \"Test upload via Header Auth\" }")
59+
60+
NEW_ID=$(echo $RESPONSE | jq -r .id)
61+
62+
if [ "$NEW_ID" == "null" ]; then
63+
echo "Error creating release. Response: $RESPONSE"
64+
exit 1
65+
fi
66+
67+
# آپلود فایل‌ها
68+
cd assets
69+
for file in *; do
70+
echo "Uploading $file..."
71+
curl -f -X POST "$API_URL/$NEW_ID/assets?name=$file" \
72+
-H "Authorization: token $CB_TOKEN" \
73+
-H "Content-Type: multipart/form-data" \
74+
-F "attachment=@$file"
75+
done

0 commit comments

Comments
 (0)