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