Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/scripts/changelog.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Lists the pull requests merged between two refs that changed the app itself (not only docs, workflows or
# repository settings), oldest first, as "Title (#12)" lines for release notes. Dependabot's updates are
# folded into one "Updated libraries" line. Used by release.yml; needs git history and the gh CLI.
param(
[string] $From, # previous release tag; empty = everything up to $To
[string] $To = 'HEAD',
[string] $Repo = $env:GITHUB_REPOSITORY
)
$ErrorActionPreference = 'Stop'

# What the app is built from: build-test.yml's "Needs a build?" list, without that workflow itself.
$appFiles = '^(CallGuard[^/]*/|[^/]*\.slnx$|Directory\.(Packages|Build)\.(props|targets)$|global\.json$|dotnet-tools\.json$|[Nn]u[Gg]et\.config$)'

# GitHub's merge commits ("Merge pull request #12 from ...") and squash merges ("Title (#12)").
$range = if ($From) { "$From..$To" } else { $To }
$numbers = @(git log $range --first-parent --format=%s | ForEach-Object {
if ($_ -match '^Merge pull request #(\d+) ') { $Matches[1] }
elseif ($_ -match '\(#(\d+)\)$') { $Matches[1] }
})
[array]::Reverse($numbers)

$dependencyUpdates = 0
foreach ($number in $numbers) {
$pr = gh pr view $number --repo $Repo --json title,author,files | ConvertFrom-Json
if (-not ($pr.files.path -match $appFiles)) { continue }
if ($pr.author.login -like '*dependabot*') { $dependencyUpdates++; continue }
"$($pr.title) (#$number)"
}
if ($dependencyUpdates) { 'Updated libraries' }
59 changes: 40 additions & 19 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
# production
# PLAY_RELEASE_STATUS variable, optional: completed (default) rolls the release out as soon as
# Google approves it; draft only uploads it, to roll out from Play Console
# The release notes on Play ("What's new") are the merged pull request's title.
# Release notes, on GitHub and on Play ("What's new"), list the pull requests merged since the previous
# release that changed the app (.github/scripts/changelog.ps1).

name: Release APK

Expand Down Expand Up @@ -77,7 +78,10 @@ jobs:
New-Item -ItemType Directory -Force $tmp | Out-Null
"TMPDIR=$tmp" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8

# Full history and tags, to list the pull requests merged since the previous release.
- uses: actions/checkout@v7
with:
fetch-depth: 0

# Install the SDK somewhere the runner user owns, so the workload install needs no sudo.
- uses: actions/setup-dotnet@v6
Expand Down Expand Up @@ -193,6 +197,23 @@ jobs:
dist-play/*.aab
retention-days: 30

# What changed since the previous release (a different version: a same-day rebuild lists everything
# since the previous day's release, because it replaces that day's release).
- name: Write release notes
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.apk.outputs.version }}
run: |
$previous = gh release list --limit 50 --json tagName -q '.[].tagName' |
Where-Object { $_ -ne "v$env:VERSION" } | Select-Object -First 1
$changes = if ($previous) { @(./.github/scripts/changelog.ps1 -From $previous) } else { @('First release of Call Guard.') }
if (-not $changes) { $changes = @('Build and maintenance updates.') }
New-Item -ItemType Directory -Force notes | Out-Null
Set-Content notes/changes.txt -Value $changes -Encoding utf8NoBOM
Set-Content notes/previous.txt -Value "$previous" -NoNewline -Encoding utf8NoBOM
Write-Host "Changes since $(if ($previous) { $previous } else { 'the beginning' }):"
$changes | ForEach-Object { Write-Host " $_" }

# One release per version. A later build of the same version (same day) replaces the earlier
# release, so its tag, notes and APK always match the newest build.
- name: Publish GitHub release
Expand All @@ -209,30 +230,30 @@ jobs:
if ($LASTEXITCODE -ne 0) { throw "Couldn't replace the existing $tag release" }
}

$notes = @'
## Install
1. On your Android phone (Android 10 or later), download the `.apk` below.
2. Open it and allow your browser or Files app to install apps when Android asks.
Google Play Protect may warn about an app from an unknown developer; choose **Install anyway**.
3. Open Call Guard and follow the setup steps on its Home tab (see the README).

Updating: install the new `.apk` over the old one. Your patterns and call log are kept.
'@
$notes += "`n`nBuild $env:VERSION_CODE."
$changes = Get-Content notes/changes.txt | ForEach-Object { "- $_" }
$previous = Get-Content notes/previous.txt -Raw
$compare = if ($previous) { " · [All changes since $previous](https://github.com/$env:GITHUB_REPOSITORY/compare/$previous...$tag)" } else { '' }
$play = "https://play.google.com/store/apps/details?id=$env:PACKAGE_NAME"
$notes = @(
"## What's new"
$changes
''
'## Install'
"**[Get it on Google Play]($play)**, or download the ``.apk`` below and open it (Android 10 or later)."
'To update, install the new `.apk` over the old one: your patterns and call log are kept. The Play version'
'and the `.apk` are signed with the same key, so either can update the other.'
''
"Build $env:VERSION_CODE$compare"
) -join "`n"
gh release create $tag dist/*.apk --target $env:GITHUB_SHA `
--title "Call Guard $env:VERSION" --notes $notes --generate-notes
--title "Call Guard $env:VERSION" --notes $notes
if ($LASTEXITCODE -ne 0) { throw "Couldn't create the $tag release" }

# "What's new" on Play: the merged pull request's title (the second paragraph of GitHub's merge
# commit message), or the commit's own subject for a direct push or a squash merge.
# "What's new" on Play: the same list without the pull request numbers. Play allows 500 characters.
- name: Write Play release notes
if: vars.PLAY_TRACK != ''
run: |
$subject = git log -1 --format=%s
$notes = if ($subject -like 'Merge pull request*') {
(git log -1 --format=%b) | Where-Object { $_.Trim() } | Select-Object -First 1
}
if (-not $notes) { $notes = $subject }
$notes = (Get-Content notes/changes.txt | ForEach-Object { '• ' + ($_ -replace ' \(#\d+\)$', '') }) -join "`n"
if ($notes.Length -gt 500) { $notes = $notes.Substring(0, 497) + '...' }
New-Item -ItemType Directory -Force whatsnew | Out-Null
Set-Content -Path whatsnew/whatsnew-en-US -Value $notes -NoNewline -Encoding utf8NoBOM
Expand Down