Sync to Codeberg #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 (Manual Git Push) | |
| run: | | |
| git remote add codeberg "https://M-Rajabi-Dev:${{ secrets.CODEBERG_TOKEN }}@codeberg.org/M-Rajabi-Dev/AudioShelf.git" | |
| git push -f codeberg main | |
| git push -f codeberg --tags | |
| - 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: Create Release on Codeberg | |
| env: | |
| CB_TOKEN: ${{ secrets.CODEBERG_TOKEN }} | |
| VERSION: ${{ inputs.version }} | |
| REPO: 'M-Rajabi-Dev/AudioShelf' | |
| run: | | |
| EXISTING_ID=$(curl -s "https://codeberg.org/api/v1/repos/$REPO/releases" | jq -r ".[] | select(.tag_name==\"$VERSION\") | .id") | |
| if [ ! -z "$EXISTING_ID" ]; then | |
| curl -X DELETE "https://codeberg.org/api/v1/repos/$REPO/releases/$EXISTING_ID" \ | |
| -H "Authorization: token $CB_TOKEN" | |
| fi | |
| RESPONSE=$(curl -X POST "https://codeberg.org/api/v1/repos/$REPO/releases" \ | |
| -H "accept: application/json" \ | |
| -H "Authorization: token $CB_TOKEN" \ | |
| -H "Content-Type: application/json" \ | |
| -d "{ \"tag_name\": \"$VERSION\", \"name\": \"AudioShelf $VERSION\", \"body\": \"Mirrored from GitHub\" }") | |
| echo "RELEASE_ID=$(echo $RESPONSE | jq -r .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 | |
| curl -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 |