Skip to content

Commit b744cec

Browse files
authored
Publish releases with version notes for every tag (#762)
1 parent e81a22f commit b744cec

File tree

4 files changed

+82
-57
lines changed

4 files changed

+82
-57
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ end_of_line = lf
99
charset = utf-8
1010
trim_trailing_whitespace = true
1111
insert_final_newline = true
12+
13+
[*.js]
14+
indent_size = 2

.github/scripts/notes.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module.exports = async ({ core, fetch }) => {
2+
const { VERSION } = process.env
3+
const slug = `version-${VERSION.replaceAll('.', '-')}`
4+
5+
try {
6+
const res = await fetch('https://wordpress.org/documentation/wp-json/wp/v2/wordpress-versions?per_page=50')
7+
const data = await res.json()
8+
9+
const release = data.find((tag) => tag.slug === slug)
10+
if (!release) {
11+
throw Error('Release not found')
12+
}
13+
14+
const { link } = release
15+
const body = release.content?.rendered?.split('<h2', 4)[2]
16+
if (!body) {
17+
throw Error('Release body is empty or unexpected')
18+
}
19+
20+
return `_Sourced from [WordPress.org Documentation](${link})._\n\n<h2${body}`
21+
} catch (e) {
22+
core.warning(e)
23+
24+
return `_Version notes available on [WordPress.org Documentation](https://wordpress.org/documentation/wordpress-version/${slug}/)._`
25+
}
26+
}

.github/scripts/tags.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
module.exports = async ({ github, context }) => {
2+
const { PACKAGE, META } = process.env
3+
4+
const [{ data: currrentTags }, { data: upstreamTags }] = await Promise.all([
5+
github.rest.repos.listTags({
6+
owner: context.repo.owner,
7+
repo: META.substring(META.indexOf('/') + 1),
8+
per_page: 100,
9+
}),
10+
github.rest.repos.listTags({
11+
owner: context.repo.owner,
12+
repo: PACKAGE.substring(PACKAGE.indexOf('/') + 1),
13+
per_page: 100,
14+
}),
15+
])
16+
17+
const targetTags = await Promise.allSettled(
18+
upstreamTags
19+
.filter((tag) => !currrentTags.find((t) => t.name === tag.name))
20+
.map((tag) =>
21+
github.rest.git
22+
.getRef({
23+
owner: context.repo.owner,
24+
repo: META.substring(META.indexOf('/') + 1),
25+
ref: 'tags/' + tag.name,
26+
})
27+
.then(() => {})
28+
.catch((res) => ({ tag: tag.name, status: res.status }))
29+
)
30+
)
31+
32+
return targetTags
33+
.filter(({ value }) => value?.status === 404)
34+
.map(({ value }) => value.tag)
35+
}

.github/workflows/meta-package.yml

Lines changed: 18 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ jobs:
1010
runs-on: ubuntu-latest
1111
outputs:
1212
tags-matrix: ${{ steps.tags-matrix.outputs.result }}
13-
latest-release: ${{ steps.latest-release.outputs.result }}
1413
steps:
1514
- uses: actions/checkout@v3
1615
with:
@@ -28,43 +27,8 @@ jobs:
2827
META: ${{ secrets.META_PACKAGE }}
2928
with:
3029
script: |
31-
const { PACKAGE, META } = process.env
32-
const [{ data: currrentTags }, { data: upstreamTags }] = await Promise.all([
33-
github.rest.repos.listTags({
34-
owner: context.repo.owner,
35-
repo: META.substring(META.indexOf('/') + 1),
36-
per_page: 100,
37-
}),
38-
github.rest.repos.listTags({
39-
owner: context.repo.owner,
40-
repo: PACKAGE.substring(PACKAGE.indexOf('/') + 1),
41-
per_page: 100,
42-
}),
43-
])
44-
const targetTags = await Promise.allSettled(
45-
upstreamTags
46-
.filter((tag) => !currrentTags.find((t) => t.name === tag.name))
47-
.map((tag) =>
48-
github.rest.git
49-
.getRef({
50-
owner: context.repo.owner,
51-
repo: META.substring(META.indexOf('/') + 1),
52-
ref: 'tags/' + tag.name,
53-
})
54-
.then(() => {})
55-
.catch((res) => ({ tag: tag.name, status: res.status }))
56-
)
57-
)
58-
return targetTags
59-
.filter(({ value }) => value?.status === 404)
60-
.map(({ value }) => value.tag)
61-
62-
# Can't be used as is: some version release batches don't override latest version
63-
# - name: Extract latest release
64-
# id: latest-release
65-
# env:
66-
# TAGS: ${{ steps.tags-matrix.outputs.result }}
67-
# run: echo "::set-output name=result::$(jq -r '.[0]' <<< "$TAGS")"
30+
const tags = require('${{ github.workspace }}/.github/scripts/tags.js')
31+
return await tags({ github, context })
6832
6933
tags:
7034
name: Tags
@@ -89,7 +53,18 @@ jobs:
8953
repository: ${{ secrets.META_PACKAGE }}
9054
token: ${{ steps.generate-token.outputs.token }}
9155

92-
- name: Create a tag
56+
- name: Retrieve version notes
57+
id: notes
58+
uses: actions/github-script@v6
59+
env:
60+
VERSION: ${{ matrix.tag }}
61+
with:
62+
result-encoding: string
63+
script: |
64+
const notes = require('${{ github.workspace }}/.github/scripts/notes.js')
65+
return await notes({ core, fetch })
66+
67+
- name: Push tag
9368
env:
9469
TAG: ${{ matrix.tag }}
9570
run: |
@@ -98,25 +73,11 @@ jobs:
9873
git tag -a "${TAG}" -m "${TAG}"
9974
git push origin "${TAG}"
10075
101-
release:
102-
name: Release
103-
runs-on: ubuntu-latest
104-
needs:
105-
- sync
106-
- tags
107-
if: needs.sync.outputs.tags-matrix != '[]'
108-
steps:
109-
- name: Generate token
110-
uses: tibdex/github-app-token@v1
111-
id: generate-token
112-
with:
113-
app_id: ${{ secrets.BOT_APP_ID }}
114-
private_key: ${{ secrets.BOT_PRIVATE_KEY }}
115-
116-
- name: Create a release
76+
- name: Publish release
11777
uses: softprops/action-gh-release@v1
11878
with:
11979
repository: ${{ secrets.META_PACKAGE }}
12080
token: ${{ steps.generate-token.outputs.token }}
121-
body: WordPress ${{ needs.sync.outputs.latest-release }}
122-
tag_name: ${{ needs.sync.outputs.latest-release }}
81+
body: ${{ steps.notes.outputs.result }}
82+
name: Version ${{ matrix.tag }}
83+
tag_name: ${{ matrix.tag }}

0 commit comments

Comments
 (0)