Skip to content

Commit 417c8e9

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

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-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: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Test Fake Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
fake_version:
7+
description: 'Fake Version Name (e.g. v-test-01)'
8+
required: true
9+
default: 'v-test-01'
10+
11+
jobs:
12+
test-fake-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 "Test File 1" > assets/Fake-Setup.exe
22+
echo "Test File 2" > assets/Fake-Portable.zip
23+
24+
- name: Push Tag to Codeberg
25+
run: |
26+
git config --global user.name "Test Bot"
27+
git config --global user.email "[email protected]"
28+
git remote add codeberg "https://M-Rajabi-Dev:${{ secrets.CODEBERG_TOKEN }}@codeberg.org/M-Rajabi-Dev/AudioShelf.git"
29+
30+
# ساخت تگ و ارسال
31+
git tag -f ${{ inputs.fake_version }}
32+
git push -f codeberg ${{ inputs.fake_version }}
33+
34+
- name: Create Release & Upload (Pure Curl)
35+
env:
36+
CB_TOKEN: ${{ secrets.CODEBERG_TOKEN }}
37+
REPO: 'M-Rajabi-Dev/AudioShelf'
38+
TAG: ${{ inputs.fake_version }}
39+
run: |
40+
API_URL="https://codeberg.org/api/v1/repos/$REPO/releases"
41+
42+
# 1. پیدا کردن ID ریلیز قدیمی (اگه باشه) و حذفش
43+
OLD_ID=$(curl -s "$API_URL" | jq -r ".[] | select(.tag_name==\"$TAG\") | .id")
44+
if [ ! -z "$OLD_ID" ] && [ "$OLD_ID" != "null" ]; then
45+
echo "Deleting old release ID: $OLD_ID"
46+
curl -X DELETE "$API_URL/$OLD_ID" -H "Authorization: token $CB_TOKEN"
47+
fi
48+
49+
# 2. ساخت ریلیز جدید
50+
echo "Creating new release..."
51+
RESPONSE=$(curl -s -X POST "$API_URL" \
52+
-H "Authorization: token $CB_TOKEN" \
53+
-H "Content-Type: application/json" \
54+
-d "{ \"tag_name\": \"$TAG\", \"name\": \"TEST RELEASE $TAG\", \"body\": \"Test upload via Curl\" }")
55+
56+
NEW_ID=$(echo $RESPONSE | jq -r .id)
57+
echo "Created Release ID: $NEW_ID"
58+
59+
# 3. آپلود فایل‌ها
60+
cd assets
61+
for file in *; do
62+
echo "Uploading $file..."
63+
curl -f -X POST "$API_URL/$NEW_ID/assets?name=$file" \
64+
-H "Authorization: token $CB_TOKEN" \
65+
-H "Content-Type: multipart/form-data" \
66+
-F "attachment=@$file"
67+
done

0 commit comments

Comments
 (0)