summaryrefslogtreecommitdiff
path: root/.github/workflows/release.yml
blob: 0265e2c070efa0e2a3e90ebacfa709ce5548a121 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
name: Cross-platform Build

on:
  push:
    tags: [ 'v*' ]
  workflow_dispatch:

permissions:
  contents: write

jobs:
  extract-version:
    name: Extract Version
    runs-on: ubuntu-latest
    outputs:
      version: ${{ steps.get_version.outputs.version }}
      version_valid: ${{ steps.validate_version.outputs.valid }}
    steps:
    - uses: actions/checkout@v4

    - name: Get version from Cargo.toml
      id: get_version
      run: |
        VERSION=$(grep '^version =' Cargo.toml | sed -E 's/version = "([^"]+)"/\1/')
        echo "Extracted version: $VERSION"
        echo "version=$VERSION" >> $GITHUB_OUTPUT

    - name: Validate SemVer
      id: validate_version
      run: |
        VERSION=${{ steps.get_version.outputs.version }}
        # Comprehensive SemVer validation regex
        # Supports: MAJOR.MINOR.PATCH-PRERELEASE+BUILD
        # Where PRERELEASE can be: alpha, beta, rc.1, etc.
        # Where BUILD can be: build.123, sha.abc123, etc.
        if [[ ! $VERSION =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?(\+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?$ ]]; then
          echo "Error: Version '$VERSION' is not a valid SemVer string"
          echo "valid=false" >> $GITHUB_OUTPUT
          exit 1
        else
          echo "Version '$VERSION' is valid SemVer"
          echo "valid=true" >> $GITHUB_OUTPUT
        fi

  build-windows:
    name: Build Windows
    runs-on: windows-latest
    needs: extract-version
    strategy:
      matrix:
        target: 
          - x86_64-pc-windows-msvc
          - aarch64-pc-windows-msvc
    steps:
    - uses: actions/checkout@v4
    
    - name: Install Rust
      uses: dtolnay/rust-toolchain@stable
      with:
        targets: ${{ matrix.target }}
    
    - name: Build
      run: cargo build --release --target ${{ matrix.target }}
    
    - name: Prepare artifact
      run: |
        mkdir artifacts
        $arch = "${{ matrix.target }}".Split('-')[0]
        $version = "${{ needs.extract-version.outputs.version }}"
        copy "target\${{ matrix.target }}\release\mikusays.exe" "artifacts\mikusays-windows-$arch-$version.exe"
    
    - name: Upload artifact
      uses: actions/upload-artifact@v4
      with:
        name: mikusays-windows-${{ matrix.target }}
        path: artifacts\*
  build-linux:
    name: Build Linux
    runs-on: ubuntu-latest
    needs: extract-version
    strategy:
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            arch: x64
          - target: aarch64-unknown-linux-gnu  
            arch: arm64
    steps:
    - uses: actions/checkout@v4
    
    - name: Install Rust
      uses: dtolnay/rust-toolchain@stable
      with:
        targets: ${{ matrix.target }}
    
    - name: Install cross-compilation tools
      if: matrix.target == 'aarch64-unknown-linux-gnu'
      run: |
        sudo apt-get update
        sudo apt-get install -y gcc-aarch64-linux-gnu
        echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
    
    - name: Build
      run: cargo build --release --target ${{ matrix.target }}
    
    - name: Strip binary
      run: |
        if [[ "${{ matrix.target }}" == "aarch64-unknown-linux-gnu" ]]; then
          aarch64-linux-gnu-strip target/${{ matrix.target }}/release/mikusays
        else
          strip target/${{ matrix.target }}/release/mikusays
        fi
    
    - name: Prepare artifact
      run: |
        mkdir -p artifacts
        version="${{ needs.extract-version.outputs.version }}"
        cp target/${{ matrix.target }}/release/mikusays artifacts/mikusays-linux-${{ matrix.arch }}-$version
        chmod +x artifacts/mikusays-linux-${{ matrix.arch }}-$version
    
    - name: Upload artifact
      uses: actions/upload-artifact@v4
      with:
        name: mikusays-linux-${{ matrix.arch }}
        path: artifacts/*
  build-macos:
    name: Build macOS
    runs-on: macos-latest
    needs: extract-version
    strategy:
      matrix:
        include:
          - target: x86_64-apple-darwin
            arch: x64
          - target: aarch64-apple-darwin
            arch: arm64
    steps:
    - uses: actions/checkout@v4
    
    - name: Install Rust
      uses: dtolnay/rust-toolchain@stable
      with:
        targets: ${{ matrix.target }}
    
    - name: Build
      run: cargo build --release --target ${{ matrix.target }}
    
    - name: Strip binary
      run: strip target/${{ matrix.target }}/release/mikusays
    
    - name: Prepare artifact
      run: |
        mkdir -p artifacts
        version="${{ needs.extract-version.outputs.version }}"
        cp target/${{ matrix.target }}/release/mikusays artifacts/mikusays-macos-${{ matrix.arch }}-$version
        chmod +x artifacts/mikusays-macos-${{ matrix.arch }}-$version
    
    - name: Upload artifact
      uses: actions/upload-artifact@v4
      with:
        name: mikusays-macos-${{ matrix.arch }}
        path: artifacts/*

  create-release:
    name: Create Release
    runs-on: ubuntu-latest
    needs: [extract-version, build-windows, build-linux, build-macos]
    if: startsWith(github.ref, 'refs/tags/v') && needs.extract-version.outputs.version_valid == 'true'
    steps:
    - uses: actions/checkout@v4
    
    - name: Download all artifacts
      uses: actions/download-artifact@v4
      with:
        path: artifacts
        merge-multiple: true
    
    - name: Display structure of downloaded files
      run: ls -R artifacts
    
    - name: Create Release
      uses: softprops/action-gh-release@v1
      with:
        files: artifacts/mikusays-*
        draft: false
        prerelease: false
        generate_release_notes: true
        body: |
          ## Downloads
          
          ### Windows
          - **x64**: `mikusays-windows-x86_64-${{ needs.extract-version.outputs.version }}.exe`
          - **ARM64**: `mikusays-windows-aarch64-${{ needs.extract-version.outputs.version }}.exe`

          ### Windows Installer
          - **Any**: `mikusays-windows-inst-any.exe`

          ### Linux (binary)
          - **x64**: `mikusays-linux-x64-${{ needs.extract-version.outputs.version }}`
          - **ARM64**: `mikusays-linux-arm64-${{ needs.extract-version.outputs.version }}`

          ### Debian Package
          - **x64 Debian Package**: `mikusays-debian-x64.deb`
          - **ARM64 Debian Package**: `mikusays-debian-arm64.deb`

          ### RedHat (RPM) Package
          - **x64 RPM Package**: `mikusays-redhat-x64.rpm`
          - **ARM64 RPM Package**: `mikusays-redhat-arm64.rpm`

          ### Repository for Debian / Ubuntu / Fedora / RHEL / CentOS
          Information on how to add it available here https://apt.xxanqw.pp.ua
          
          ### macOS
          - **Intel (x64)**: `mikusays-macos-x64-${{ needs.extract-version.outputs.version }}`
          - **Apple Silicon (ARM64)**: `mikusays-macos-arm64-${{ needs.extract-version.outputs.version }}`
          
          ## Usage
          ```bash
          # Download the appropriate binary for your platform
          # On Unix-like systems, make it executable:
          chmod +x mikusays-*
          
          # Run the program:
          ./mikusays-* "Hello, World!"
          ```
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}