|
| 1 | +name: Build release daemon |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: ["master"] |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 10 | + cancel-in-progress: true |
| 11 | + |
| 12 | +jobs: |
| 13 | + build: |
| 14 | + strategy: |
| 15 | + fail-fast: false |
| 16 | + matrix: |
| 17 | + include: |
| 18 | + - os: ubuntu-latest |
| 19 | + target: x86_64-unknown-linux-gnu |
| 20 | + suffix: linux-amd64 |
| 21 | + - os: ubuntu-latest |
| 22 | + target: aarch64-unknown-linux-gnu |
| 23 | + suffix: linux-arm64 |
| 24 | + use_cross: true |
| 25 | + - os: macos-latest |
| 26 | + target: x86_64-apple-darwin |
| 27 | + suffix: macos-amd64 |
| 28 | + - os: macos-latest |
| 29 | + target: aarch64-apple-darwin |
| 30 | + suffix: macos-arm64 |
| 31 | + - os: windows-latest |
| 32 | + target: x86_64-pc-windows-msvc |
| 33 | + suffix: windows-amd64 |
| 34 | + bin_ext: .exe |
| 35 | + |
| 36 | + runs-on: ${{ matrix.os }} |
| 37 | + |
| 38 | + steps: |
| 39 | + - uses: actions/checkout@v4 |
| 40 | + |
| 41 | + - name: Extract version |
| 42 | + id: meta |
| 43 | + shell: bash |
| 44 | + run: | |
| 45 | + VERSION=$(grep '^version' splitway-daemon/Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/') |
| 46 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 47 | +
|
| 48 | + - uses: dtolnay/rust-toolchain@stable |
| 49 | + with: |
| 50 | + targets: ${{ matrix.target }} |
| 51 | + |
| 52 | + - name: Install cross |
| 53 | + if: ${{ matrix.use_cross == true }} |
| 54 | + uses: taiki-e/install-action@v2 |
| 55 | + with: |
| 56 | + tool: cross |
| 57 | + |
| 58 | + - name: Build (cross) |
| 59 | + if: ${{ matrix.use_cross == true }} |
| 60 | + run: cross build --release -p splitway-daemon --target ${{ matrix.target }} |
| 61 | + |
| 62 | + - name: Build (cargo) |
| 63 | + if: ${{ matrix.use_cross != true }} |
| 64 | + run: cargo build --release -p splitway-daemon --target ${{ matrix.target }} |
| 65 | + |
| 66 | + - name: Rename binary |
| 67 | + shell: bash |
| 68 | + run: | |
| 69 | + src="target/${{ matrix.target }}/release/splitway-daemon${{ matrix.bin_ext }}" |
| 70 | + dst="splitway-daemon-${{ matrix.suffix }}${{ matrix.bin_ext }}" |
| 71 | + cp "$src" "$dst" |
| 72 | +
|
| 73 | + - uses: actions/upload-artifact@v4 |
| 74 | + with: |
| 75 | + name: splitway-daemon-${{ matrix.suffix }} |
| 76 | + path: splitway-daemon-${{ matrix.suffix }}${{ matrix.bin_ext }} |
| 77 | + |
| 78 | + release: |
| 79 | + needs: build |
| 80 | + runs-on: ubuntu-latest |
| 81 | + |
| 82 | + permissions: |
| 83 | + contents: write |
| 84 | + |
| 85 | + steps: |
| 86 | + - uses: actions/checkout@v4 |
| 87 | + |
| 88 | + - name: Extract version |
| 89 | + id: meta |
| 90 | + shell: bash |
| 91 | + run: | |
| 92 | + VERSION=$(grep '^version' splitway-daemon/Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/') |
| 93 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 94 | + echo "tag=v$VERSION" >> $GITHUB_OUTPUT |
| 95 | +
|
| 96 | + - uses: actions/download-artifact@v4 |
| 97 | + with: |
| 98 | + path: artifacts |
| 99 | + merge-multiple: true |
| 100 | + |
| 101 | + - name: Create release |
| 102 | + uses: softprops/action-gh-release@v2 |
| 103 | + with: |
| 104 | + tag_name: ${{ steps.meta.outputs.tag }} |
| 105 | + name: ${{ steps.meta.outputs.tag }} |
| 106 | + files: artifacts/* |
| 107 | + fail_on_unmatched_files: true |
| 108 | + |
| 109 | + bump-version: |
| 110 | + needs: release |
| 111 | + runs-on: ubuntu-latest |
| 112 | + |
| 113 | + permissions: |
| 114 | + contents: write |
| 115 | + |
| 116 | + steps: |
| 117 | + - uses: actions/checkout@v4 |
| 118 | + |
| 119 | + - name: Bump patch version in Cargo.toml files |
| 120 | + shell: bash |
| 121 | + run: | |
| 122 | + VERSION=$(grep '^version' splitway-daemon/Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/') |
| 123 | + MAJOR=$(echo "$VERSION" | cut -d. -f1) |
| 124 | + MINOR=$(echo "$VERSION" | cut -d. -f2) |
| 125 | + PATCH=$(echo "$VERSION" | cut -d. -f3) |
| 126 | + NEW_PATCH=$((PATCH + 1)) |
| 127 | + NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH" |
| 128 | + sed -i "s/^version = \"$VERSION\"/version = \"$NEW_VERSION\"/" splitway-daemon/Cargo.toml |
| 129 | + echo "Bumped $VERSION -> $NEW_VERSION" |
| 130 | +
|
| 131 | + - name: Commit and push version bump |
| 132 | + shell: bash |
| 133 | + run: | |
| 134 | + git config user.name "github-actions[bot]" |
| 135 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 136 | + git add splitway-daemon/Cargo.toml |
| 137 | + git commit -m "chore: bump version after release" |
| 138 | + git push |
0 commit comments