Skip to content

Merge pull request #125 from beNative/codex/fix-auto-update-release-f… #45

Merge pull request #125 from beNative/codex/fix-auto-update-release-f…

Merge pull request #125 from beNative/codex/fix-auto-update-release-f… #45

Workflow file for this run

name: Release
on:
push:
tags:
- 'v*'
permissions:
contents: write
jobs:
create_release:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build release notes
id: notes
run: |
awk '
/^## / {
if (found) exit
found = 1
}
found { print }
' VERSION_LOG.md > release-notes.md
if [ ! -s release-notes.md ]; then
echo "Failed to extract release notes" >&2
exit 1
fi
echo "Release notes:" >&2
cat release-notes.md >&2
- name: Create GitHub release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref_name }}
release_name: DocForge ${{ github.ref_name }}
body_path: release-notes.md
draft: false
prerelease: false
package:
needs: create_release
name: ${{ matrix.display-name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- display-name: macOS x64
os: macos-latest
script: package:mac:x64
arch: x64
npm-platform: darwin
cache-paths: |
~/Library/Caches/electron
~/Library/Caches/electron-builder
- display-name: Windows x64
os: windows-latest
script: package:win:x64
arch: x64
npm-platform: win32
cache-paths: |
~/AppData/Local/electron/Cache
~/AppData/Local/electron-builder/Cache
- display-name: Windows ia32
os: windows-latest
script: package:win:ia32
arch: ia32
npm-platform: win32
cache-paths: |
~/AppData/Local/electron/Cache
~/AppData/Local/electron-builder/Cache
- display-name: Linux x64
os: ubuntu-latest
script: package:linux:x64
arch: x64
npm-platform: linux
cache-paths: |
~/.cache/electron
~/.cache/electron-builder
- display-name: Linux armv7l
os: ubuntu-latest
script: package:linux:armv7l
arch: armv7l
npm-platform: linux
cache-paths: |
~/.cache/electron
~/.cache/electron-builder
- display-name: Linux arm64
os: ubuntu-latest
script: package:linux:arm64
arch: arm64
npm-platform: linux
cache-paths: |
~/.cache/electron
~/.cache/electron-builder
defaults:
run:
shell: bash
env:
NODE_OPTIONS: --max_old_space_size=4096
TAG_NAME: ${{ github.ref_name }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
cache-dependency-path: package-lock.json
- name: Cache Electron downloads
uses: actions/cache@v4
with:
path: ${{ matrix.cache-paths }}
key: ${{ runner.os }}-electron-${{ matrix.arch }}-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-electron-${{ matrix.arch }}-
${{ runner.os }}-electron-
- name: Install system dependencies (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends -y rpm libarchive-tools
if ! sudo apt-get install --no-install-recommends -y libfuse2; then
sudo apt-get install --no-install-recommends -y libfuse2t64
fi
- name: Install dependencies
run: npm ci
env:
npm_config_arch: ${{ matrix.arch }}
npm_config_target_arch: ${{ matrix.arch }}
npm_config_platform: ${{ matrix.npm-platform }}
- name: Prepare native modules
run: npm run postinstall --if-present
env:
npm_config_arch: ${{ matrix.arch }}
npm_config_target_arch: ${{ matrix.arch }}
npm_config_platform: ${{ matrix.npm-platform }}
- name: Package application
run: npm run ${{ matrix.script }}
env:
npm_config_arch: ${{ matrix.arch }}
npm_config_target_arch: ${{ matrix.arch }}
npm_config_platform: ${{ matrix.npm-platform }}
- name: Normalize Windows artifact names
if: runner.os == 'Windows'
env:
MATRIX_ARCH: ${{ matrix.arch }}
run: |
set -euo pipefail
arch="$MATRIX_ARCH"
shopt -s nullglob
exe_name=""
blockmap_name=""
for file in release/*.exe; do
dir=$(dirname "$file")
base=$(basename "$file")
ext="${base##*.}"
stem="${base%.$ext}"
if [[ "$arch" != "x64" ]]; then
renamed="$dir/${stem}-${arch}.${ext}"
mv "$file" "$renamed"
file="$renamed"
fi
exe_name=$(basename "$file")
original_blockmap="$dir/${stem}.${ext}.blockmap"
if [[ -f "$original_blockmap" ]]; then
target_blockmap="$dir/${exe_name}.blockmap"
if [[ "$original_blockmap" != "$target_blockmap" ]]; then
mv "$original_blockmap" "$target_blockmap"
fi
blockmap_name=$(basename "$target_blockmap")
fi
done
latest_file=""
if [[ -f release/latest.yml ]]; then
if [[ "$arch" != "x64" ]]; then
latest_file="release/latest-${arch}.yml"
mv release/latest.yml "$latest_file"
else
latest_file="release/latest.yml"
fi
fi
if [[ -n "$exe_name" && -n "$latest_file" ]]; then
export WINDOWS_EXE_NAME="$exe_name"
export WINDOWS_BLOCKMAP_NAME="$blockmap_name"
export WINDOWS_LATEST_FILE="$latest_file"
python - <<'PY'
import os

Check failure on line 214 in .github/workflows/release.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/release.yml

Invalid workflow file

You have an error in your yaml syntax on line 214
import re
from pathlib import Path
from urllib.parse import quote
latest = Path(os.environ["WINDOWS_LATEST_FILE"])
exe_name = os.environ["WINDOWS_EXE_NAME"]
blockmap_name = os.environ.get("WINDOWS_BLOCKMAP_NAME") or ""
def replace_line(line: str, needle: str, replacement: str) -> str:
prefix, _, _ = line.partition(needle)
return f"{prefix}{needle}{replacement}\n"
lines = latest.read_text(encoding="utf-8").splitlines(keepends=True)
updated = []
for line in lines:
stripped = line.strip()
if stripped.startswith("path:") and ".exe" in stripped:
updated.append(replace_line(line, "path:", f" {exe_name}"))
continue
if stripped.startswith("url:") and ".exe" in stripped:
value = stripped.split(None, 1)[1] if len(stripped.split(None, 1)) == 2 else ""
if value.endswith(".exe.blockmap") and blockmap_name:
updated.append(replace_line(line, "url:", f" {quote(blockmap_name)}"))
continue
if value.endswith(".exe"):
updated.append(replace_line(line, "url:", f" {quote(exe_name)}"))
continue
updated.append(line)
latest.write_text("".join(updated), encoding="utf-8")
PY
fi
- name: Upload release assets
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
shopt -s nullglob
files=()
while IFS= read -r -d '' file; do
case "$file" in
*.blockmap) continue ;;
esac
files+=("$file")
done < <(find release -type f -print0)
if [ ${#files[@]} -eq 0 ]; then
echo "No release files found" >&2
exit 1
fi
for file in "${files[@]}"; do
echo "Uploading $(basename "$file")"
gh release upload "$TAG_NAME" "$file" --clobber
done
- name: Upload build logs on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.display-name }}-logs
path: |
npm-debug.log
*.log
release/**/*.log
if-no-files-found: ignore
retention-days: 7