1+ name : Sync to Codeberg
2+
3+ on :
4+ workflow_dispatch :
5+ inputs :
6+ version :
7+ description : ' Version Tag (e.g. v1.1.0)'
8+ required : true
9+
10+ jobs :
11+ mirror-and-release :
12+ runs-on : ubuntu-latest
13+ steps :
14+ - name : Checkout Code
15+ uses : actions/checkout@v3
16+ with :
17+ fetch-depth : 0
18+
19+ - name : Mirror to Codeberg (Exclude .github)
20+ run : |
21+ git config --global user.name "GitHub Action"
22+ git config --global user.email "[email protected] " 23+
24+ git remote add codeberg "https://M-Rajabi-Dev:${{ secrets.CODEBERG_TOKEN }}@codeberg.org/M-Rajabi-Dev/AudioShelf.git"
25+
26+ git checkout -b codeberg-clean
27+ git rm -rf .github
28+ git commit -m "Sync to Codeberg (Removed .github)"
29+
30+ git tag -f ${{ inputs.version }}
31+
32+ git push -f codeberg codeberg-clean:main
33+ git push -f codeberg ${{ inputs.version }}
34+
35+ - name : Download Assets from GitHub
36+ env :
37+ GH_TOKEN : ${{ github.token }}
38+ run : |
39+ gh release download ${{ inputs.version }} -p "*Setup.exe" -p "*Portable.zip" --dir ./assets
40+
41+ - name : Get or Create Release ID
42+ env :
43+ CB_TOKEN : ${{ secrets.CODEBERG_TOKEN }}
44+ VERSION : ${{ inputs.version }}
45+ REPO : ' M-Rajabi-Dev/AudioShelf'
46+ run : |
47+ echo "Processing Release for $VERSION..."
48+
49+ CREATE_RESP=$(curl -s -X POST "https://codeberg.org/api/v1/repos/$REPO/releases" \
50+ -H "Authorization: token $CB_TOKEN" \
51+ -H "Content-Type: application/json" \
52+ -d "{ \"tag_name\": \"$VERSION\", \"name\": \"AudioShelf $VERSION\", \"body\": \"Mirrored from GitHub\" }")
53+
54+ REL_ID=$(echo "$CREATE_RESP" | jq -r .id)
55+
56+ if [ "$REL_ID" == "null" ]; then
57+ echo "Release likely exists. Fetching existing ID..."
58+ GET_RESP=$(curl -s -X GET "https://codeberg.org/api/v1/repos/$REPO/releases/tags/$VERSION" \
59+ -H "Authorization: token $CB_TOKEN")
60+ REL_ID=$(echo "$GET_RESP" | jq -r .id)
61+ fi
62+
63+ if [ "$REL_ID" == "null" ] || [ -z "$REL_ID" ]; then
64+ echo "CRITICAL ERROR: Could not get Release ID."
65+ echo "API Response: $CREATE_RESP"
66+ exit 1
67+ fi
68+
69+ echo "FOUND RELEASE ID: $REL_ID"
70+ echo "RELEASE_ID=$REL_ID" >> $GITHUB_ENV
71+
72+ - name : Upload Assets to Codeberg
73+ env :
74+ CB_TOKEN : ${{ secrets.CODEBERG_TOKEN }}
75+ REPO : ' M-Rajabi-Dev/AudioShelf'
76+ run : |
77+ cd assets
78+ for file in *; do
79+ echo "Uploading $file..."
80+
81+ EXISTING_ASSET_ID=$(curl -s "https://codeberg.org/api/v1/repos/$REPO/releases/${{ env.RELEASE_ID }}/assets" | jq -r ".[] | select(.name==\"$file\") | .id")
82+
83+ if [ ! -z "$EXISTING_ASSET_ID" ]; then
84+ echo "Deleting old asset $file..."
85+ curl -X DELETE "https://codeberg.org/api/v1/repos/$REPO/releases/${{ env.RELEASE_ID }}/assets/$EXISTING_ASSET_ID" \
86+ -H "Authorization: token $CB_TOKEN"
87+ fi
88+
89+ curl -f -X POST "https://codeberg.org/api/v1/repos/$REPO/releases/${{ env.RELEASE_ID }}/assets?name=$file" \
90+ -H "accept: application/json" \
91+ -H "Authorization: token $CB_TOKEN" \
92+ -H "Content-Type: multipart/form-data" \
93+ -F "attachment=@$file"
94+ done
0 commit comments