-
Notifications
You must be signed in to change notification settings - Fork 2
156 lines (138 loc) · 5.49 KB
/
__call-release-notifier.yml
File metadata and controls
156 lines (138 loc) · 5.49 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
---
name: Release Notifications (called)
permissions: {}
on:
workflow_call:
inputs:
gh_name:
description: 'GitHub name to use for the workflow.'
required: true
type: string
secrets:
GH_EMAIL:
description: 'GitHub email to use for the workflow.'
required: true
GH_TOKEN:
description: 'GitHub token to use for the workflow.'
required: true
jobs:
update-blog:
name: Update blog
if: github.repository_owner == 'LizardByte'
permissions:
contents: read
runs-on: ubuntu-latest
environment:
name: release-announcement
url: ${{ steps.create-pr.outputs.pull-request-url }}
env:
BLOG_REPO: ${{ github.repository_owner }}/${{ github.repository_owner }}.github.io
steps:
- name: Check topics
env:
TOPIC: replicator-release-notifications
id: check-label
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
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@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
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@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: ${{ env.BLOG_REPO }}
- 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}")"
thumbnail_base_url="https://app.lizardbyte.dev/dashboard/github/openGraphImages"
thumbnail_url="${thumbnail_base_url}/${{ github.event.repository.name }}_624x312.png"
# create jekyll blog post
{
echo "---"
echo "layout: release"
echo "title: ${{ github.event.repository.name }} ${tag_name} Released"
echo "release-tag: ${tag_name}"
echo "gh-repo: ${{ github.repository }}"
echo "gh-badge: [follow, fork, star]"
echo "tags: [release, ${repo_lower}]"
echo "thumbnail-img: ${thumbnail_url}"
echo "comments: true"
echo "authors:"
echo " - github: LizardByte-bot"
echo "---"
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@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
with:
author: "${{ inputs.gh_name }} <${{ secrets.GH_EMAIL }}>"
committer: "${{ inputs.gh_name }} <${{ secrets.GH_EMAIL }}>"
token: ${{ secrets.GH_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_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 }}"