.github/workflows/ci-cd.yml

142 lines · 4785 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: Comment go-winio for Linux Build
 28        run: |
 29          echo 'function toggle_winio_import() {
 30              local action="$1"
 31              local file="internal/player.go"
 32              
 33              if [ "$action" == "comment" ]; then
 34                  sed -i "s|^\\(\\s*\\\"github.com/Microsoft/go-winio\\\"\\)|// \\1|" "$file"
 35                  sed -i "s|^\\(.*conn, err = winio.DialPipe.*\\)|// \\1|" "$file"
 36              elif [ "$action" == "uncomment" ]; then
 37                  sed -i "s|// \\(\\s*\\\"github.com/Microsoft/go-winio\\\"\\)|\\1|" "$file"
 38                  sed -i "s|^// \\(.*conn, err = winio.DialPipe.*\\)|\\1|" "$file"
 39              fi
 40          }
 41          toggle_winio_import comment' > toggle_winio_import.sh
 42
 43      - name: Execute Commenting Function for Linux Build # Comment out lines before Linux build
 44        run: |
 45          bash toggle_winio_import.sh
 46
 47      - name: Build Linux binary
 48        run: |
 49          ./Build/buildlinux
 50
 51      - name: Revert Changes in player.go
 52        run: |
 53          git checkout -- internal/player.go
 54
 55      - name: Build Windows binary (cross-compile)
 56        run: |
 57          ./Build/buildwindows
 58
 59      - name: Upload Artifacts
 60        uses: actions/upload-artifact@v4  # Updated to version 4
 61        with:
 62          name: curd-binaries
 63          path: |
 64            Build/curd
 65            Build/curd.exe
 66
 67      - name: List Build Directory
 68        run: |
 69          echo "Listing contents of Build directory:"
 70          ls -R Build
 71
 72  release:
 73    runs-on: windows-latest  # Use Windows runner for creating the installer
 74    needs: build  # Ensure the build job is complete before running this job
 75    if: github.ref == 'refs/heads/main' && github.event_name == 'push'  # Only run on pushes to main
 76
 77    steps:
 78      - name: Checkout code
 79        uses: actions/checkout@v2
 80        with:
 81          lfs: true
 82
 83      - name: Download and extract MPV binary
 84        run: |
 85          # Create directory if it doesn't exist
 86          New-Item -ItemType Directory -Force -Path "Build\mpv"
 87          # Download the compressed MPV binary
 88          Invoke-WebRequest -Uri "https://raw.githubusercontent.com/${{ github.repository }}/main/Build/mpv.exe.gz" -OutFile "Build\mpv\mpv.exe.gz"
 89          # Extract using 7-Zip (built into Windows runners)
 90          7z x "Build\mpv\mpv.exe.gz" -o"Build\mpv"
 91          Remove-Item "Build\mpv\mpv.exe.gz"
 92        shell: pwsh
 93
 94      - name: Download Artifacts
 95        uses: actions/download-artifact@v4
 96        with:
 97          name: curd-binaries
 98          path: Build
 99
100      - name: Bump Version
101        id: bump_version
102        run: |
103          $current_version = Get-Content VERSION.txt
104          $version_parts = $current_version -split '\.'
105          $major = $version_parts[0]
106          $minor = $version_parts[1]
107          $patch = [int]$version_parts[2] + 1
108          $new_version = "$major.$minor.$patch"
109          $new_version | Set-Content VERSION.txt
110          git config user.name "GitHub Actions"
111          git config user.email "actions@github.com"
112          git add VERSION.txt
113          git commit -m "Bump version to $new_version"
114          git tag "v$new_version"
115          echo "::set-output name=new_version::$new_version"
116
117      - name: Update Inno Setup Script with New Version
118        run: |
119          $new_version = Get-Content VERSION.txt
120          $iss_path = "Build/curd-windows-build.iss"
121          (Get-Content $iss_path) -replace "AppVersion=.*", "AppVersion=$new_version" | Set-Content $iss_path
122  
123      - name: Create Windows Installer
124        run: |
125          & "C:\Program Files (x86)\Inno Setup 6\ISCC.exe" "Build\curd-windows-build.iss"  
126        shell: pwsh
127
128      - name: Create Release
129        id: create_release
130        uses: softprops/action-gh-release@v1
131        with:
132          tag_name: "v${{ steps.bump_version.outputs.new_version }}"  # Use the bumped version as tag
133          name: "Curd v${{ steps.bump_version.outputs.new_version }}"  # Use new version in release name
134          draft: false
135          prerelease: false
136          generate_release_notes: true 
137          files: |
138            Build/curd
139            Build/curd.exe
140            Build/Output/CurdInstaller.exe
141        env:
142          GITHUB_TOKEN: ${{ secrets.ACTIONS_PAT }}