.github/workflows/ci-cd.yml

187 lines · 6965 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  workflow_dispatch:
 11    inputs:
 12      pr_number:
 13        description: 'Pull Request Number'
 14        required: false
 15        type: string
 16
 17jobs:
 18  build:
 19    runs-on: ubuntu-latest
 20
 21    steps:
 22      - name: Checkout code
 23        uses: actions/checkout@v4
 24        with:
 25          fetch-depth: 0  # Fetch all history and tags
 26          ref: ${{ github.event.pull_request.head.sha || (github.event.inputs.pr_number && format('refs/pull/{0}/head', github.event.inputs.pr_number)) || github.sha }}
 27
 28      - name: Set up Go
 29        uses: actions/setup-go@v4
 30        with:
 31          go-version: '1.21'
 32
 33      - name: Install Dependencies
 34        run: go mod tidy
 35
 36      - name: Build Linux binary
 37        run: |
 38          ./Build/buildlinux
 39          mkdir -p release/linux
 40          mv curd-linux-x86_64 release/linux/
 41          mv curd-linux-arm64 release/linux/
 42        env:
 43          GITHUB_EVENT_NAME: ${{ github.event_name }}
 44          GITHUB_REF: ${{ github.ref }}
 45          GITHUB_EVENT_HEAD_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
 46          COMPRESS: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && contains(github.event.head_commit.message, 'release:') }}
 47
 48      - name: Build macOS x86_64 binary
 49        run: |
 50          ./Build/buildmac-x86_64
 51
 52      - name: Build macOS ARM64 binary
 53        run: |
 54          ./Build/buildmac-arm64
 55
 56      - name: Install LLVM and gcc-mingw-w64
 57        run: |
 58          sudo apt-get update && sudo apt-get install -y llvm gcc-mingw-w64
 59          # Find the llvm-lipo command
 60          LIPO_CMD=$(find /usr/bin -name "llvm-lipo*" | head -n 1)
 61          echo "Found lipo command: $LIPO_CMD"
 62          echo "LIPO_CMD=$LIPO_CMD" >> $GITHUB_ENV
 63
 64      - name: Create Universal macOS binary
 65        run: |
 66          ${{ env.LIPO_CMD }} -create "curd-macos-x86_64" "curd-macos-arm64" -output "curd-macos-universal"
 67          mkdir -p release/macos
 68          mv curd-macos-x86_64 release/macos
 69          mv curd-macos-arm64 release/macos
 70          mv curd-macos-universal release/macos
 71
 72      - name: Build Windows binary (cross-compile)
 73        run: |
 74          ./Build/buildwindows
 75          mkdir -p release/windows
 76          mv curd-windows-x86_64.exe release/windows/curd-windows-x86_64.exe
 77        env:
 78          GITHUB_EVENT_NAME: ${{ github.event_name }}
 79          GITHUB_REF: ${{ github.ref }}
 80          GITHUB_EVENT_HEAD_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
 81          COMPRESS: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && contains(github.event.head_commit.message, 'release:') }}
 82
 83      - name: Upload Artifacts
 84        uses: actions/upload-artifact@v4
 85        with:
 86          name: curd-binaries
 87          path: |
 88            release/linux/curd-linux-x86_64
 89            release/linux/curd-linux-arm64
 90            release/macos/curd-macos-x86_64
 91            release/macos/curd-macos-arm64
 92            release/macos/curd-macos-universal
 93            release/windows/curd-windows-x86_64.exe
 94          retention-days: 1
 95          if-no-files-found: error
 96
 97  release:
 98    runs-on: windows-latest
 99    needs: build
100    permissions:
101      contents: write
102      actions: read
103    if: |
104      github.ref == 'refs/heads/main' && 
105      github.event_name == 'push' && 
106      (contains(github.event.head_commit.message, 'release:'))
107
108    steps:
109      - name: Checkout code
110        uses: actions/checkout@v4
111        with:
112          fetch-depth: 0
113
114      - name: Download and extract MPV binary
115        run: |
116          # Create directory if it doesn't exist
117          New-Item -ItemType Directory -Force -Path "Build\mpv"
118          # Download the compressed MPV binary
119          Invoke-WebRequest -Uri "https://raw.githubusercontent.com/${{ github.repository }}/main/Build/mpv.exe.gz" -OutFile "Build\mpv\mpv.exe.gz"
120          # Extract using 7-Zip (built into Windows runners)
121          7z x "Build\mpv\mpv.exe.gz" -o"Build\mpv"
122          Remove-Item "Build\mpv\mpv.exe.gz"
123        shell: pwsh
124
125      - name: Download Artifacts
126        uses: actions/download-artifact@v4
127        with:
128          name: curd-binaries
129          path: Build
130
131      - name: Organize Release Files
132        run: |
133          $version = Get-Content VERSION.txt
134          echo "CURD_VERSION=$version" >> $env:GITHUB_ENV
135          $release_dir = "releases/curd-$version"
136          
137          # Create directory structure
138          New-Item -ItemType Directory -Force -Path "$release_dir/windows"
139          New-Item -ItemType Directory -Force -Path "$release_dir/macos"
140          New-Item -ItemType Directory -Force -Path "$release_dir/linux"
141          
142          # List contents of Build directory to debug
143          Write-Host "Contents of Build directory:"
144          Get-ChildItem -Path "Build" -Recurse
145          
146          # Move files to their respective directories
147          Move-Item "Build/windows/curd-windows-x86_64.exe" "$release_dir/windows/"
148          Move-Item "Build/macos/curd-macos-universal" "$release_dir/macos/"
149          Move-Item "Build/macos/curd-macos-x86_64" "$release_dir/macos/"
150          Move-Item "Build/macos/curd-macos-arm64" "$release_dir/macos/"
151          Move-Item "Build/linux/curd-linux-x86_64" "$release_dir/linux/"
152          Move-Item "Build/linux/curd-linux-arm64" "$release_dir/linux/"
153          Copy-Item "Build/mpv/mpv.exe" "$release_dir/windows/"
154        shell: pwsh
155
156      - name: Update Inno Setup Script with New Version
157        run: |
158          $iss_path = "Build/curd-windows-build.iss"
159          $content = Get-Content $iss_path
160          $content = $content -replace '^AppVersion=.*', "AppVersion=$env:CURD_VERSION"
161          Set-Content $iss_path $content
162        shell: pwsh
163
164      - name: Create Windows Installer
165        run: |
166          & "C:\Program Files (x86)\Inno Setup 6\ISCC.exe" "Build\curd-windows-build.iss"  
167        shell: pwsh
168
169      - name: Create Release
170        id: create_release
171        uses: softprops/action-gh-release@v1
172        with:
173          tag_name: "v${{ env.CURD_VERSION }}"
174          name: "Curd v${{ env.CURD_VERSION }}"
175          draft: false
176          prerelease: false
177          generate_release_notes: true 
178          files: |
179            releases/curd-${{ env.CURD_VERSION }}/linux/curd-linux-x86_64
180            releases/curd-${{ env.CURD_VERSION }}/linux/curd-linux-arm64
181            releases/curd-${{ env.CURD_VERSION }}/macos/curd-macos-x86_64
182            releases/curd-${{ env.CURD_VERSION }}/macos/curd-macos-arm64
183            releases/curd-${{ env.CURD_VERSION }}/macos/curd-macos-universal
184            releases/curd-${{ env.CURD_VERSION }}/windows/curd-windows-x86_64.exe
185            Build/Output/curd-windows-installer.exe
186        env:
187          GITHUB_TOKEN: ${{ secrets.ACTIONS_PAT }}