.github/workflows/ci-cd.yml

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