.github/workflows/ci-cd.yml
126 lines · 4185 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 release:
68 runs-on: windows-latest # Use Windows runner for creating the installer
69 needs: build # Ensure the build job is complete before running this job
70 if: github.ref == 'refs/heads/main' && github.event_name == 'push' # Only run on pushes to main
71
72 steps:
73 - name: Checkout code
74 uses: actions/checkout@v2
75 with:
76 lfs: true
77
78 - name: Download Artifacts
79 uses: actions/download-artifact@v4 # Updated to version 4
80 with:
81 name: curd-binaries
82 path: Build # Specify where to download the artifacts
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 }}