-
Notifications
You must be signed in to change notification settings - Fork 39
147 lines (123 loc) · 4.8 KB
/
release-note.yaml
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# Copyright 2023 The Knative Authors.
# SPDX-License-Identifier: Apache-2.0
# This file is automagically synced here from github.com/knative-extensions/knobots
name: 'Release Notes'
on:
workflow_dispatch:
inputs:
repo:
description: 'Repository'
required: true
branch:
description: 'Branch (defaults to latest release branch)'
required: false
start-rev:
description: 'Start Tag (defaults to merge-base(branch, prev-branch))'
required: false
end-rev:
description: 'End Tag (defaults to HEAD of the target branch)'
required: false
start-sha:
description: 'The commit hash to start processing from (inclusive). To be used with new repos where previous branch is missing.'
required: false
jobs:
release-notes:
name: Release Notes
runs-on: 'ubuntu-latest'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_WEBHOOK: ${{ secrets.SONAR_TOKEN != '' }}
steps:
- name: Set up Go
uses: actions/setup-go@v4
with:
cache: false # installing deps doesn't have a go.sum
go-version: 1.21.x
- name: Restore module cache
uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: |
${{ runner.os }}-golang-
restore-keys: |
${{ runner.os }}-golang-
- name: Install Dependencies
# https://github.com/kubernetes/release/tree/master/cmd/release-notes
run: go install k8s.io/release/cmd/release-notes@latest
- name: Check out code
uses: actions/checkout@v3
with:
# fetch-depth of 0 indicates all history for all branches and tags.
fetch-depth: 0
repository: ${{ inputs.repo }}
- name: Generate Notes - ${{ inputs.repo }}
run: |
set -x
BRANCHES="$(mktemp)"
# List of branches sorted by semver descending
git branch -r -l "origin/release-[0-9]*\.[0-9]*" --format="%(refname:lstrip=3)" | sort -Vr > "$BRANCHES"
# The release-notes tool access ENV vars as options
# https://github.com/kubernetes/release/tree/master/cmd/release-notes#options
export BRANCH="${{ inputs.branch }}"
export ORG=$(echo '${{ inputs.repo }}' | awk -F '/' '{print $1}')
export REPO=$(echo '${{ inputs.repo }}' | awk -F '/' '{print $2}')
if [[ -z "$BRANCH" ]]; then
BRANCH="$(head -n1 "$BRANCHES")" # Default to last release branch
fi
echo "ORG=$ORG" >> $GITHUB_ENV
echo "REPO=$REPO" >> $GITHUB_ENV
echo "BRANCH=$BRANCH" >> $GITHUB_ENV
export START_SHA="${{ inputs.start-sha }}"
# If start rev isn't set find the merge base of
# the target branch and the previous branch
export START_REV="${{ inputs.start-rev }}"
if [[ -z "$START_REV" ]]; then
if [[ "$BRANCH" == "main" ]]; then
LAST_BRANCH="$(head -n1 "$BRANCHES")"
else
# use grep magic to find the next branch
# '-A 1' - prints the line after the match which we can parse
LAST_BRANCH="$(grep -A 1 "$BRANCH" "$BRANCHES" | tail -n1)"
fi
export START_SHA="$(git merge-base origin/$LAST_BRANCH origin/$BRANCH)"
fi
export END_REV="${{ inputs.end-rev }}"
if [[ -z "$END_REV" ]]; then
END_REV="origin/${BRANCH}"
fi
release-notes \
--required-author="" \
--output=release-notes.md \
--repo-path="$PWD" \
- name: Display Notes
run: |
echo "${{ inputs.repo }}@${{ env.BRANCH }}" >> $GITHUB_STEP_SUMMARY
cat release-notes.md >> $GITHUB_STEP_SUMMARY
- name: Archive Release Notes
uses: actions/upload-artifact@v3
with:
name: ${{ env.ORG }}-${{ env.REPO }}-${{ env.BRANCH }}.md
path: release-notes.md
- name: Status GO
run: |
echo 'SLACK_COLOR=#098e00' >> "$GITHUB_ENV"
echo 'SLACK_TITLE=Release note - ${{ inputs.repo }}@${{ env.BRANCH }}' >> "$GITHUB_ENV"
- name: Status NO-GO
if: failure()
run: |
echo 'SLACK_COLOR=#8E1600' >> "$GITHUB_ENV"
echo 'SLACK_TITLE=Release note failed - ${{ inputs.repo }}@${{ env.BRANCH }}' >> "$GITHUB_ENV"
- name: Post status to Slack
# Note: using env.SLACK_WEBHOOK here because secrets are not allowed in the if block.
if: ${{ always() && env.SLACK_WEBHOOK != '' }}
uses: rtCamp/[email protected]
env:
SLACK_CHANNEL: knative-release
SLACK_USERNAME: knative/release
SLACK_ICON: http://github.com/knative.png?size=48
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
MSG_MINIMAL: 'true'
SLACK_MESSAGE: View - https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
SLACK_FOOTER: ""