.github/workflows/ci-cd.yml

201 lines · 7431 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
 57        run: |
 58          sudo apt-get update && sudo apt-get install -y llvm
 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: Checkout MPV binaries
115        uses: actions/checkout@v4
116        with:
117          ref: mpv-binaries
118          path: mpv-temp
119          sparse-checkout: |
120            Build/mpv.exe.gz
121            Build/mpv.zip
122
123      - name: Setup MPV binary
124        run: |
125          New-Item -ItemType Directory -Force -Path "Build\mpv"
126          if (Test-Path "mpv-temp/Build/mpv.exe.gz") {
127            Copy-Item "mpv-temp/Build/mpv.exe.gz" "Build\mpv\mpv.exe.gz"
128            7z x "Build\mpv\mpv.exe.gz" -o"Build\mpv"
129            Remove-Item "Build\mpv\mpv.exe.gz"
130          } else {
131            Write-Host "Warning: MPV binary not found in mpv-binaries branch, downloading from URL..."
132            Invoke-WebRequest -Uri "https://raw.githubusercontent.com/${{ github.repository }}/main/Build/mpv.exe.gz" -OutFile "Build\mpv\mpv.exe.gz"
133            7z x "Build\mpv\mpv.exe.gz" -o"Build\mpv"
134            Remove-Item "Build\mpv\mpv.exe.gz"
135          }
136          Remove-Item -Recurse -Force "mpv-temp" -ErrorAction SilentlyContinue
137        shell: pwsh
138
139      - name: Download Artifacts
140        uses: actions/download-artifact@v4
141        with:
142          name: curd-binaries
143          path: Build
144
145      - name: Organize Release Files
146        run: |
147          $version = Get-Content VERSION.txt
148          echo "CURD_VERSION=$version" >> $env:GITHUB_ENV
149          $release_dir = "releases/curd-$version"
150          
151          # Create directory structure
152          New-Item -ItemType Directory -Force -Path "$release_dir/windows"
153          New-Item -ItemType Directory -Force -Path "$release_dir/macos"
154          New-Item -ItemType Directory -Force -Path "$release_dir/linux"
155          
156          # List contents of Build directory to debug
157          Write-Host "Contents of Build directory:"
158          Get-ChildItem -Path "Build" -Recurse
159          
160          # Move files to their respective directories
161          Move-Item "Build/windows/curd-windows-x86_64.exe" "$release_dir/windows/"
162          Move-Item "Build/macos/curd-macos-universal" "$release_dir/macos/"
163          Move-Item "Build/macos/curd-macos-x86_64" "$release_dir/macos/"
164          Move-Item "Build/macos/curd-macos-arm64" "$release_dir/macos/"
165          Move-Item "Build/linux/curd-linux-x86_64" "$release_dir/linux/"
166          Move-Item "Build/linux/curd-linux-arm64" "$release_dir/linux/"
167          Copy-Item "Build/mpv/mpv.exe" "$release_dir/windows/"
168        shell: pwsh
169
170      - name: Update Inno Setup Script with New Version
171        run: |
172          $iss_path = "Build/curd-windows-build.iss"
173          $content = Get-Content $iss_path
174          $content = $content -replace '^AppVersion=.*', "AppVersion=$env:CURD_VERSION"
175          Set-Content $iss_path $content
176        shell: pwsh
177
178      - name: Create Windows Installer
179        run: |
180          & "C:\Program Files (x86)\Inno Setup 6\ISCC.exe" "Build\curd-windows-build.iss"  
181        shell: pwsh
182
183      - name: Create Release
184        id: create_release
185        uses: softprops/action-gh-release@v1
186        with:
187          tag_name: "v${{ env.CURD_VERSION }}"
188          name: "Curd v${{ env.CURD_VERSION }}"
189          draft: false
190          prerelease: false
191          generate_release_notes: true 
192          files: |
193            releases/curd-${{ env.CURD_VERSION }}/linux/curd-linux-x86_64
194            releases/curd-${{ env.CURD_VERSION }}/linux/curd-linux-arm64
195            releases/curd-${{ env.CURD_VERSION }}/macos/curd-macos-x86_64
196            releases/curd-${{ env.CURD_VERSION }}/macos/curd-macos-arm64
197            releases/curd-${{ env.CURD_VERSION }}/macos/curd-macos-universal
198            releases/curd-${{ env.CURD_VERSION }}/windows/curd-windows-x86_64.exe
199            Build/Output/curd-windows-installer.exe
200        env:
201          GITHUB_TOKEN: ${{ secrets.ACTIONS_PAT }}