Repository navigation
162 lines (141 loc) · 5.8 KB
/
Copy pathrelease-notes.yml
File metadata and controls
162 lines (141 loc) · 5.8 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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: Release Notes Publisher
on:
release:
types:
- published
workflow_dispatch:
inputs:
debug_mode:
description: Enable debug logging
required: false
default: false
type: boolean
release-tag:
description: Release tag to publish into docs
required: true
type: string
prerelease:
description: Whether this release is a prerelease
required: false
default: false
type: boolean
release-body:
description: Release notes markdown body to publish into docs
required: false
default: ''
type: string
permissions:
contents: write
concurrency:
group: release-notes-publisher
cancel-in-progress: false
jobs:
update_release_notes_docs:
runs-on: ubuntu-24.04
steps:
- name: 🔍 Introspect Inputs
run: |
echo "::group::Workflow Inputs"
echo "Debug Mode: ${{ inputs.debug_mode || false }}"
echo "Release Tag Input: ${{ inputs['release-tag'] || '' }}"
echo "Prerelease Input: ${{ inputs.prerelease || false }}"
echo "Actor: ${{ github.actor }}"
echo "Event Name: ${{ github.event_name }}"
echo "Ref: ${{ github.ref }}"
echo "Release Tag From Event: ${{ github.event.release.tag_name || '' }}"
echo "Release Prerelease From Event: ${{ github.event.release.prerelease || false }}"
echo "::endgroup::"
- name: Checkout
uses: actions/checkout@v6
with:
token: ${{ secrets.RELEASE_NOTES_PAT }}
ref: master
fetch-depth: 0
- name: Prepare release notes file
id: prepare_release_notes
uses: actions/github-script@v8
env:
MANUAL_RELEASE_TAG: ${{ inputs['release-tag'] || '' }}
MANUAL_RELEASE_BODY: ${{ inputs['release-body'] || '' }}
MANUAL_PRERELEASE: ${{ inputs.prerelease || false }}
with:
script: |
const fs = require('fs');
const path = require('path');
const isManual = context.eventName === 'workflow_dispatch';
const tag = (isManual ? process.env.MANUAL_RELEASE_TAG : context.payload.release?.tag_name || '').trim();
const prerelease = isManual
? `${process.env.MANUAL_PRERELEASE}`.toLowerCase() === 'true'
: Boolean(context.payload.release?.prerelease);
const body = isManual ? process.env.MANUAL_RELEASE_BODY : (context.payload.release?.body || '');
if (!tag) {
core.setFailed('Unable to determine the release tag for the docs update.');
return;
}
const processedBody = body.replace(/\[/g, '\\[').replace(/\]/g, '\\]');
const content = [
'---',
`title: ${tag}`,
`date: ${new Date().toISOString().slice(0, 10)}`,
`tag: ${tag}`,
`prerelease: ${prerelease}`,
'---',
'',
processedBody,
'',
].join('\n');
const releaseFile = path.join(process.env.GITHUB_WORKSPACE, 'docs', 'content', 'en', 'project', 'releases', `${tag}.md`);
const tempFile = path.join(process.env.RUNNER_TEMP, `release-notes-${tag}.md`);
fs.writeFileSync(releaseFile, content, 'utf8');
fs.writeFileSync(tempFile, content, 'utf8');
core.info(`Prepared release notes for ${tag} at ${releaseFile}`);
core.setOutput('release_tag', tag);
core.setOutput('release_file', releaseFile);
core.setOutput('temp_file', tempFile);
- name: Commit and push release notes
env:
RELEASE_FILE: ${{ steps.prepare_release_notes.outputs.release_file }}
RELEASE_TAG: ${{ steps.prepare_release_notes.outputs.release_tag }}
TEMP_FILE: ${{ steps.prepare_release_notes.outputs.temp_file }}
run: |
git config user.name l5io
git config user.email ci@meshery.io
for attempt in 1 2 3; do
echo "Attempt ${attempt}: syncing release notes on top of origin/master"
git fetch origin master
git checkout master
git reset --hard origin/master
cp "$TEMP_FILE" "$RELEASE_FILE"
git add "$RELEASE_FILE"
if git diff --cached --quiet; then
echo "Release notes for ${RELEASE_TAG} are already up to date."
exit 0
fi
git commit --signoff -m "[Docs] Release Notes for Meshery ${RELEASE_TAG}" --author="${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>"
if git push origin HEAD:master; then
exit 0
fi
git reset --hard origin/master
sleep $((attempt * 10))
done
echo "Failed to publish release notes for ${RELEASE_TAG} after repeated push retries."
exit 1
- name: 🚨 Email Alert on Failure
if: failure()
uses: dawidd6/action-send-mail@v7
with:
server_address: smtp.gmail.com
server_port: 465
username: ${{ secrets.MAIL_USERNAME }}
password: ${{ secrets.MAIL_PASSWORD }}
subject: "Workflow Failed: ${{ github.workflow }}"
to: maintainers@meshery.io
from: support@meshery.io
secure: true
body: |
The release notes publishing workflow failed.
Repository: ${{ github.repository }}
Workflow: ${{ github.workflow }}
Run URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
Event: ${{ github.event_name }}
Release Tag: ${{ steps.prepare_release_notes.outputs.release_tag || github.event.release.tag_name || inputs['release-tag'] || 'unknown' }}