.github/workflows/ci-cd.yml

144 lines · 4638 bytes

  1name: CI/CD Pipeline
  2
  3on:
  4  push:
  5    branches:
  6      - main  # Trigger on pushes to the main branch
  7  pull_request:
  8    branches:
  9      - main  # Trigger on pull requests targeting the main branch
 10
 11jobs:
 12  build:
 13    runs-on: ubuntu-latest
 14
 15    steps:
 16      - name: Checkout code
 17        uses: actions/checkout@v2
 18
 19      - name: Set up Go
 20        uses: actions/setup-go@v2
 21        with:
 22          go-version: '1.23.2'
 23
 24      - name: Install Dependencies
 25        run: go mod tidy
 26
 27      - name: Build Linux binary
 28        run: |
 29          ./Build/buildlinux
 30
 31      - name: Build macOS Intel binary
 32        run: |
 33          ./Build/buildmac
 34
 35      - name: Build macOS ARM64 binary
 36        run: |
 37          ./Build/buildmac-arm64
 38
 39      - name: Create Universal macOS binary
 40        run: |
 41          mkdir -p Build/macos
 42          mv curd Build/macos/curd-amd64
 43          mv curd-arm64 Build/macos/curd-arm64
 44          lipo -create Build/macos/curd-amd64 Build/macos/curd-arm64 -output Build/macos/curd
 45          rm Build/macos/curd-amd64 Build/macos/curd-arm64
 46
 47      - name: Revert Changes in player.go
 48        run: |
 49          git checkout -- internal/player.go
 50
 51      - name: Build Windows binary (cross-compile)
 52        run: |
 53          ./Build/buildwindows
 54
 55      - name: Upload Artifacts
 56        uses: actions/upload-artifact@v4
 57        with:
 58          name: curd-binaries
 59          path: |
 60            Build/curd
 61            Build/curd.exe
 62            Build/macos/curd
 63          retention-days: 1
 64          if-no-files-found: error
 65
 66      - name: List Build Directory
 67        run: |
 68          echo "Listing contents of Build directory:"
 69          ls -R Build
 70
 71  release:
 72    runs-on: windows-latest  # Use Windows runner for creating the installer
 73    needs: build  # Ensure the build job is complete before running this job
 74    if: github.ref == 'refs/heads/main' && github.event_name == 'push'  # Only run on pushes to main
 75
 76    steps:
 77      - name: Checkout code
 78        uses: actions/checkout@v2
 79        with:
 80          lfs: true
 81
 82      - name: Download and extract MPV binary
 83        run: |
 84          # Create directory if it doesn't exist
 85          New-Item -ItemType Directory -Force -Path "Build\mpv"
 86          # Download the compressed MPV binary
 87          Invoke-WebRequest -Uri "https://raw.githubusercontent.com/${{ github.repository }}/main/Build/mpv.exe.gz" -OutFile "Build\mpv\mpv.exe.gz"
 88          # Extract using 7-Zip (built into Windows runners)
 89          7z x "Build\mpv\mpv.exe.gz" -o"Build\mpv"
 90          Remove-Item "Build\mpv\mpv.exe.gz"
 91        shell: pwsh
 92
 93      - name: Download Artifacts
 94        uses: actions/download-artifact@v4
 95        with:
 96          name: curd-binaries
 97          path: Build
 98          repository: ${{ github.repository }}  # Explicitly set repository
 99          github-token: ${{ secrets.GITHUB_TOKEN }}  # Add token for authentication
100
101      - name: Bump Version
102        id: bump_version
103        run: |
104          $current_version = Get-Content VERSION.txt
105          $version_parts = $current_version -split '\.'
106          $major = $version_parts[0]
107          $minor = $version_parts[1]
108          $patch = [int]$version_parts[2] + 1
109          $new_version = "$major.$minor.$patch"
110          $new_version | Set-Content VERSION.txt
111          git config user.name "GitHub Actions"
112          git config user.email "actions@github.com"
113          git add VERSION.txt
114          git commit -m "Bump version to $new_version"
115          git tag "v$new_version"
116          echo "::set-output name=new_version::$new_version"
117
118      - name: Update Inno Setup Script with New Version
119        run: |
120          $new_version = Get-Content VERSION.txt
121          $iss_path = "Build/curd-windows-build.iss"
122          (Get-Content $iss_path) -replace "AppVersion=.*", "AppVersion=$new_version" | Set-Content $iss_path
123  
124      - name: Create Windows Installer
125        run: |
126          & "C:\Program Files (x86)\Inno Setup 6\ISCC.exe" "Build\curd-windows-build.iss"  
127        shell: pwsh
128
129      - name: Create Release
130        id: create_release
131        uses: softprops/action-gh-release@v1
132        with:
133          tag_name: "v${{ steps.bump_version.outputs.new_version }}"  # Use the bumped version as tag
134          name: "Curd v${{ steps.bump_version.outputs.new_version }}"  # Use new version in release name
135          draft: false
136          prerelease: false
137          generate_release_notes: true 
138          files: |
139            Build/curd
140            Build/curd.exe
141            Build/macos/curd
142            Build/Output/CurdInstaller.exe
143        env:
144          GITHUB_TOKEN: ${{ secrets.ACTIONS_PAT }}