.github/workflows/ci-cd.yml

124 lines · 4151 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
 76      - name: Download Artifacts
 77        uses: actions/download-artifact@v4  # Updated to version 4
 78        with:
 79          name: curd-binaries
 80          path: Build  # Specify where to download the artifacts
 81        
 82      - name: Bump Version
 83        id: bump_version
 84        run: |
 85          $current_version = Get-Content VERSION.txt
 86          $version_parts = $current_version -split '\.'
 87          $major = $version_parts[0]
 88          $minor = $version_parts[1]
 89          $patch = [int]$version_parts[2] + 1
 90          $new_version = "$major.$minor.$patch"
 91          $new_version | Set-Content VERSION.txt
 92          git config user.name "GitHub Actions"
 93          git config user.email "actions@github.com"
 94          git add VERSION.txt
 95          git commit -m "Bump version to $new_version"
 96          git tag "v$new_version"
 97          echo "::set-output name=new_version::$new_version"
 98
 99      - name: Update Inno Setup Script with New Version
100        run: |
101          $new_version = Get-Content VERSION.txt
102          $iss_path = "Build/curd-windows-build.iss"
103          (Get-Content $iss_path) -replace "AppVersion=.*", "AppVersion=$new_version" | Set-Content $iss_path
104  
105      - name: Create Windows Installer
106        run: |
107          & "C:\Program Files (x86)\Inno Setup 6\ISCC.exe" "Build\curd-windows-build.iss"  
108        shell: pwsh
109
110      - name: Create Release
111        id: create_release
112        uses: softprops/action-gh-release@v1
113        with:
114          tag_name: "v${{ steps.bump_version.outputs.new_version }}"  # Use the bumped version as tag
115          name: "Curd v${{ steps.bump_version.outputs.new_version }}"  # Use new version in release name
116          draft: false
117          prerelease: false
118          generate_release_notes: true 
119          files: |
120            Build/curd
121            Build/curd.exe
122            Build/Output/CurdInstaller.exe
123        env:
124          GITHUB_TOKEN: ${{ secrets.ACTIONS_PAT }}