-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
138 lines (119 loc) · 4.88 KB
/
release-notifier.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
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
---
# This action is centrally managed in https://github.com/<organization>/.github/
# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in
# the above-mentioned repo.
# Create a blog post for a new release and open a PR to the blog repo
name: Release Notifications
on:
release:
types:
- released # this triggers when a release is published, but does not include pre-releases or drafts
jobs:
update-blog:
if: >-
github.repository_owner == 'LizardByte'
runs-on: ubuntu-latest
steps:
- name: Check topics
env:
TOPIC: replicator-release-notifications
id: check-label
uses: actions/github-script@v7
with:
script: |
const topic = process.env.TOPIC;
console.log(`Checking if repo has topic: ${topic}`);
const repoTopics = await github.rest.repos.getAllTopics({
owner: context.repo.owner,
repo: context.repo.repo
});
console.log(`Repo topics: ${repoTopics.data.names}`);
const hasTopic = repoTopics.data.names.includes(topic);
console.log(`Has topic: ${hasTopic}`);
core.setOutput('hasTopic', hasTopic);
- name: Check if latest GitHub release
id: check-release
if: >-
steps.check-label.outputs.hasTopic == 'true'
uses: actions/github-script@v7
with:
script: |
const latestRelease = await github.rest.repos.getLatestRelease({
owner: context.repo.owner,
repo: context.repo.repo
});
core.setOutput('isLatestRelease', latestRelease.data.tag_name === context.payload.release.tag_name);
- name: Checkout blog
if: >-
steps.check-label.outputs.hasTopic == 'true' &&
steps.check-release.outputs.isLatestRelease == 'true'
uses: actions/checkout@v4
with:
repository: "LizardByte/LizardByte.github.io"
- name: Create blog post
if: >-
steps.check-label.outputs.hasTopic == 'true' &&
steps.check-release.outputs.isLatestRelease == 'true'
run: |
# setup variables
tag_name="${{ github.event.release.tag_name }}"
semver="${tag_name#v}"
repo_lower="$(echo "${{ github.event.repository.name }}" | tr '[:upper:]' '[:lower:]')"
# extract year, month, and day
year="${semver%%.*}"
month_day="${semver#*.}"
month_day="${month_day%%.*}"
# ensure month_day is 4 digits
month_day=$(printf "%04d" "$month_day")
# create the filename
file_name="_posts/releases/${repo_lower}/${year}-${month_day:0:2}-${month_day:2:2}-v${semver}.md"
mkdir -p "$(dirname "${file_name}")"
# create jekyll blog post
echo "---" > "${file_name}"
echo "layout: release" >> "${file_name}"
echo "title: ${{ github.event.repository.name }} ${tag_name} Released" >> "${file_name}"
echo "release-tag: ${tag_name}" >> "${file_name}"
echo "gh-repo: ${{ github.repository }}" >> "${file_name}"
echo "gh-badge: [follow, fork, star]" >> "${file_name}"
echo "tags: [release, ${repo_lower}]" >> "${file_name}"
echo "comments: true" >> "${file_name}"
echo "author: LizardByte-bot" >> "${file_name}"
echo "---" >> "${file_name}"
echo "" >> "${file_name}"
release_body=$(cat <<EOF
${{ github.event.release.body }}
EOF
)
echo "${release_body}" >> "${file_name}"
- name: Create/Update Pull Request
id: create-pr
if: >-
steps.check-label.outputs.hasTopic == 'true' &&
steps.check-release.outputs.isLatestRelease == 'true'
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GH_BOT_TOKEN }}
commit-message: |
chore: Add blog post for ${{ github.event.repository.name }} release ${{ github.event.release.tag_name }}
branch: bot/add-${{ github.event.repository.name }}-${{ github.event.release.tag_name }}
delete-branch: true
title: |
chore: Add blog post for ${{ github.event.repository.name }} release ${{ github.event.release.tag_name }}
body: ${{ github.event.release.body }}
labels:
blog
- name: Automerge PR
env:
GH_TOKEN: ${{ secrets.GH_BOT_TOKEN }}
if: >-
steps.check-label.outputs.hasTopic == 'true' &&
steps.check-release.outputs.isLatestRelease == 'true'
run: |
gh \
pr \
merge \
--auto \
--delete-branch \
--repo "LizardByte/LizardByte.github.io" \
--squash \
"${{ steps.create-pr.outputs.pull-request-number }}"