|
| 1 | +name: CLI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + types: [opened, synchronize, reopened] |
| 8 | + release: |
| 9 | + types: [published] |
| 10 | + |
| 11 | +jobs: |
| 12 | + build: |
| 13 | + name: Build Rust (${{ matrix.os }}) |
| 14 | + runs-on: ${{ matrix.os }} |
| 15 | + strategy: |
| 16 | + fail-fast: true |
| 17 | + matrix: |
| 18 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 19 | + include: |
| 20 | + - os: ubuntu-latest |
| 21 | + bin_src: rust/target/release/contentmd |
| 22 | + bin_dst: dist/contentmd-linux |
| 23 | + artifact: contentmd-linux |
| 24 | + - os: macos-latest |
| 25 | + bin_src: rust/target/release/contentmd |
| 26 | + bin_dst: dist/contentmd-macos |
| 27 | + artifact: contentmd-macos |
| 28 | + - os: windows-latest |
| 29 | + bin_src: rust/target/release/contentmd.exe |
| 30 | + bin_dst: dist/contentmd-windows.exe |
| 31 | + artifact: contentmd-windows |
| 32 | + |
| 33 | + steps: |
| 34 | + - name: Checkout |
| 35 | + uses: actions/checkout@v6 |
| 36 | + |
| 37 | + - name: Setup Rust |
| 38 | + uses: dtolnay/rust-toolchain@stable |
| 39 | + |
| 40 | + - name: Cache Rust dependencies |
| 41 | + uses: actions/cache@v5 |
| 42 | + with: |
| 43 | + path: | |
| 44 | + ~/.cargo/registry |
| 45 | + ~/.cargo/git |
| 46 | + rust/target |
| 47 | + key: ${{ runner.os }}-cargo-${{ hashFiles('rust/Cargo.lock') }} |
| 48 | + restore-keys: ${{ runner.os }}-cargo- |
| 49 | + |
| 50 | + - name: Set Cargo.toml version from release tag |
| 51 | + if: github.event_name == 'release' |
| 52 | + shell: bash |
| 53 | + run: | |
| 54 | + TAG="${{ github.event.release.tag_name }}" |
| 55 | + VERSION="${TAG#v}" |
| 56 | + VERSION="${VERSION%%-*}" |
| 57 | + if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 58 | + echo "Release tag '$TAG' does not yield a valid major.minor.patch version (got '$VERSION')" >&2 |
| 59 | + exit 1 |
| 60 | + fi |
| 61 | + echo "Setting Cargo.toml version to $VERSION" |
| 62 | + sed -i.bak -E "s/^version = \".*\"/version = \"$VERSION\"/" rust/Cargo.toml |
| 63 | + rm rust/Cargo.toml.bak |
| 64 | + grep '^version' rust/Cargo.toml |
| 65 | +
|
| 66 | + - name: Run Tests |
| 67 | + working-directory: rust |
| 68 | + run: cargo test |
| 69 | + |
| 70 | + - name: Build Binary |
| 71 | + working-directory: rust |
| 72 | + run: cargo build --release |
| 73 | + |
| 74 | + - name: Stage binary for upload |
| 75 | + shell: bash |
| 76 | + run: | |
| 77 | + mkdir -p dist |
| 78 | + cp ${{ matrix.bin_src }} ${{ matrix.bin_dst }} |
| 79 | +
|
| 80 | + - name: Upload binary artifact |
| 81 | + uses: actions/upload-artifact@v7 |
| 82 | + with: |
| 83 | + name: ${{ matrix.artifact }} |
| 84 | + path: ${{ matrix.bin_dst }} |
| 85 | + retention-days: 2 |
| 86 | + |
| 87 | + release: |
| 88 | + name: Attach binaries to release |
| 89 | + needs: build |
| 90 | + if: github.event_name == 'release' |
| 91 | + runs-on: ubuntu-latest |
| 92 | + permissions: |
| 93 | + contents: write |
| 94 | + steps: |
| 95 | + - name: Download all artifacts |
| 96 | + uses: actions/download-artifact@v8 |
| 97 | + with: |
| 98 | + path: dist |
| 99 | + merge-multiple: true |
| 100 | + |
| 101 | + - name: Upload binaries to release |
| 102 | + env: |
| 103 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 104 | + run: gh release upload "${{ github.event.release.tag_name }}" dist/* --clobber --repo "${{ github.repository }}" |
0 commit comments