mal-cli-rs 0.2.1

CLI tool for myanimelist
Documentation
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
name: CI

on:
  push:
    branches: [ master ]  # Only run on master pushes
    tags: [ 'v*' ]  # Trigger on version tags
  pull_request:
    branches: [ master ]

env:
  CARGO_TERM_COLOR: always
  RUST_BACKTRACE: 1

jobs:
  
  # Build jobs (only run on tags for releases)
  build:
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
            rust: stable
            target: x86_64-unknown-linux-gnu
            artifact_name: mal-cli
            asset_name: mal-cli-linux-x86_64
          # - os: ubuntu-latest
          #   rust: nightly
          #   target: x86_64-unknown-linux-gnu
          #   artifact_name: mal-cli
            # asset_name: mal-cli-linux-x86_64-nightly
          - os: macos-latest
            rust: stable
            target: x86_64-apple-darwin
            artifact_name: mal-cli
            asset_name: mal-cli-macos-x86_64
          # - os: macos-latest
          #   rust: nightly
          #   target: x86_64-apple-darwin
          #   artifact_name: mal-cli
          #   asset_name: mal-cli-macos-x86_64-nightly
          - os: windows-latest
            rust: stable
            target: x86_64-pc-windows-msvc
            artifact_name: mal-cli.exe
            asset_name: mal-cli-windows-x86_64.exe
          # - os: windows-latest
          #   rust: nightly
          #   target: x86_64-pc-windows-msvc
          #   artifact_name: mal-cli.exe
          #   asset_name: mal-cli-windows-x86_64.exe-nightly

    runs-on: ${{ matrix.os }}
    if: startsWith(github.ref, 'refs/tags/v')  # Only run on tag pushes
    continue-on-error: ${{ matrix.rust == 'nightly' }}

    steps:
      - uses: actions/checkout@v4

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: ${{ matrix.rust }}
          components: clippy
          targets: ${{ matrix.target }}

      - name: Cache cargo registry
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-${{ matrix.rust }}-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            ${{ runner.os }}-cargo-${{ matrix.rust }}-
            ${{ runner.os }}-cargo-

      - name: Build Debug
        run: |
          rustc --version
          make build

      - name: Run clippy
        run: |
          cargo clean
          make clippy

      - name: Build Release
        shell: bash
        run: |
          make build-release 
      
          if [[ "$RUNNER_OS" == "Windows" ]]; then
            echo "Detected Windows"
            ./target/release/mal.exe --version || echo "mal.exe not found"
            ls -l target/release/ || true
            cp target/release/mal.exe target/release/${{ matrix.artifact_name }}
          else
            echo "Detected Linux/macOS"
            ./target/release/mal --version || echo "mal not found"
            ls -l target/release/ || true
            cp target/release/mal target/release/${{ matrix.artifact_name }}
          fi

      - name: Upload binary artifacts
        uses: actions/upload-artifact@v4
        with:
          name: ${{ matrix.asset_name }}
          path: target/release/${{ matrix.artifact_name }}

  build-linux-musl:
    runs-on: ubuntu-latest
    if: startsWith(github.ref, 'refs/tags/v')  # Only run on tag pushes
    steps:
      - uses: actions/checkout@v4

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: stable
          targets: x86_64-unknown-linux-musl

      - name: Cache cargo registry
        uses: actions/cache@v3
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-musl-cargo-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            ${{ runner.os }}-musl-cargo-

      - name: Setup MUSL
        run: |
          sudo apt-get update -qq
          sudo apt-get install -qq musl-tools

      - name: Build Debug
        run: |
          make build-linux-musl-debug
          ./target/x86_64-unknown-linux-musl/debug/mal --version

      - name: Build Release 
        run: |
          make build-linux-musl-release
          ./target/x86_64-unknown-linux-musl/release/mal --version

      - name: Upload MUSL binary artifacts
        uses: actions/upload-artifact@v4
        with:
          name: mal-cli-linux-musl-static
          path: target/x86_64-unknown-linux-musl/release/mal

  rustfmt:
    name: Rustfmt
    runs-on: ubuntu-latest
    if: ${{ !startsWith(github.ref, 'refs/tags/v') }}   # Skip on tag pushes, handled in test job
    steps:
      - uses: actions/checkout@v4

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt

      - name: Check formatting
        run: cargo fmt -- --check

  security-audit:
    name: Security audit
    runs-on: ubuntu-latest
    if: ${{ !startsWith(github.ref, 'refs/tags/v') }}  # Skip on tag pushes, handled in test job
    steps:
      - uses: actions/checkout@v4

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Cache cargo registry
        uses: actions/cache@v3
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
          key: ${{ runner.os }}-audit-cargo-${{ hashFiles('**/Cargo.lock') }}

      - name: Run security audit
        run: make audit

  # GitHub Release Job
  release:
    name: Create GitHub Release
    runs-on: ubuntu-latest
    if: startsWith(github.ref, 'refs/tags/v')
    needs: [build, build-linux-musl]
    steps:
      - uses: actions/checkout@v4

      - name: Get version
        id: version
        run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT

      - name: Download all artifacts
        uses: actions/download-artifact@v4
        with:
          path: artifacts

      - name: Prepare release assets
        run: |
          mkdir -p release-assets
          VERSION="${{ steps.version.outputs.VERSION }}"

          ls -R ./artifacts/
          # Copy and rename artifacts for release with version
          cp artifacts/mal-cli-linux-x86_64/mal-cli release-assets/mal-cli-v${VERSION}-linux-x86_64

          cp artifacts/mal-cli-linux-musl-static/mal  release-assets/mal-cli-v${VERSION}-linux-musl-x86_64
          
          cp artifacts/mal-cli-macos-x86_64/mal-cli release-assets/mal-cli-v${VERSION}-macos-x86_64
          
          cp artifacts/mal-cli-windows-x86_64.exe/mal-cli.exe release-assets/mal-cli-v${VERSION}-windows-x86_64.exe
          
          # Make binaries executable
          chmod +x release-assets/mal-cli-v${VERSION}-*
          
          # Create checksums
          cd release-assets
          sha256sum * > checksums.txt
          cd ..

      - name: Create Release
        uses: softprops/action-gh-release@v2
        with:
          files: |
            release-assets/*
          generate_release_notes: true
          draft: false
          prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc') }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# AUR Package Release
  aur-release:
    name: Release to AUR
    runs-on: ubuntu-latest
    if: startsWith(github.ref, 'refs/tags/v')
    needs: [release]
    steps:
      - uses: actions/checkout@v4

      - name: Get version
        id: version
        run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT

      - name: Generate PKGBUILD
        run: |
          # Download source tarball to calculate sha256
          curl -L -o source.tar.gz "https://github.com/${GITHUB_REPOSITORY}/archive/refs/tags/v${{ steps.version.outputs.VERSION }}.tar.gz"
          SHA256=$(sha256sum source.tar.gz | cut -d' ' -f1)
          
          cat > PKGBUILD << EOF
          # Maintainer: L4z3x <moussaousselmal1970@gmail.com>
          pkgname=mal-cli
          pkgver=${{ steps.version.outputs.VERSION }}
          pkgrel=1
          pkgdesc="A powerful CLI tool for MyAnimeList"
          arch=('x86_64')
          url="https://github.com/${GITHUB_REPOSITORY}"
          license=('MIT')
          depends=('gcc-libs')
          makedepends=('rust' 'cargo')
          source=("\${pkgname}-\${pkgver}.tar.gz::https://github.com/${GITHUB_REPOSITORY}/archive/refs/tags/v\${pkgver}.tar.gz")
          sha256sums=('${SHA256}')
          options=('!lto')
          build() {
              cd "\${srcdir}/mal-cli-\${pkgver}"
              cargo build --release --locked
          }
          
          package() {
              cd "\${srcdir}/mal-cli-\${pkgver}"
              install -Dm755 "target/release/mal" "\${pkgdir}/usr/bin/mal"
          }
          EOF
          
          # Generate .SRCINFO manually (simpler than installing makepkg)
          cat > .SRCINFO << EOF
          pkgbase = mal-cli
          	pkgdesc = A powerful CLI tool for MyAnimeList
          	pkgver = ${{ steps.version.outputs.VERSION }}
          	pkgrel = 1
          	url = https://github.com/${GITHUB_REPOSITORY}
          	arch = x86_64
          	license = MIT
          	makedepends = rust
          	makedepends = cargo
          	depends = gcc-libs
          	source = mal-cli-${{ steps.version.outputs.VERSION }}.tar.gz::https://github.com/${GITHUB_REPOSITORY}/archive/refs/tags/v${{ steps.version.outputs.VERSION }}.tar.gz
          	sha256sums = ${SHA256}
          
          pkgname = mal-cli
          EOF

      - name: Publish to AUR
        uses: KSXGitHub/github-actions-deploy-aur@v4.1.1
        with:
          pkgname: mal-cli
          pkgbuild: ./PKGBUILD
          commit_username: ${{ secrets.AUR_USERNAME }}
          commit_email: ${{ secrets.AUR_EMAIL }}
          ssh_private_key: ${{ secrets.AUR_SSH_PRIVATE_KEY }}
          commit_message: "Update to version ${{ steps.version.outputs.VERSION }}"
          ssh_keyscan_types: rsa,ecdsa,ed25519
          allow_empty_commits: false
# Debian Package Release
  debian-release:
    name: Create Debian Package
    runs-on: ubuntu-latest
    if: startsWith(github.ref, 'refs/tags/v')
    needs: [release]
    steps:
      - uses: actions/checkout@v4

      - name: Get version
        id: version
        run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT

      - name: Install packaging tools
        run: |
          sudo apt-get update
          sudo apt-get install -y devscripts build-essential lintian fakeroot

      - name: Download Linux binary
        uses: actions/download-artifact@v4
        with:
          name: mal-cli-linux-x86_64
          path: ./artifacts

      - name: Create Debian package structure
        run: |
          PKG_NAME="mal-cli"
          VERSION="${{ steps.version.outputs.VERSION }}"
          PKG_DIR="${PKG_NAME}_${VERSION}"
          
          # Create package directory structure
          mkdir -p ${PKG_DIR}/DEBIAN
          mkdir -p ${PKG_DIR}/usr/bin
          mkdir -p ${PKG_DIR}/usr/share/doc/${PKG_NAME}
          
          # Copy binary and make executable
          cp ./artifacts/mal-cli ${PKG_DIR}/usr/bin/mal
          chmod +x ${PKG_DIR}/usr/bin/mal
          
          # Create control file
          cat > ${PKG_DIR}/DEBIAN/control << EOF
          Package: mal-cli
          Version: ${VERSION}
          Section: utils
          Priority: optional
          Architecture: amd64
          Depends: libc6 (>= 2.17), libgcc-s1 (>= 3.0)
          Maintainer: L4z3x <moussaousselmal1970@gmail.com>
          Description: A powerful CLI tool for MyAnimeList
           mal-cli is a command-line interface tool that provides functionality
           for interacting with MyAnimeList. It allows users to manage their
           anime lists and perform various operations from the terminal.
           .
           This package provides the 'mal' command for MyAnimeList operations.
          Homepage: https://github.com/${GITHUB_REPOSITORY}
          EOF
          
          # Create copyright file
          cat > ${PKG_DIR}/usr/share/doc/${PKG_NAME}/copyright << EOF
          Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
          Upstream-Name: mal-cli
          Upstream-Contact: L4z3x <moussaousselmal1970@gmail.com>
          Source: https://github.com/${GITHUB_REPOSITORY}
          
          Files: *
          Copyright: $(date +%Y) L4z3x
          License: MIT
           Permission is hereby granted, free of charge, to any person obtaining a
           copy of this software and associated documentation files (the "Software"),
           to deal in the Software without restriction, including without limitation
           the rights to use, copy, modify, merge, publish, distribute, sublicense,
           and/or sell copies of the Software, and to permit persons to whom the
           Software is furnished to do so, subject to the following conditions:
           .
           The above copyright notice and this permission notice shall be included
           in all copies or substantial portions of the Software.
           .
           THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
           OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
           FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
           THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
           LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
           FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
           DEALINGS IN THE SOFTWARE.
          EOF
          
          # Create changelog
          cat > ${PKG_DIR}/usr/share/doc/${PKG_NAME}/changelog.Debian << EOF
          mal-cli (${VERSION}-1) unstable; urgency=medium
          
            * New upstream release ${VERSION}
            * Updated dependencies and build system
          
           -- L4z3x <moussaousselmal1970@gmail.com>  $(date -R)
          EOF
          
          # Compress changelog
          gzip -9 ${PKG_DIR}/usr/share/doc/${PKG_NAME}/changelog.Debian
          
          # Create postinst script (optional, for any post-installation tasks)
          cat > ${PKG_DIR}/DEBIAN/postinst << EOF
          #!/bin/bash
          set -e
          
          # Ensure binary is executable
          chmod +x /usr/bin/mal
          
          exit 0
          EOF
          chmod 755 ${PKG_DIR}/DEBIAN/postinst
          
          # Create prerm script (optional, for cleanup before removal)
          cat > ${PKG_DIR}/DEBIAN/prerm << EOF
          #!/bin/bash
          set -e
          
          # Nothing to do before removal
          
          exit 0
          EOF
          chmod 755 ${PKG_DIR}/DEBIAN/prerm

      - name: Build Debian package
        run: |
          PKG_NAME="mal-cli"
          VERSION="${{ steps.version.outputs.VERSION }}"
          PKG_DIR="${PKG_NAME}_${VERSION}"
          
          # Set package permissions correctly
          find ${PKG_DIR} -type d -exec chmod 755 {} \;
          find ${PKG_DIR}/usr -type f -exec chmod 644 {} \;
          chmod +x ${PKG_DIR}/usr/bin/mal
          chmod 755 ${PKG_DIR}/DEBIAN/postinst
          chmod 755 ${PKG_DIR}/DEBIAN/prerm
          
          # Build the package
          dpkg-deb --build ${PKG_DIR}
          
          # Rename to standard naming convention
          mv ${PKG_DIR}.deb mal-cli_${VERSION}-1_amd64.deb
          
          # Verify the package
          dpkg-deb --info mal-cli_${VERSION}-1_amd64.deb
          dpkg-deb --contents mal-cli_${VERSION}-1_amd64.deb
          
          # Optional: Run lintian to check for issues (warnings are ok)
          lintian mal-cli_${VERSION}-1_amd64.deb || true

      - name: Test Debian package
        run: |
          VERSION="${{ steps.version.outputs.VERSION }}"
          
          # Test installation (dry-run)
          sudo dpkg --dry-run -i mal-cli_${VERSION}-1_amd64.deb
          
          # Actually install and test
          sudo dpkg -i mal-cli_${VERSION}-1_amd64.deb || true
          sudo apt-get install -f -y  # Fix any dependency issues
          
          # Test that the command works
          mal --version || echo "Note: mal command may require specific setup"
          
          # Remove the package
          sudo dpkg -r mal-cli || true

      - name: Upload Debian package to GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          files: mal-cli_${{ steps.version.outputs.VERSION }}-1_amd64.deb
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  
  publish-crate:
    name: Publish to crates.io
    runs-on: ubuntu-latest
    if: startsWith(github.ref, 'refs/tags/v')  # Only run on version tags
    needs: [build]
    steps:
    - uses: actions/checkout@v3
    - uses: actions-rs/toolchain@v1
      with:
          toolchain: stable
          override: true
    - uses: katyo/publish-crates@v2
      with:
          registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}