|
| 1 | +name: Continuous Delivery |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + type: choice |
| 8 | + required: true |
| 9 | + description: 'Version number to bump' |
| 10 | + options: |
| 11 | + - patch |
| 12 | + - minor |
| 13 | + - major |
| 14 | + pull_request: |
| 15 | + branches: |
| 16 | + - main |
| 17 | + types: |
| 18 | + - closed |
| 19 | + |
| 20 | +permissions: |
| 21 | + contents: write |
| 22 | + issues: write |
| 23 | + pull-requests: write |
| 24 | + |
| 25 | +jobs: |
| 26 | + publish-dry-run: |
| 27 | + name: "Runs cargo publish --dry-run" |
| 28 | + runs-on: ubuntu-latest |
| 29 | + steps: |
| 30 | + - name: Checkout |
| 31 | + uses: actions/checkout@v6 |
| 32 | + |
| 33 | + - name: Setup Rust |
| 34 | + uses: dtolnay/rust-toolchain@stable |
| 35 | + |
| 36 | + - name: Setup Rust Cache |
| 37 | + uses: Swatinem/rust-cache@v2 |
| 38 | + |
| 39 | + - name: Setup Cargo Binstall |
| 40 | + uses: cargo-bins/cargo-binstall@main |
| 41 | + |
| 42 | + - name: Install Rust Binaries |
| 43 | + run: cargo binstall -y --force cargo-tag |
| 44 | + |
| 45 | + - name: Build (debug) |
| 46 | + run: cargo b |
| 47 | + |
| 48 | + - name: publish crate |
| 49 | + run: | |
| 50 | + cargo package --list --allow-dirty |
| 51 | + cargo publish --dry-run --allow-dirty |
| 52 | +
|
| 53 | + build-binaries: |
| 54 | + name: Build binaries |
| 55 | + needs: publish-dry-run |
| 56 | + strategy: |
| 57 | + matrix: |
| 58 | + include: |
| 59 | + - name: linux-x64 |
| 60 | + os: ubuntu-latest |
| 61 | + target: x86_64-unknown-linux-gnu |
| 62 | + - name: linux-arm64 |
| 63 | + os: ubuntu-latest |
| 64 | + target: aarch64-unknown-linux-gnu |
| 65 | + - name: macos-x64 |
| 66 | + os: macos-latest |
| 67 | + target: x86_64-apple-darwin |
| 68 | + - name: macos-arm64 |
| 69 | + os: macos-latest |
| 70 | + target: aarch64-apple-darwin |
| 71 | + runs-on: ${{ matrix.os }} |
| 72 | + steps: |
| 73 | + - name: Checkout |
| 74 | + uses: actions/checkout@v6 |
| 75 | + |
| 76 | + - name: Setup Rust |
| 77 | + uses: dtolnay/rust-toolchain@stable |
| 78 | + with: |
| 79 | + targets: ${{ matrix.target }} |
| 80 | + |
| 81 | + - name: Setup Rust Cache |
| 82 | + uses: Swatinem/rust-cache@v2 |
| 83 | + |
| 84 | + - name: Install Linker for ARM64 Linux GNU |
| 85 | + if: ${{ matrix.target == 'aarch64-unknown-linux-gnu' }} |
| 86 | + run: | |
| 87 | + sudo apt-get update |
| 88 | + sudo apt-get install -y gcc-aarch64-linux-gnu |
| 89 | +
|
| 90 | + - name: Setup Cargo Binstall |
| 91 | + uses: cargo-bins/cargo-binstall@main |
| 92 | + |
| 93 | + - name: Install Rust Binaries |
| 94 | + run: cargo binstall -y --force cargo-tag |
| 95 | + |
| 96 | + - name: Retrieve Git Commit SHA |
| 97 | + run: echo "GIT_COMMIT_SHA7=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_ENV |
| 98 | + |
| 99 | + - name: Retrieve Version |
| 100 | + run: | |
| 101 | + git config --global user.name 'github-actions[bot]' |
| 102 | + git config --global user.email 'github-actions[bot]@users.noreply.github.com' |
| 103 | + if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then |
| 104 | + echo "CRATE_VERSION=$(cargo tag --no-tag --no-commit -p=v ${{ inputs.version }})" >> $GITHUB_ENV |
| 105 | + else |
| 106 | + echo "CRATE_VERSION=$(cargo tag --no-tag --no-commit -p=v prerelease pre.$GIT_COMMIT_SHA7)" >> $GITHUB_ENV |
| 107 | + fi |
| 108 | +
|
| 109 | + - name: Build binary |
| 110 | + run: cargo build --release --target ${{ matrix.target }} |
| 111 | + |
| 112 | + - name: Package binary |
| 113 | + run: | |
| 114 | + # Create binary name with version and target |
| 115 | + BINARY_NAME="mate-${{ env.CRATE_VERSION }}-${{ matrix.name }}" |
| 116 | +
|
| 117 | + # Copy and rename binary |
| 118 | + if [ "${{ matrix.os }}" == "ubuntu-latest" ] || [ "${{ matrix.os }}" == "macos-latest" ]; then |
| 119 | + cp target/${{ matrix.target }}/release/mate $BINARY_NAME |
| 120 | + fi |
| 121 | +
|
| 122 | + # Create tar.gz archive |
| 123 | + tar -czf $BINARY_NAME.tar.gz $BINARY_NAME |
| 124 | +
|
| 125 | + # Store artifact name for later use |
| 126 | + echo "ARTIFACT_NAME=$BINARY_NAME.tar.gz" >> $GITHUB_ENV |
| 127 | +
|
| 128 | + - name: Upload binary artifact |
| 129 | + uses: actions/upload-artifact@v4 |
| 130 | + with: |
| 131 | + name: ${{ env.ARTIFACT_NAME }} |
| 132 | + path: ${{ env.ARTIFACT_NAME }} |
| 133 | + |
| 134 | + release: |
| 135 | + name: Create Release |
| 136 | + needs: build-binaries |
| 137 | + runs-on: ubuntu-latest |
| 138 | + steps: |
| 139 | + - name: Checkout |
| 140 | + uses: actions/checkout@v6 |
| 141 | + |
| 142 | + - name: Setup Rust |
| 143 | + uses: dtolnay/rust-toolchain@stable |
| 144 | + with: |
| 145 | + targets: ${{ matrix.target }} |
| 146 | + |
| 147 | + - name: Setup Rust Cache |
| 148 | + uses: Swatinem/rust-cache@v2 |
| 149 | + |
| 150 | + - name: Setup Cargo Binstall |
| 151 | + uses: cargo-bins/cargo-binstall@main |
| 152 | + |
| 153 | + - name: Install Rust Binaries |
| 154 | + run: cargo binstall -y --force cargo-tag |
| 155 | + |
| 156 | + - name: Retrieve Git Commit SHA |
| 157 | + run: echo "GIT_COMMIT_SHA7=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_ENV |
| 158 | + |
| 159 | + - name: Commit Version Bump |
| 160 | + run: | |
| 161 | + git config --global user.name 'github-actions[bot]' |
| 162 | + git config --global user.email 'github-actions[bot]@users.noreply.github.com' |
| 163 | + if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then |
| 164 | + echo "CRATE_VERSION=$(cargo tag -p=v ${{ inputs.version }})" >> $GITHUB_ENV |
| 165 | + else |
| 166 | + echo "CRATE_VERSION=$(cargo tag -p=v prerelease pre.$GIT_COMMIT_SHA7)" >> $GITHUB_ENV |
| 167 | + fi |
| 168 | + git push origin main --follow-tags |
| 169 | +
|
| 170 | + - name: Download all artifacts |
| 171 | + uses: actions/download-artifact@v4 |
| 172 | + with: |
| 173 | + path: ./artifacts |
| 174 | + |
| 175 | + - name: Create Release with GitHub CLI |
| 176 | + env: |
| 177 | + GH_TOKEN: ${{ github.token }} |
| 178 | + run: | |
| 179 | + # Determine if this is a pre-release |
| 180 | + IS_PRERELEASE="" |
| 181 | + if [ "${{ github.event_name }}" != "workflow_dispatch" ]; then |
| 182 | + IS_PRERELEASE="--prerelease" |
| 183 | + fi |
| 184 | +
|
| 185 | + # Create the release |
| 186 | + gh release create "${{ env.CRATE_VERSION }}" \ |
| 187 | + --title "Release ${{ env.CRATE_VERSION }}" \ |
| 188 | + --generate-notes \ |
| 189 | + $IS_PRERELEASE |
| 190 | +
|
| 191 | + # Upload all binary artifacts |
| 192 | + for artifact_dir in ./artifacts/*/; do |
| 193 | + if [ -d "$artifact_dir" ]; then |
| 194 | + for file in "$artifact_dir"*.tar.gz; do |
| 195 | + if [ -f "$file" ]; then |
| 196 | + echo "Uploading $(basename "$file")" |
| 197 | + gh release upload "${{ env.CRATE_VERSION }}" "$file" |
| 198 | + fi |
| 199 | + done |
| 200 | + fi |
| 201 | + done |
0 commit comments