-
Notifications
You must be signed in to change notification settings - Fork 47
82 lines (70 loc) · 2.88 KB
/
report.yml
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
name: Performance Report
on:
workflow_dispatch: # Allow manual triggering
# When another workflow is completed and successful
workflow_run:
workflows: [ Code Check and Release ]
types:
- completed
jobs:
report:
runs-on: ubuntu-latest
timeout-minutes: 60 # Allow 1 hour for the job to complete
steps:
- name: Check out repository
uses: actions/checkout@v2
with:
fetch-depth: 0 # Ensure all tags are fetched
- name: Determine Tag Name
id: determine_tag
run: |
if [[ "${{ github.event_name }}" == "push" ]]; then
# For push events, get the tag from github.ref
TAG_NAME="${GITHUB_REF#refs/tags/}"
else
# For manual trigger, get the latest tag
TAG_NAME=$(git describe --tags $(git rev-list --tags --max-count=1))
fi
echo "Using tag: $TAG_NAME"
echo "tag=$TAG_NAME" >> $GITHUB_ENV
- name: Check out Repository at Tag
uses: actions/checkout@v2
with:
ref: ${{ env.tag }} # Checkout at the determined tag
# Check if release notes are already updated
- name: Check Release Notes
id: check_release_notes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Set GH_TOKEN for GitHub CLI
run: |
RELEASE_BODY=$(gh release view "$TAG_NAME" --json body --jq '.body')
echo "Current release body: $RELEASE_BODY"
if [[ $RELEASE_BODY == *"Performance Report"* ]]; then
echo "Release notes already updated"
exit 1
fi
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ vars.DOTNET_VERSION }} # Using repository-level environment variable
- name: Run benchmarks
run: |
cd src/Nino.Benchmark
dotnet run -c Release
- name: Update Release Body
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Set GH_TOKEN for GitHub CLI
TAG_NAME: ${{ env.tag }}
run: |
# Read PERF_CONTENT from the file
cd src/Nino.Benchmark/BenchmarkDotNet.Artifacts/results
PERF_CONTENT=$(cat Nino.Benchmark.SimpleTest-report-github.md)
echo "Performance report content: $PERF_CONTENT"
# Retrieve the existing release body
RELEASE_BODY=$(gh release view "$TAG_NAME" --json body --jq '.body')
echo "Current release body: $RELEASE_BODY"
# Prepare the new content by using printf to handle multiline content correctly
NEW_CONTENT=$(printf "\n\n## Performance Report\n<details><summary>expand</summary>\n\n%s\n\n</details>\n" "$PERF_CONTENT")
UPDATED_BODY=$(printf "%s%s" "$RELEASE_BODY" "$NEW_CONTENT")
# Update the release notes
gh release edit "$TAG_NAME" --notes "$UPDATED_BODY"