|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + create_release: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Check out repository |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + |
| 20 | + - name: Build release notes |
| 21 | + id: notes |
| 22 | + run: | |
| 23 | + awk ' |
| 24 | + /^## / { |
| 25 | + if (found) exit |
| 26 | + found = 1 |
| 27 | + } |
| 28 | + found { print } |
| 29 | + ' VERSION_LOG.md > release-notes.md |
| 30 | + if [ ! -s release-notes.md ]; then |
| 31 | + echo "Failed to extract release notes" >&2 |
| 32 | + exit 1 |
| 33 | + fi |
| 34 | + echo "Release notes:" >&2 |
| 35 | + cat release-notes.md >&2 |
| 36 | +
|
| 37 | + - name: Create GitHub release |
| 38 | + id: create_release |
| 39 | + uses: actions/create-release@v1 |
| 40 | + env: |
| 41 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 42 | + with: |
| 43 | + tag_name: ${{ github.ref_name }} |
| 44 | + release_name: DocForge ${{ github.ref_name }} |
| 45 | + body_path: release-notes.md |
| 46 | + draft: false |
| 47 | + prerelease: false |
| 48 | + |
| 49 | + package: |
| 50 | + needs: create_release |
| 51 | + name: ${{ matrix.display-name }} |
| 52 | + runs-on: ${{ matrix.os }} |
| 53 | + strategy: |
| 54 | + fail-fast: false |
| 55 | + matrix: |
| 56 | + include: |
| 57 | + - display-name: macOS x64 |
| 58 | + os: macos-latest |
| 59 | + script: package:mac:x64 |
| 60 | + arch: x64 |
| 61 | + npm-platform: darwin |
| 62 | + cache-paths: | |
| 63 | + ~/Library/Caches/electron |
| 64 | + ~/Library/Caches/electron-builder |
| 65 | + - display-name: Windows x64 |
| 66 | + os: windows-latest |
| 67 | + script: package:win:x64 |
| 68 | + arch: x64 |
| 69 | + npm-platform: win32 |
| 70 | + cache-paths: | |
| 71 | + ~/AppData/Local/electron/Cache |
| 72 | + ~/AppData/Local/electron-builder/Cache |
| 73 | + - display-name: Windows ia32 |
| 74 | + os: windows-latest |
| 75 | + script: package:win:ia32 |
| 76 | + arch: ia32 |
| 77 | + npm-platform: win32 |
| 78 | + cache-paths: | |
| 79 | + ~/AppData/Local/electron/Cache |
| 80 | + ~/AppData/Local/electron-builder/Cache |
| 81 | + - display-name: Linux x64 |
| 82 | + os: ubuntu-latest |
| 83 | + script: package:linux:x64 |
| 84 | + arch: x64 |
| 85 | + npm-platform: linux |
| 86 | + cache-paths: | |
| 87 | + ~/.cache/electron |
| 88 | + ~/.cache/electron-builder |
| 89 | + - display-name: Linux armv7l |
| 90 | + os: ubuntu-latest |
| 91 | + script: package:linux:armv7l |
| 92 | + arch: armv7l |
| 93 | + npm-platform: linux |
| 94 | + cache-paths: | |
| 95 | + ~/.cache/electron |
| 96 | + ~/.cache/electron-builder |
| 97 | + - display-name: Linux arm64 |
| 98 | + os: ubuntu-latest |
| 99 | + script: package:linux:arm64 |
| 100 | + arch: arm64 |
| 101 | + npm-platform: linux |
| 102 | + cache-paths: | |
| 103 | + ~/.cache/electron |
| 104 | + ~/.cache/electron-builder |
| 105 | + defaults: |
| 106 | + run: |
| 107 | + shell: bash |
| 108 | + env: |
| 109 | + NODE_OPTIONS: --max_old_space_size=4096 |
| 110 | + TAG_NAME: ${{ github.ref_name }} |
| 111 | + steps: |
| 112 | + - name: Checkout repository |
| 113 | + uses: actions/checkout@v4 |
| 114 | + with: |
| 115 | + fetch-depth: 0 |
| 116 | + |
| 117 | + - name: Setup Node.js |
| 118 | + uses: actions/setup-node@v4 |
| 119 | + with: |
| 120 | + node-version: 20 |
| 121 | + cache: npm |
| 122 | + cache-dependency-path: package-lock.json |
| 123 | + |
| 124 | + - name: Cache Electron downloads |
| 125 | + uses: actions/cache@v4 |
| 126 | + with: |
| 127 | + path: ${{ matrix.cache-paths }} |
| 128 | + key: ${{ runner.os }}-electron-${{ matrix.arch }}-${{ hashFiles('package-lock.json') }} |
| 129 | + restore-keys: | |
| 130 | + ${{ runner.os }}-electron-${{ matrix.arch }}- |
| 131 | + ${{ runner.os }}-electron- |
| 132 | +
|
| 133 | + - name: Install system dependencies (Linux) |
| 134 | + if: runner.os == 'Linux' |
| 135 | + run: | |
| 136 | + sudo apt-get update |
| 137 | + sudo apt-get install --no-install-recommends -y rpm libarchive-tools |
| 138 | + if ! sudo apt-get install --no-install-recommends -y libfuse2; then |
| 139 | + sudo apt-get install --no-install-recommends -y libfuse2t64 |
| 140 | + fi |
| 141 | +
|
| 142 | + - name: Install dependencies |
| 143 | + run: npm ci |
| 144 | + env: |
| 145 | + npm_config_arch: ${{ matrix.arch }} |
| 146 | + npm_config_target_arch: ${{ matrix.arch }} |
| 147 | + npm_config_platform: ${{ matrix.npm-platform }} |
| 148 | + |
| 149 | + - name: Prepare native modules |
| 150 | + run: npm run postinstall --if-present |
| 151 | + env: |
| 152 | + npm_config_arch: ${{ matrix.arch }} |
| 153 | + npm_config_target_arch: ${{ matrix.arch }} |
| 154 | + npm_config_platform: ${{ matrix.npm-platform }} |
| 155 | + |
| 156 | + - name: Package application |
| 157 | + run: npm run ${{ matrix.script }} |
| 158 | + env: |
| 159 | + npm_config_arch: ${{ matrix.arch }} |
| 160 | + npm_config_target_arch: ${{ matrix.arch }} |
| 161 | + npm_config_platform: ${{ matrix.npm-platform }} |
| 162 | + |
| 163 | + - name: Upload release assets |
| 164 | + env: |
| 165 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 166 | + run: | |
| 167 | + shopt -s nullglob |
| 168 | + files=() |
| 169 | + while IFS= read -r -d '' file; do |
| 170 | + case "$file" in |
| 171 | + *.blockmap) continue ;; |
| 172 | + esac |
| 173 | + files+=("$file") |
| 174 | + done < <(find release -type f -print0) |
| 175 | +
|
| 176 | + if [ ${#files[@]} -eq 0 ]; then |
| 177 | + echo "No release files found" >&2 |
| 178 | + exit 1 |
| 179 | + fi |
| 180 | +
|
| 181 | + for file in "${files[@]}"; do |
| 182 | + echo "Uploading $(basename "$file")" |
| 183 | + gh release upload "$TAG_NAME" "$file" --clobber |
| 184 | + done |
| 185 | +
|
| 186 | + - name: Upload build logs on failure |
| 187 | + if: failure() |
| 188 | + uses: actions/upload-artifact@v4 |
| 189 | + with: |
| 190 | + name: ${{ matrix.display-name }}-logs |
| 191 | + path: | |
| 192 | + npm-debug.log |
| 193 | + *.log |
| 194 | + release/**/*.log |
| 195 | + if-no-files-found: ignore |
| 196 | + retention-days: 7 |
0 commit comments