Commit ba5e84440b
Unsigned
Layout: unified · split
.github/workflows/ci-cd.yml +111 −130
| @@ -13,140 +13,121 @@ jobs: | ||
| 13 | 13 | runs-on: ubuntu-latest |
| 14 | 14 | |
| 15 | 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 # Install Go dependencies | |
| 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 | # chmod +x Build/buildlinux | |
| 50 | # ./Build/buildlinux | |
| 51 | ||
| 52 | # - name: Revert Changes in player.go | |
| 53 | # run: | | |
| 54 | # git checkout -- internal/player.go | |
| 55 | ||
| 56 | # - name: Run Tests | |
| 57 | # run: go test ./... # Run tests for your Go code | |
| 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 # Install Go dependencies | |
| 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 | outputDir="Build" # Set the output directory for Linux builds | |
| 50 | mkdir -p "$outputDir" # Create the directory if it doesn't exist | |
| 51 | go build -o "$outputDir/curd-linux" ./cmd/curd/main.go | |
| 52 | ||
| 53 | - name: Revert Changes in player.go | |
| 54 | run: | | |
| 55 | git checkout -- internal/player.go | |
| 56 | ||
| 57 | - name: Build Windows binary (cross-compile) | |
| 58 | run: | | |
| 59 | outputDir="Build" # Use the same name for consistency | |
| 60 | mkdir -p "$outputDir" # Create the directory if it doesn't exist | |
| 61 | set GOOS=windows | |
| 62 | set GOARCH=amd64 | |
| 63 | go build -o "$outputDir\curd.exe" .\cmd\curd\main.go | |
| 64 | ||
| 65 | - name: Upload Artifacts | |
| 66 | uses: actions/upload-artifact@v2 | |
| 67 | with: | |
| 68 | name: curd-binaries | |
| 69 | path: | | |
| 70 | Build/curd-linux | |
| 71 | Build/curd.exe # Include the Windows binary | |
| 58 | 72 | |
| 59 | 73 | release: |
| 60 | 74 | runs-on: windows-latest # Use Windows runner for creating the installer |
| 61 | needs: build | |
| 75 | needs: build # Ensure the build job is complete before running this job | |
| 62 | 76 | if: github.ref == 'refs/heads/main' && github.event_name == 'push' # Only run on pushes to main |
| 63 | 77 | |
| 64 | 78 | steps: |
| 65 | - name: Checkout code | |
| 66 | uses: actions/checkout@v2 | |
| 67 | ||
| 68 | - name: Set up Go | |
| 69 | uses: actions/setup-go@v2 | |
| 70 | with: | |
| 71 | go-version: '1.23.2' | |
| 72 | ||
| 73 | - name: Install Dependencies | |
| 74 | run: go mod tidy # Install Go dependencies | |
| 75 | ||
| 76 | - name: Verify Go Version | |
| 77 | run: go version | |
| 78 | ||
| 79 | - name: Build Windows binary | |
| 80 | run: | | |
| 81 | echo "Current directory: $(Get-Location)" | |
| 82 | echo "Directory contents:" | |
| 83 | dir | |
| 84 | echo "Building the Windows binary..." | |
| 85 | ||
| 86 | $outputDir = "D:\a\curd\curd\Build\" | |
| 87 | ||
| 88 | if (-Not (Test-Path $outputDir)) { | |
| 89 | New-Item -ItemType Directory -Path $outputDir | |
| 90 | echo "Created directory: $outputDir" | |
| 91 | } else { | |
| 92 | echo "Directory already exists: $outputDir" | |
| 93 | } | |
| 94 | ||
| 95 | echo "Building the Windows binary..." | |
| 96 | set GOOS=windows | |
| 97 | set GOARCH=amd64 | |
| 98 | go build -o "$outputDir\curd.exe" .\cmd\curd\main.go | |
| 99 | ||
| 100 | if ($LASTEXITCODE -ne 0) { | |
| 101 | echo "Build failed" | |
| 102 | exit 1 | |
| 103 | } | |
| 104 | echo "Build completed successfully!" | |
| 105 | ||
| 106 | - name: Download Inno Setup # Clean up | |
| 107 | run: | | |
| 108 | Invoke-WebRequest -Uri "https://jrsoftware.org/download.php/is.exe" -OutFile "is.exe" # Download Inno Setup installer | |
| 109 | Start-Process -FilePath "is.exe" -ArgumentList "/SILENT" -Wait # Run installer silently | |
| 110 | Remove-Item "is.exe" | |
| 111 | ||
| 112 | - name: List Build Directory | |
| 113 | run: tree /F | |
| 114 | ||
| 115 | - name: Bump Version | |
| 116 | id: bump_version | |
| 117 | run: | | |
| 118 | $current_version = Get-Content VERSION.txt | |
| 119 | $version_parts = $current_version -split '\.' | |
| 120 | $major = $version_parts[0] | |
| 121 | $minor = $version_parts[1] | |
| 122 | $patch = [int]$version_parts[2] + 1 | |
| 123 | $new_version = "$major.$minor.$patch" | |
| 124 | $new_version | Set-Content VERSION.txt | |
| 125 | Write-Host "New version: $new_version" | |
| 126 | git config user.name "GitHub Actions" | |
| 127 | git config user.email "actions@github.com" | |
| 128 | git add VERSION.txt | |
| 129 | git commit -m "Bump version to $new_version" | |
| 130 | git tag "v$new_version" | |
| 131 | ||
| 132 | - name: Update Inno Setup Script with New Version | |
| 133 | run: | | |
| 134 | $new_version = Get-Content VERSION.txt | |
| 135 | $iss_path = "Build/curd-windows-build.iss" | |
| 136 | (Get-Content $iss_path) -replace "AppVersion=.*", "AppVersion=$new_version" | Set-Content $iss_path | |
| 79 | - name: Checkout code | |
| 80 | uses: actions/checkout@v2 | |
| 81 | ||
| 82 | - name: Download Artifacts | |
| 83 | uses: actions/download-artifact@v2 | |
| 84 | with: | |
| 85 | name: curd-binaries | |
| 86 | path: Build # Specify where to download the artifacts | |
| 87 | ||
| 88 | - name: Set up Go | |
| 89 | uses: actions/setup-go@v2 | |
| 90 | with: | |
| 91 | go-version: '1.23.2' | |
| 92 | ||
| 93 | - name: Install Dependencies | |
| 94 | run: go mod tidy # Install Go dependencies | |
| 95 | ||
| 96 | - name: Bump Version | |
| 97 | id: bump_version | |
| 98 | run: | | |
| 99 | $current_version = Get-Content VERSION.txt | |
| 100 | $version_parts = $current_version -split '\.' | |
| 101 | $major = $version_parts[0] | |
| 102 | $minor = $version_parts[1] | |
| 103 | $patch = [int]$version_parts[2] + 1 | |
| 104 | $new_version = "$major.$minor.$patch" | |
| 105 | $new_version | Set-Content VERSION.txt | |
| 106 | Write-Host "New version: $new_version" | |
| 107 | git config user.name "GitHub Actions" | |
| 108 | git config user.email "actions@github.com" | |
| 109 | git add VERSION.txt | |
| 110 | git commit -m "Bump version to $new_version" | |
| 111 | git tag "v$new_version" | |
| 112 | ||
| 113 | - name: Update Inno Setup Script with New Version | |
| 114 | run: | | |
| 115 | $new_version = Get-Content VERSION.txt | |
| 116 | $iss_path = "Build/curd-windows-build.iss" | |
| 117 | (Get-Content $iss_path) -replace "AppVersion=.*", "AppVersion=$new_version" | Set-Content $iss_path | |
| 137 | 118 | |
| 138 | - name: Create Windows Installer | |
| 139 | run: | | |
| 140 | & "C:\Program Files (x86)\Inno Setup 6\ISCC.exe" "D:\a\curd\curd\Build\curd-windows-build.iss" | |
| 141 | shell: pwsh | |
| 142 | ||
| 143 | - name: Create Release | |
| 144 | id: create_release | |
| 145 | uses: softprops/action-gh-release@v1 | |
| 146 | with: | |
| 147 | tag_name: ${{ steps.bump_version.outputs.new_version }} # Use the bumped version as tag | |
| 148 | release_name: "Curd v${{ steps.bump_version.outputs.new_version }}" # Use new version in release name | |
| 149 | draft: false | |
| 150 | prerelease: false | |
| 151 | env: | |
| 152 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Automatically provided token | |
| 119 | - name: Create Windows Installer | |
| 120 | run: | | |
| 121 | & "C:\Program Files (x86)\Inno Setup 6\ISCC.exe" "Build\curd-windows-build.iss" | |
| 122 | shell: pwsh | |
| 123 | ||
| 124 | - name: Create Release | |
| 125 | id: create_release | |
| 126 | uses: softprops/action-gh-release@v1 | |
| 127 | with: | |
| 128 | tag_name: "v${{ steps.bump_version.outputs.new_version }}" # Use the bumped version as tag | |
| 129 | release_name: "Curd v${{ steps.bump_version.outputs.new_version }}" # Use new version in release name | |
| 130 | draft: false | |
| 131 | prerelease: false | |
| 132 | env: | |
| 133 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Automatically provided token | |