-
Notifications
You must be signed in to change notification settings - Fork 3
52 lines (47 loc) · 2.36 KB
/
auto-release.yml
File metadata and controls
52 lines (47 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
name: Automatic Release
on:
push:
branches: [master, main]
defaults:
run:
shell: pwsh
env:
# Because actions using `github.token` cannot trigger other workflows to occur
GH_TOKEN: ${{ secrets.PARTICULARBOT_GITHUB_TOKEN }}
jobs:
auto-release:
name: Automatic Release
# Don't run unless merging to the default branch
if: ${{ github.ref_name == github.event.repository.default_branch }}
runs-on: ubuntu-latest
steps:
# Checkout required for GitHub CLI to work
- name: Checkout
uses: actions/checkout@v6.0.2
with:
# Need history for git diff to work
fetch-depth: 0
- name: Determine if auto-release is necessary
run: |
# Script checks the diff of src/Particular.PlatformSample/Particular.PlatformSample.csproj in the latest commit, and invokes a release of the next minor if ServiceControl/ServicePulse changes
echo "Comparing diff of latest commit (git diff HEAD~1 HEAD) to determine if ServiceControl/ServicePulse package was updated"
$diff = $(git diff HEAD~1 HEAD src/Particular.PlatformSample/Particular.PlatformSample.csproj )
# Grep search for lines that show an addition contianing ServiceControl/ServicePulse
$updates = $diff | grep -E '^\+\s+<PackageReference Include="Particular\.PlatformSample\.(ServiceControl|ServicePulse)"'
echo "Result of search for ServiceControl/ServicePulse updates in PR diff"
echo $updates
# Get number of lines
$lines = ($updates | Measure-Object -Line).Lines
if ($lines -eq 0) {
echo "Nothing to release"
exit 0
}
echo "Change to ServiceControl/ServicePulse detected, need to release"
$tags = gh api /repos/${{ github.repository }}/tags | ConvertFrom-Json
$latest = [Version]($tags | Where-Object name -match '^\d+\.\d+\.\d+$' | Sort-Object -Descending {[Version]$_.name} | Select-Object name)[0].name
$nextMinor = "$($latest.Major).$($latest.Minor + 1).0"
echo "Latest release is $latest, next release should be $nextMinor"
echo "Tagging release of $nextMinor"
gh api repos/Particular/Particular.PlatformSample/git/refs -f ref="refs/tags/$nextMinor" -f sha="$Env:GITHUB_SHA"
echo "Release triggered, complete"
exit 0