Skip to content

Commit 984f340

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

File tree

2 files changed

+114
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)