-
Notifications
You must be signed in to change notification settings - Fork 0
123 lines (106 loc) · 4.19 KB
/
release.yml
File metadata and controls
123 lines (106 loc) · 4.19 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
name: Release
on:
push:
branches:
- main
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
version:
name: Determine version
runs-on: ubuntu-latest
outputs:
new_tag: ${{ steps.tag.outputs.new_tag }}
new_version: ${{ steps.tag.outputs.new_version }}
changelog: ${{ steps.tag.outputs.changelog }}
previous_tag: ${{ steps.tag.outputs.previous_tag }}
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Determine next version
id: tag
uses: mathieudutour/github-tag-action@d28fa2ccfbd16e871a4bdf35e11b3ad1bd56c0c1 # v6.2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
default_bump: false
tag_prefix: v
bump:
name: Bump version in files
runs-on: ubuntu-latest
needs: version
if: needs.version.outputs.new_tag != ''
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: main
- name: Bump versions from .version-bump.json
env:
NEW_VERSION: ${{ needs.version.outputs.new_version }}
run: |
echo "Bumping version to ${NEW_VERSION}"
jq -c '.files[]' .version-bump.json | while IFS= read -r entry; do
FILE=$(echo "$entry" | jq -r '.path')
FIELD=$(echo "$entry" | jq -r '.field')
if [ ! -f "$FILE" ]; then
echo "::warning::File not found: $FILE"
continue
fi
# Convert dot-notation path to jq setpath array
# e.g. "plugins.0.version" -> ["plugins",0,"version"]
JQ_PATH=$(echo "$FIELD" | jq -R 'split(".") | map(if test("^[0-9]+$") then tonumber else . end)')
echo "Updating $FILE field '$FIELD' to $NEW_VERSION"
jq --arg v "$NEW_VERSION" --argjson path "$JQ_PATH" 'setpath($path; $v)' "$FILE" > tmp.$$.json && mv tmp.$$.json "$FILE"
done
- name: Audit for stale version references
env:
PREVIOUS_TAG: ${{ needs.version.outputs.previous_tag }}
run: |
PREVIOUS_VERSION="${PREVIOUS_TAG#v}"
if [ -z "$PREVIOUS_VERSION" ]; then
echo "No previous version to audit against"
exit 0
fi
echo "Auditing for stale references to ${PREVIOUS_VERSION}"
EXCLUDE_ARGS=""
for pattern in $(jq -r '.audit.exclude[]' .version-bump.json); do
EXCLUDE_ARGS="$EXCLUDE_ARGS --exclude=$pattern --exclude-dir=$pattern"
done
if grep -r "$PREVIOUS_VERSION" . $EXCLUDE_ARGS --include='*.json' --include='*.md' --include='*.yml' --include='*.yaml' 2>/dev/null; then
echo "::warning::Found stale version references to ${PREVIOUS_VERSION} — check the files above"
else
echo "No stale version references found"
fi
- name: Create version bump PR
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
with:
commit-message: "chore(release): bump version to v${{ needs.version.outputs.new_version }}"
branch: chore/bump-version-${{ needs.version.outputs.new_version }}
title: "chore(release): bump version to v${{ needs.version.outputs.new_version }}"
body: "Automated version bump to v${{ needs.version.outputs.new_version }}"
labels: automated
release:
name: Create GitHub release
runs-on: ubuntu-latest
needs: [version, bump]
steps:
- name: Create release
uses: actions/github-script@d746ffe35508b1917358783b479e04febd2b8f71 # v9.0.0
env:
NEW_TAG: ${{ needs.version.outputs.new_tag }}
CHANGELOG: ${{ needs.version.outputs.changelog }}
with:
script: |
await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: process.env.NEW_TAG,
name: process.env.NEW_TAG,
body: process.env.CHANGELOG,
draft: false,
prerelease: false
});