|
| 1 | +name: Manually Triggered Desktop Release |
| 2 | + |
| 3 | +permissions: |
| 4 | + contents: write |
| 5 | + actions: read |
| 6 | + |
| 7 | +concurrency: |
| 8 | + group: desktop-release-${{ github.ref }} |
| 9 | + cancel-in-progress: true |
| 10 | + |
| 11 | +on: |
| 12 | + workflow_dispatch: |
| 13 | + inputs: |
| 14 | + version-bump: |
| 15 | + description: 'The type of version bump (major, minor, or patch)' |
| 16 | + required: true |
| 17 | + default: 'patch' |
| 18 | + type: choice |
| 19 | + options: |
| 20 | + - patch |
| 21 | + - minor |
| 22 | + - major |
| 23 | + |
| 24 | +jobs: |
| 25 | + version: |
| 26 | + runs-on: ubuntu-latest |
| 27 | + outputs: |
| 28 | + new_version: ${{ steps.bump.outputs.new_version }} |
| 29 | + steps: |
| 30 | + - name: Checkout repository |
| 31 | + uses: actions/checkout@v4 |
| 32 | + with: |
| 33 | + fetch-depth: 0 |
| 34 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 35 | + |
| 36 | + - name: Configure Git |
| 37 | + run: | |
| 38 | + git config user.name "github-actions[bot]" |
| 39 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 40 | +
|
| 41 | + - name: Compute New Version |
| 42 | + id: bump |
| 43 | + run: | |
| 44 | + set -euo pipefail |
| 45 | +
|
| 46 | + # Fetch the latest tag from the repository |
| 47 | + LATEST_TAG=$(git tag --sort=-v:refname | head -n 1) |
| 48 | + if [[ -z "$LATEST_TAG" ]]; then |
| 49 | + LATEST_TAG="v0.0.0" |
| 50 | + fi |
| 51 | +
|
| 52 | + # Parse the latest tag to get major, minor, and patch numbers |
| 53 | + if [[ "$LATEST_TAG" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then |
| 54 | + MAJOR=${BASH_REMATCH[1]} |
| 55 | + MINOR=${BASH_REMATCH[2]} |
| 56 | + PATCH=${BASH_REMATCH[3]} |
| 57 | + else |
| 58 | + echo "Could not parse latest tag: $LATEST_TAG. Starting from v0.1.0." |
| 59 | + MAJOR=0; MINOR=1; PATCH=0 |
| 60 | + fi |
| 61 | +
|
| 62 | + # Increment the version based on the manual input |
| 63 | + BUMP_TYPE="${{ github.event.inputs.version-bump }}" |
| 64 | + if [ "$BUMP_TYPE" == "major" ]; then |
| 65 | + MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 |
| 66 | + elif [ "$BUMP_TYPE" == "minor" ]; then |
| 67 | + MINOR=$((MINOR + 1)); PATCH=0 |
| 68 | + else |
| 69 | + PATCH=$((PATCH + 1)) |
| 70 | + fi |
| 71 | +
|
| 72 | + NEW_VERSION="v$MAJOR.$MINOR.$PATCH" |
| 73 | + VERSION_NO_V="$MAJOR.$MINOR.$PATCH" |
| 74 | +
|
| 75 | + echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT" |
| 76 | + echo "version_no_v=$VERSION_NO_V" >> "$GITHUB_OUTPUT" |
| 77 | + echo "New version will be: $NEW_VERSION" |
| 78 | +
|
| 79 | + - name: Update Version Files |
| 80 | + run: | |
| 81 | + VERSION_NO_V="${{ steps.bump.outputs.version_no_v }}" |
| 82 | +
|
| 83 | + # Update package.json |
| 84 | + jq --arg ver "$VERSION_NO_V" '.version = $ver' package.json > package.json.tmp |
| 85 | + mv package.json.tmp package.json |
| 86 | +
|
| 87 | + # Update src-tauri/tauri.conf.json |
| 88 | + jq --arg ver "$VERSION_NO_V" '.version = $ver' src-tauri/tauri.conf.json > src-tauri/tauri.conf.json.tmp |
| 89 | + mv src-tauri/tauri.conf.json.tmp src-tauri/tauri.conf.json |
| 90 | +
|
| 91 | + # Update src-tauri/Cargo.toml |
| 92 | + sed -i "s/^version = \".*\"/version = \"$VERSION_NO_V\"/" src-tauri/Cargo.toml |
| 93 | +
|
| 94 | + echo "Updated version files to $VERSION_NO_V" |
| 95 | +
|
| 96 | + - name: Commit Version Bump |
| 97 | + run: | |
| 98 | + NEW_VERSION="${{ steps.bump.outputs.new_version }}" |
| 99 | +
|
| 100 | + git add package.json src-tauri/tauri.conf.json src-tauri/Cargo.toml |
| 101 | + git commit -m "chore: bump version to $NEW_VERSION" |
| 102 | + git tag "$NEW_VERSION" |
| 103 | + git push origin HEAD:${{ github.ref_name }} |
| 104 | + git push origin "$NEW_VERSION" |
| 105 | +
|
| 106 | + build-tauri: |
| 107 | + runs-on: ${{ matrix.os }} |
| 108 | + needs: version |
| 109 | + strategy: |
| 110 | + fail-fast: false |
| 111 | + matrix: |
| 112 | + os: [ubuntu-latest, windows-2022, macos-latest] |
| 113 | + |
| 114 | + steps: |
| 115 | + - name: Checkout repository |
| 116 | + uses: actions/checkout@v4 |
| 117 | + with: |
| 118 | + ref: ${{ github.ref_name }} |
| 119 | + |
| 120 | + - name: Setup Node.js |
| 121 | + uses: actions/setup-node@v4 |
| 122 | + with: |
| 123 | + node-version: 18 |
| 124 | + |
| 125 | + - name: Cache Node.js Dependencies |
| 126 | + uses: actions/cache@v4 |
| 127 | + with: |
| 128 | + path: ~/.npm |
| 129 | + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} |
| 130 | + restore-keys: ${{ runner.os }}-node- |
| 131 | + |
| 132 | + - name: Install Dependencies |
| 133 | + run: npm ci |
| 134 | + shell: bash |
| 135 | + |
| 136 | + - name: Setup Rust (stable) |
| 137 | + uses: dtolnay/rust-toolchain@stable |
| 138 | + |
| 139 | + - name: Install Linux Dependencies (Ubuntu) |
| 140 | + if: matrix.os == 'ubuntu-latest' |
| 141 | + run: | |
| 142 | + sudo apt update |
| 143 | + sudo apt install libwebkit2gtk-4.1-dev \ |
| 144 | + build-essential \ |
| 145 | + curl \ |
| 146 | + wget \ |
| 147 | + file \ |
| 148 | + libxdo-dev \ |
| 149 | + libssl-dev \ |
| 150 | + libayatana-appindicator3-dev \ |
| 151 | + librsvg2-dev |
| 152 | + shell: bash |
| 153 | + |
| 154 | + - name: Install macOS Dependencies |
| 155 | + if: matrix.os == 'macos-latest' |
| 156 | + run: | |
| 157 | + brew update |
| 158 | + brew install pkg-config |
| 159 | + shell: bash |
| 160 | + |
| 161 | + - name: Install Windows Dependencies |
| 162 | + if: matrix.os == 'windows-2022' |
| 163 | + shell: powershell |
| 164 | + run: | |
| 165 | + choco install -y wixtoolset nsis webview2-runtime |
| 166 | +
|
| 167 | + - name: Cache Rust Dependencies |
| 168 | + uses: Swatinem/rust-cache@v2 |
| 169 | + with: |
| 170 | + workspaces: './src-tauri' |
| 171 | + |
| 172 | + - name: Build Tauri App |
| 173 | + run: npm run tauri build |
| 174 | + shell: bash |
| 175 | + |
| 176 | + - name: Upload Tauri Build Artifacts |
| 177 | + uses: actions/upload-artifact@v4 |
| 178 | + with: |
| 179 | + name: Tauri Build Artifacts (${{ matrix.os }}) |
| 180 | + path: | |
| 181 | + src-tauri/target/release/bundle |
| 182 | +
|
| 183 | + create-release: |
| 184 | + runs-on: ubuntu-latest |
| 185 | + needs: [version, build-tauri] |
| 186 | + steps: |
| 187 | + - name: Checkout repository |
| 188 | + uses: actions/checkout@v4 |
| 189 | + with: |
| 190 | + fetch-depth: 0 |
| 191 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 192 | + ref: ${{ github.ref_name }} |
| 193 | + |
| 194 | + - name: Configure Git |
| 195 | + run: | |
| 196 | + git config user.name "github-actions[bot]" |
| 197 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 198 | +
|
| 199 | + - name: Generate Changelog |
| 200 | + id: changelog |
| 201 | + uses: TriPSs/conventional-changelog-action@v3 |
| 202 | + with: |
| 203 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 204 | + skip-on-empty: 'false' |
| 205 | + skip-commit: 'true' |
| 206 | + skip-version-file: 'true' |
| 207 | + skip-git-pull: 'true' |
| 208 | + git-push: 'false' |
| 209 | + output-file: 'false' |
| 210 | + release-count: 0 |
| 211 | + |
| 212 | + - name: Update Repository Changelog |
| 213 | + run: | |
| 214 | + set -euo pipefail |
| 215 | + CHANGELOG_FILE="CHANGELOG.md" |
| 216 | + TEMP_CHANGELOG="$(mktemp)" |
| 217 | +
|
| 218 | + cat <<'EOF' > "$TEMP_CHANGELOG" |
| 219 | + ${{ steps.changelog.outputs.changelog }} |
| 220 | + EOF |
| 221 | +
|
| 222 | + if [ -f "$CHANGELOG_FILE" ]; then |
| 223 | + printf "\n" >> "$TEMP_CHANGELOG" |
| 224 | + cat "$CHANGELOG_FILE" >> "$TEMP_CHANGELOG" |
| 225 | + fi |
| 226 | +
|
| 227 | + mv "$TEMP_CHANGELOG" "$CHANGELOG_FILE" |
| 228 | +
|
| 229 | + - name: Commit and Push Changelog |
| 230 | + env: |
| 231 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 232 | + run: | |
| 233 | + set -euo pipefail |
| 234 | + if git diff --quiet -- CHANGELOG.md; then |
| 235 | + echo "No changelog updates to commit." |
| 236 | + exit 0 |
| 237 | + fi |
| 238 | +
|
| 239 | + git add CHANGELOG.md |
| 240 | + git commit -m "chore: update changelog for ${{ needs.version.outputs.new_version }}" |
| 241 | + git push origin HEAD:${{ github.ref_name }} |
| 242 | +
|
| 243 | + - name: Download all build artifacts |
| 244 | + uses: actions/download-artifact@v4 |
| 245 | + with: |
| 246 | + path: artifacts |
| 247 | + |
| 248 | + - name: Prepare Release Assets |
| 249 | + run: | |
| 250 | + mkdir -p release-assets |
| 251 | + find artifacts -type f \( -name "*.deb" -o -name "*.AppImage" -o -name "*.msi" -o -name "*.dmg" \) -exec cp {} release-assets/ \; || true |
| 252 | +
|
| 253 | + if [ -d "artifacts/Tauri Build Artifacts (macos-latest)/src-tauri/target/release/bundle/macos" ]; then |
| 254 | + MACOS_BUNDLE_DIR="artifacts/Tauri Build Artifacts (macos-latest)/src-tauri/target/release/bundle/macos" |
| 255 | + cd "$MACOS_BUNDLE_DIR" |
| 256 | + shopt -s nullglob |
| 257 | + apps=( *.app ) |
| 258 | + if [ ${#apps[@]} -gt 0 ]; then |
| 259 | + for app in "${apps[@]}"; do |
| 260 | + zip -r "$GITHUB_WORKSPACE/release-assets/${app%.app}.zip" "$app" |
| 261 | + done |
| 262 | + fi |
| 263 | + cd - |
| 264 | + fi |
| 265 | +
|
| 266 | + echo "Prepared release assets:" |
| 267 | + ls -l release-assets/ |
| 268 | +
|
| 269 | + - name: Install GitHub CLI |
| 270 | + run: | |
| 271 | + type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y) |
| 272 | + curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \ |
| 273 | + && sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \ |
| 274 | + && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \ |
| 275 | + && sudo apt update \ |
| 276 | + && sudo apt install gh -y |
| 277 | +
|
| 278 | + - name: Create GitHub Release |
| 279 | + env: |
| 280 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 281 | + run: | |
| 282 | + set -euo pipefail |
| 283 | +
|
| 284 | + NEW_VERSION="${{ needs.version.outputs.new_version }}" |
| 285 | + echo "Creating release: $NEW_VERSION" |
| 286 | +
|
| 287 | + CHANGELOG_NOTES_FILE="RELEASE_NOTES.md" |
| 288 | + echo '${{ steps.changelog.outputs.changelog }}' > "$CHANGELOG_NOTES_FILE" |
| 289 | +
|
| 290 | + gh release create "$NEW_VERSION" \ |
| 291 | + --title "CircuitVerse Desktop $NEW_VERSION" \ |
| 292 | + --notes-file "$CHANGELOG_NOTES_FILE" \ |
| 293 | + release-assets/* |
0 commit comments