diff --git a/.github/scripts/nightly-pick.sh b/.github/scripts/nightly-pick.sh new file mode 100755 index 0000000..82d5c1f --- /dev/null +++ b/.github/scripts/nightly-pick.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash +# nightly-pick.sh WORKFLOW... +# +# Finds the newest commit on main that has a completed run of each +# WORKFLOW (a file name in .github/workflows). It writes these lines to +# $GITHUB_OUTPUT: +# +# sha= +# run_= (for each WORKFLOW, "." and "-" as "_") +# skip=true|false (true: the nightly release has this commit) +# +# A run that is not complete is not used. Thus a run that is in progress +# does not stop the nightly release: the release uses the run before it. +# Set FORCE=true to publish again when the commit did not change. +# +# It needs GH_TOKEN and GH_REPO. +set -euo pipefail + +[ $# -ge 1 ] || { echo "usage: $0 WORKFLOW..." >&2; exit 2; } +out=${GITHUB_OUTPUT:-/dev/stdout} + +# the completed runs of a workflow on main (pushes and manual runs), newest first: "sha id" +runs() { + gh run list --workflow "$1" --branch main --status completed --limit 50 \ + --json headSha,databaseId,event \ + --jq '.[] | select(.event == "push" or .event == "workflow_dispatch") | "\(.headSha) \(.databaseId)"' +} + +declare -A list +for w in "$@"; do + list[$w]=$(runs "$w") +done + +sha= +while read -r s _; do + [ -n "$s" ] || continue + ok=1 + for w in "$@"; do + grep -q "^$s " <<<"${list[$w]}" || { ok=0; break; } + done + if [ "$ok" = 1 ]; then sha=$s; break; fi +done <<<"${list[$1]}" + +if [ -z "$sha" ]; then + echo "::error::No commit on main has a completed run of each of: $*" + exit 1 +fi + +echo "sha=$sha" >> "$out" +for w in "$@"; do + id=$(grep -m1 "^$sha " <<<"${list[$w]}" | cut -d' ' -f2) + echo "run_$(tr '.-' '__' <<<"$w")=$id" >> "$out" + echo "$w: run $id" +done + +old=$(gh api "repos/$GH_REPO/git/ref/tags/nightly" --jq .object.sha 2>/dev/null || true) +echo "Commit: $sha (the nightly release has: ${old:-none})" +if [ "$sha" = "$old" ] && [ "${FORCE:-false}" != true ]; then + echo "skip=true" >> "$out" + echo "No new commits on main. The nightly release does not change." +else + echo "skip=false" >> "$out" +fi diff --git a/.github/scripts/nightly-publish.sh b/.github/scripts/nightly-publish.sh new file mode 100755 index 0000000..0350848 --- /dev/null +++ b/.github/scripts/nightly-publish.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +# nightly-publish.sh SHA NOTES DIR +# +# Replaces the "nightly" pre-release with a new one: its tag at SHA, its +# text from the file NOTES, its files all the files in DIR. +# +# It needs GH_TOKEN and GH_REPO. +set -euo pipefail + +sha=$1 notes=$2 dir=$3 +shopt -s nullglob +files=("$dir"/*) +[ ${#files[@]} -gt 0 ] || { echo "::error::No files to publish in $dir"; exit 1; } + +gh release delete nightly --yes --cleanup-tag 2>/dev/null || true +# (a tag that has no release) +gh api -X DELETE "repos/$GH_REPO/git/refs/tags/nightly" 2>/dev/null || true + +gh release create nightly "${files[@]}" \ + --prerelease --latest=false --target "$sha" \ + --title "Nightly build ($(date -u +%Y-%m-%d), ${sha:0:7})" \ + --notes-file "$notes" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0296894..7d3ee5c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,6 +2,9 @@ # Windows app for Linux and macOS (winport/) name: Build +# The nightly release (nightly.yml) takes its files from this +# workflow's artifacts on main. Each artifact is a .tar.gz or a .zip, +# because an artifact does not keep the executable bit of a file. on: push: branches: [main] @@ -57,6 +60,14 @@ jobs: DMODEM_SSH_TEST=127.0.0.1:2222:dmtest:Sesame-42 DMODEM_SSH_TEST_KEY="$RUNNER_TEMP/key" \ DMODEM_SSH_TEST_PPK="$RUNNER_TEMP/key.ppk" DMODEM_SSH_TEST_AGENT="$RUNNER_TEMP/agent.sock" \ build/ssh/dmodemssh_test + - name: Package + run: | + DESTDIR="$PWD/pkg" cmake --install build --prefix /usr + tar -C pkg -czf dmodem-gui-linux-x86_64.tar.gz usr + - uses: actions/upload-artifact@v4 + with: + name: dmodem-linux + path: dmodem-gui-linux-x86_64.tar.gz # Both Windows builds use clang-retro (https://clang-retro.github.io/), # its toolchain package from its setup-toolchain action, on Linux @@ -144,10 +155,12 @@ jobs: cmake --build build --target dmodem-win32 - name: Smoke test (Xvfb) run: xvfb-run -a winport/test/smoke.sh build/winport/dmodem-win32 + - name: Package + run: tar -C build/winport -czf dmodem-win32-linux-x86_64.tar.gz dmodem-win32 - uses: actions/upload-artifact@v4 with: name: dmodem-win32-linux - path: build/winport/dmodem-win32 + path: dmodem-win32-linux-x86_64.tar.gz winport-macos: name: Windows app on macOS (clang-retro MFC's Win32 layer) @@ -166,10 +179,12 @@ jobs: -DDMODEM_GUI_WINPORT=ON -DCLANG_RETRO_MFC="$PWD/mfc" \ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ cmake --build build --target dmodem-win32 -j"$(sysctl -n hw.ncpu)" + - name: Package + run: tar -C build/winport -czf dmodem-win32-macos-arm64.tar.gz dmodem-win32 - uses: actions/upload-artifact@v4 with: name: dmodem-win32-macos - path: build/winport/dmodem-win32 + path: dmodem-win32-macos-arm64.tar.gz macos: name: macOS (SwiftUI) @@ -192,7 +207,10 @@ jobs: xcodebuild -project DModem.xcodeproj -scheme DModem \ -configuration Release -derivedDataPath ../build/xcode \ CODE_SIGN_IDENTITY=- build + # (ditto keeps the bundle's symbolic links and executable bits) + - name: Package + run: ditto -c -k --keepParent build/xcode/Build/Products/Release/D-Modem.app D-Modem-macos.zip - uses: actions/upload-artifact@v4 with: name: dmodem-macos - path: build/xcode/Build/Products/Release/D-Modem.app + path: D-Modem-macos.zip diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml new file mode 100644 index 0000000..349b59c --- /dev/null +++ b/.github/workflows/nightly.yml @@ -0,0 +1,94 @@ +# Nightly: the "nightly" pre-release of the apps, from the artifacts of +# the newest complete run of build.yml on main. It does not build the +# apps again. Each run replaces the release and moves its tag. When +# main has no new commits, the run stops and the release does not +# change. A manual run (Actions > Nightly > Run workflow) can publish +# again with "force". +# +# The files are not signed: Windows SmartScreen and macOS Gatekeeper +# show a warning for them. +name: Nightly + +on: + schedule: + - cron: "23 5 * * *" + workflow_dispatch: + inputs: + force: + description: Publish again, also when main has no new commits + type: boolean + default: false + +# (one at a time: a second run waits for the first) +concurrency: + group: nightly + cancel-in-progress: false + +permissions: + contents: write + actions: read + +jobs: + nightly: + runs-on: ubuntu-24.04 + timeout-minutes: 20 + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + steps: + - uses: actions/checkout@v4 + + - name: The newest build of main + id: pick + run: .github/scripts/nightly-pick.sh build.yml + env: + FORCE: ${{ inputs.force || 'false' }} + + - uses: actions/download-artifact@v4 + if: steps.pick.outputs.skip == 'false' + with: + run-id: ${{ steps.pick.outputs.run_build_yml }} + github-token: ${{ github.token }} + path: dl + + - name: Files + if: steps.pick.outputs.skip == 'false' + env: + SHA: ${{ steps.pick.outputs.sha }} + RUN: ${{ steps.pick.outputs.run_build_yml }} + run: | + mkdir out + take() { # take ARTIFACT FILE [NAME]: copy it if the build made it + if [ -f "dl/$1/$2" ]; then cp "dl/$1/$2" "out/${3:-$2}"; else echo "- $1" >> missing; fi + } + take dmodem-windows-9x dmodem.exe dmodem-win9x.exe + take dmodem-windows dmodem.exe dmodem-win7.exe + take dmodem-linux dmodem-gui-linux-x86_64.tar.gz + take dmodem-macos D-Modem-macos.zip + take dmodem-win32-linux dmodem-win32-linux-x86_64.tar.gz + take dmodem-win32-macos dmodem-win32-macos-arm64.tar.gz + (cd out && sha256sum * > SHA256SUMS) + ls -l out + { + echo "The newest build of \`main\`, from commit $SHA ([build run]($GITHUB_SERVER_URL/$GH_REPO/actions/runs/$RUN))." + echo "This is not a stable release. The files are not signed." + echo + echo "| File | What it is |" + echo "| --- | --- |" + echo "| \`dmodem-win9x.exe\` | The Windows app for Windows 95, 98, ME, NT 4.0 and later |" + echo "| \`dmodem-win7.exe\` | The Windows app for Windows 7 and later |" + echo "| \`dmodem-gui-linux-x86_64.tar.gz\` | The Linux app (GTK 4), x86_64. It needs GTK 4, libadwaita, PulseAudio and libsndfile. Extract it into \`/\` or \`/usr/local\` |" + echo "| \`D-Modem-macos.zip\` | The macOS app (SwiftUI), arm64 and x86_64, macOS 13 and later. Not notarized: right-click the app and select Open |" + echo "| \`dmodem-win32-linux-x86_64.tar.gz\` | The Windows app on Linux (X11), x86_64 |" + echo "| \`dmodem-win32-macos-arm64.tar.gz\` | The Windows app on macOS, arm64 |" + echo "| \`SHA256SUMS\` | The SHA-256 of each file |" + if [ -f missing ]; then + echo + echo "This build did not make these artifacts:" + cat missing + fi + } > notes.md + + - name: Publish + if: steps.pick.outputs.skip == 'false' + run: .github/scripts/nightly-publish.sh "${{ steps.pick.outputs.sha }}" notes.md out diff --git a/README.md b/README.md index 785a46b..51d401d 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,18 @@ libdmodemctl. Thus they operate in the same way. The Linux app's Phone page The Windows app's Phone page taking a message +## Nightly builds + +The [nightly release](https://github.com/D-Modem/gui/releases/tag/nightly) +has the apps from the newest build of `main`. It has the Windows app (for +Windows 95 and later, and for Windows 7 and later), the Linux app, the +macOS app, and the Windows app for Linux and macOS. A workflow +(`.github/workflows/nightly.yml`) replaces the release one time each day. +When `main` has no new commits, the release does not change. + +These builds are not stable releases. The files are not signed. Thus +Windows and macOS can show a warning before the app starts. + ## Quick start Linux: