Skip to content

Sync to Codeberg

Sync to Codeberg #6

Workflow file for this run

name: Sync to Codeberg
on:
workflow_dispatch:
inputs:
version:
description: 'Version Tag (e.g. v1.1.0)'
required: true
jobs:
mirror-and-release:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Mirror to Codeberg (Exclude .github)
run: |
git config --global user.name "GitHub Action"
git config --global user.email "[email protected]"
git remote add codeberg "https://M-Rajabi-Dev:${{ secrets.CODEBERG_TOKEN }}@codeberg.org/M-Rajabi-Dev/AudioShelf.git"
git checkout -b codeberg-clean
git rm -rf .github
git commit -m "Sync to Codeberg (Removed .github)"
git tag -f ${{ inputs.version }}
git push -f codeberg codeberg-clean:main
git push -f codeberg ${{ inputs.version }}
- name: Download Assets from GitHub
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release download ${{ inputs.version }} -p "*Setup.exe" -p "*Portable.zip" --dir ./assets
- name: Get or Create Release ID
env:
CB_TOKEN: ${{ secrets.CODEBERG_TOKEN }}
VERSION: ${{ inputs.version }}
REPO: 'M-Rajabi-Dev/AudioShelf'
run: |
echo "Processing Release for $VERSION..."
CREATE_RESP=$(curl -s -X POST "https://codeberg.org/api/v1/repos/$REPO/releases" \
-H "Authorization: token $CB_TOKEN" \
-H "Content-Type: application/json" \
-d "{ \"tag_name\": \"$VERSION\", \"name\": \"AudioShelf $VERSION\", \"body\": \"Mirrored from GitHub\" }")
REL_ID=$(echo "$CREATE_RESP" | jq -r .id)
if [ "$REL_ID" == "null" ]; then
echo "Release likely exists. Fetching existing ID..."
GET_RESP=$(curl -s -X GET "https://codeberg.org/api/v1/repos/$REPO/releases/tags/$VERSION" \
-H "Authorization: token $CB_TOKEN")
REL_ID=$(echo "$GET_RESP" | jq -r .id)
fi
if [ "$REL_ID" == "null" ] || [ -z "$REL_ID" ]; then
echo "CRITICAL ERROR: Could not get Release ID."
echo "API Response: $CREATE_RESP"
exit 1
fi
echo "FOUND RELEASE ID: $REL_ID"
echo "RELEASE_ID=$REL_ID" >> $GITHUB_ENV
- name: Upload Assets to Codeberg
env:
CB_TOKEN: ${{ secrets.CODEBERG_TOKEN }}
REPO: 'M-Rajabi-Dev/AudioShelf'
run: |
cd assets
for file in *; do
echo "Uploading $file..."
EXISTING_ASSET_ID=$(curl -s "https://codeberg.org/api/v1/repos/$REPO/releases/${{ env.RELEASE_ID }}/assets" | jq -r ".[] | select(.name==\"$file\") | .id")
if [ ! -z "$EXISTING_ASSET_ID" ]; then
echo "Deleting old asset $file..."
curl -X DELETE "https://codeberg.org/api/v1/repos/$REPO/releases/${{ env.RELEASE_ID }}/assets/$EXISTING_ASSET_ID" \
-H "Authorization: token $CB_TOKEN"
fi
curl -f -X POST "https://codeberg.org/api/v1/repos/$REPO/releases/${{ env.RELEASE_ID }}/assets?name=$file" \
-H "accept: application/json" \
-H "Authorization: token $CB_TOKEN" \
-H "Content-Type: multipart/form-data" \
-F "attachment=@$file"
done