|
| 1 | +name: Release to Github |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: # Allows manual triggering of the workflow |
| 5 | + inputs: |
| 6 | + type: |
| 7 | + description: 'Type of release (major/minor/patch)' |
| 8 | + required: true |
| 9 | + default: 'minor' |
| 10 | + dry_run: |
| 11 | + description: 'Dry run (true/false)' # Allows a test run without making actual changes |
| 12 | + required: true |
| 13 | + default: true |
| 14 | + # skip_tests: |
| 15 | + # description: 'Skip tests (true/false)' # Allows skipping tests if needed |
| 16 | + # required: true |
| 17 | + # default: false |
| 18 | + |
| 19 | +env: |
| 20 | + CARGO_TERM_COLOR: always # Ensures cargo outputs colored logs |
| 21 | + |
| 22 | +jobs: |
| 23 | + build: |
| 24 | + strategy: |
| 25 | + matrix: |
| 26 | + platform: |
| 27 | + - os: ubuntu-latest |
| 28 | + linux-override: false |
| 29 | + - os: macos-13 |
| 30 | + linux-override: false |
| 31 | + - os: macos-14 |
| 32 | + linux-override: false |
| 33 | + - os: windows-latest |
| 34 | + linux-override: false |
| 35 | + - os: ubuntu-latest # Extra Ubuntu build for ARM support |
| 36 | + linux-override: true |
| 37 | + runs-on: ${{ matrix.platform.os }} |
| 38 | + steps: |
| 39 | + - name: Checkout source code |
| 40 | + uses: actions/checkout@v3 # Fetches the repository |
| 41 | + |
| 42 | + - name: Ensure Cargo Directories Exist for Cache Restore |
| 43 | + run: | |
| 44 | + mkdir -p ~/.cargo/registry ~/.cargo/index target |
| 45 | + shell: bash # Prevents cache failures due to missing directories |
| 46 | + |
| 47 | + - name: Cache Cargo Registry, Index, Build |
| 48 | + uses: actions/cache@v3 |
| 49 | + with: |
| 50 | + path: | |
| 51 | + ~/.cargo/registry |
| 52 | + ~/.cargo/index |
| 53 | + target |
| 54 | + key: ${{ runner.os }}-${{ runner.arch }}-cargo-${{ hashFiles('**/Cargo.toml') }} |
| 55 | + restore-keys: | |
| 56 | + cargo-build-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/Cargo.toml') }} |
| 57 | + cargo-build-${{ runner.os }}-${{ runner.arch }}- |
| 58 | +
|
| 59 | + - name: Set up Rust |
| 60 | + uses: actions-rs/toolchain@v1 |
| 61 | + with: |
| 62 | + toolchain: stable # Installs stable Rust toolchain |
| 63 | + |
| 64 | + - name: Build project |
| 65 | + run: cargo build --verbose # Builds the Rust project |
| 66 | + |
| 67 | + prepare-release: |
| 68 | + needs: [build] # Runs only after build job completes |
| 69 | + runs-on: ubuntu-latest # Ensures consistent release process |
| 70 | + outputs: |
| 71 | + rr_cargo_version: ${{ steps.get-version.outputs.VERSION }} |
| 72 | + workflow_git_tag: ${{ steps.get-version.outputs.WORKFLOW_GIT_TAG }} |
| 73 | + steps: |
| 74 | + - name: Checkout repository with full history |
| 75 | + uses: actions/checkout@v3 |
| 76 | + with: |
| 77 | + fetch-depth: 0 # Required for versioning |
| 78 | + token: ${{ secrets.RELEASE_TOKEN }} # Uses a token with release permissions |
| 79 | + |
| 80 | + - name: Install Rust Target for Linux Arm if needed |
| 81 | + shell: bash |
| 82 | + run: | |
| 83 | + if [ "${{ matrix.platform.linux-override }}" = "true" ]; then |
| 84 | + rustup target add aarch64-unknown-linux-gnu |
| 85 | + fi |
| 86 | +
|
| 87 | + - name: Cache Cargo dependencies |
| 88 | + uses: actions/cache@v3 |
| 89 | + with: |
| 90 | + path: | |
| 91 | + ~/.cargo/registry |
| 92 | + ~/.cargo/index |
| 93 | + target |
| 94 | + key: ${{ runner.os }}-${{ runner.arch }}-cargo-${{ hashFiles('**/Cargo.toml') }} |
| 95 | + |
| 96 | + - name: Install cargo-release |
| 97 | + run: | |
| 98 | + if ! command -v cargo-release &> /dev/null; then |
| 99 | + cargo install cargo-release |
| 100 | + fi |
| 101 | +
|
| 102 | + - name: Configure Git |
| 103 | + run: | |
| 104 | + git config --global user.name "GitHub Action" |
| 105 | + git config --global user.email "[email protected]" |
| 106 | +
|
| 107 | + - name: Update Cargo.toml version and push to GitHub |
| 108 | + run: | |
| 109 | + if [ "${{ github.event.inputs.dry_run }}" = "false" ]; then |
| 110 | + cargo release --verbose --execute --no-confirm ${{ github.event.inputs.type }} --no-publish --no-verify |
| 111 | + else |
| 112 | + cargo release --verbose ${{ github.event.inputs.type }} --no-publish --no-verify |
| 113 | + fi |
| 114 | +
|
| 115 | + - name: Extract Version from Cargo.toml |
| 116 | + id: get-version |
| 117 | + run: | |
| 118 | + VERSION=$(grep '^version = ' Cargo.toml | sed -E 's/version = "(.*)"/\1/') |
| 119 | + echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT" |
| 120 | + echo "WORKFLOW_GIT_TAG=v$VERSION" >> "$GITHUB_OUTPUT" |
| 121 | +
|
| 122 | + release: |
| 123 | + needs: [prepare-release] |
| 124 | + if: ${{ github.event.inputs.dry_run == 'false' }} # Only run if not a dry run |
| 125 | + strategy: |
| 126 | + matrix: |
| 127 | + platform: |
| 128 | + - os: ubuntu-latest |
| 129 | + linux-override: false |
| 130 | + - os: macos-13 |
| 131 | + linux-override: false |
| 132 | + - os: macos-14 |
| 133 | + linux-override: false |
| 134 | + - os: windows-latest |
| 135 | + linux-override: false |
| 136 | + - os: ubuntu-latest |
| 137 | + linux-override: true |
| 138 | + runs-on: ${{ matrix.platform.os }} |
| 139 | + steps: |
| 140 | + - name: Checkout repository |
| 141 | + uses: actions/checkout@v3 |
| 142 | + |
| 143 | + - name: Build release binary |
| 144 | + run: | |
| 145 | + if [[ "${{ matrix.platform.linux-override }}" == "true" ]]; then |
| 146 | + rustup target add aarch64-unknown-linux-gnu |
| 147 | + cargo build -p c-wrapper --release --target aarch64-unknown-linux-gnu --verbose |
| 148 | + else |
| 149 | + cargo build -p c-wrapper --release --verbose |
| 150 | + fi |
| 151 | +
|
| 152 | + - name: Archive binary |
| 153 | + uses: ksm2/archive-action@v1 |
| 154 | + with: |
| 155 | + name: "surrealml-${{ needs.prepare-release.outputs.rr_cargo_version }}" |
| 156 | + format: "tar.gz" |
| 157 | + include: "{libc_wrapper.so, libc_wrapper.dll,libc_wrapper.dylib,README.md}" |
| 158 | + |
| 159 | + - name: Create GitHub Release |
| 160 | + uses: ncipollo/release-action@v1 |
| 161 | + with: |
| 162 | + artifacts: "surrealml-${{ needs.prepare-release.outputs.rr_cargo_version }}.tar.gz" |
| 163 | + allowUpdates: true |
| 164 | + generateReleaseNotes: true |
| 165 | + token: ${{ secrets.RELEASE_TOKEN }} |
| 166 | + tag: ${{ needs.prepare-release.outputs.workflow_git_tag }} |
0 commit comments