.github/workflows/ci-cd.yml
136 lines · 4480 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 pwd
50 tree ./
51 outputDir="Build"
52 mkdir -p "$outputDir"
53 go build -o "$outputDir/curd" ./cmd/curd/main.go
54 pwd
55 tree ./
56
57 - name: Revert Changes in player.go
58 run: |
59 git checkout -- internal/player.go
60
61 - name: Build Windows binary (cross-compile)
62 run: |
63 pwd
64 tree ./
65 outputDir="Build"
66 mkdir -p "$outputDir"
67 GOOS=windows GOARCH=amd64 go build -o "$outputDir/curd.exe" ./cmd/curd/main.go
68 pwd
69 tree ./
70
71 - name: Upload Artifacts
72 uses: actions/upload-artifact@v4 # Updated to version 4
73 with:
74 name: curd-binaries
75 path: |
76 Build/curd
77 Build/curd.exe
78
79 release:
80 runs-on: windows-latest # Use Windows runner for creating the installer
81 needs: build # Ensure the build job is complete before running this job
82 if: github.ref == 'refs/heads/main' && github.event_name == 'push' # Only run on pushes to main
83
84 steps:
85 - name: Checkout code
86 uses: actions/checkout@v2
87
88 - name: Download Artifacts
89 uses: actions/download-artifact@v4 # Updated to version 4
90 with:
91 name: curd-binaries
92 path: Build # Specify where to download the artifacts
93
94 - name: Bump Version
95 id: bump_version
96 run: |
97 $current_version = Get-Content VERSION.txt
98 $version_parts = $current_version -split '\.'
99 $major = $version_parts[0]
100 $minor = $version_parts[1]
101 $patch = [int]$version_parts[2] + 1
102 $new_version = "$major.$minor.$patch"
103 $new_version | Set-Content VERSION.txt
104 git config user.name "GitHub Actions"
105 git config user.email "actions@github.com"
106 git add VERSION.txt
107 git commit -m "Bump version to $new_version"
108 git tag "v$new_version"
109 echo "::set-output name=new_version::$new_version"
110
111 - name: Update Inno Setup Script with New Version
112 run: |
113 $new_version = Get-Content VERSION.txt
114 $iss_path = "Build/curd-windows-build.iss"
115 (Get-Content $iss_path) -replace "AppVersion=.*", "AppVersion=$new_version" | Set-Content $iss_path
116
117 - name: Create Windows Installer
118 run: |
119 & "C:\Program Files (x86)\Inno Setup 6\ISCC.exe" "Build\curd-windows-build.iss"
120 shell: pwsh
121
122 - name: Create Release
123 id: create_release
124 uses: softprops/action-gh-release@v1
125 with:
126 tag_name: "v${{ steps.bump_version.outputs.new_version }}" # Use the bumped version as tag
127 name: "Curd v${{ steps.bump_version.outputs.new_version }}" # Use new version in release name
128 draft: false
129 prerelease: false
130 generate_release_notes: true
131 files: |
132 Build/curd
133 Build/curd.exe
134 Build/curdInstaller.exe
135 env:
136 GITHUB_TOKEN: ${{ secrets.ACTIONS_PAT }}