Repository navigation
183 lines (166 loc) · 6.11 KB
/
Copy pathrelease.yml
File metadata and controls
183 lines (166 loc) · 6.11 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
name: Build & Release
on:
push:
tags:
- 'v*'
- 'backfill-*'
permissions:
contents: write
jobs:
release:
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '17'
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v4
with:
gradle-version: '7.6.4'
- name: Extract changelog for release
id: changelog
run: |
# Tags created before CHANGELOG.md existed fall back to the copy on master
if [ ! -f CHANGELOG.md ]; then
git fetch --depth=1 origin master || true
if git cat-file -e origin/master:CHANGELOG.md 2>/dev/null; then
git show origin/master:CHANGELOG.md > CHANGELOG.md
fi
fi
version="${GITHUB_REF_NAME#v}"
{
echo "body<<CHANGELOG_EOF"
awk -v ver="[$version]" '
index($0, "## " ver) == 1 { flag = 1; next }
flag && /^## \[/ { exit }
flag { print }
' CHANGELOG.md
echo "CHANGELOG_EOF"
} >> "$GITHUB_OUTPUT"
- name: Build plugin
run: |
# Tags from before the wrapper was committed have no ./gradlew
if [ -x ./gradlew ]; then
./gradlew buildPlugin --no-daemon --stacktrace
else
gradle buildPlugin --no-daemon --stacktrace
fi
- name: Create release
uses: softprops/action-gh-release@v2
with:
body: ${{ steps.changelog.outputs.body }}
files: build/distributions/*.zip
generate_release_notes: true
# Backfill: build historical tags whose release has no zip attached and upload it.
# Triggered by pushing a tag named backfill-assets* (e.g. backfill-assets-2); inert for normal v* tags.
discover-backfill-tags:
if: startsWith(github.ref, 'refs/tags/backfill-assets')
runs-on: ubuntu-latest
outputs:
tags: ${{ steps.discover.outputs.tags }}
steps:
- name: Find releases without a plugin zip
id: discover
env:
GH_TOKEN: ${{ github.token }}
run: |
# releases that exist but carry no assets
no_asset_releases=$(gh api "repos/$GITHUB_REPOSITORY/releases?per_page=100" --paginate --jq '.[] | select((.assets | length) == 0) | .tag_name')
# all tags from v1.5.0 on (older toolchains are not reproducible in CI)
all_tags=$(gh api "repos/$GITHUB_REPOSITORY/tags?per_page=100" --paginate --jq '.[].name' | awk '$0 >= "v1.5.0"')
missing=()
while read -r tag; do
[ -z "$tag" ] && continue
if ! grep -qx "$tag" <<< "$no_asset_releases"; then
missing+=("$tag")
echo "missing asset: $tag"
fi
done <<< "$all_tags"
if [ ${#missing[@]} -gt 0 ]; then
echo "tags=$(printf '%s\n' "${missing[@]}" | jq -R . | jq -sc .)" >> "$GITHUB_OUTPUT"
else
echo 'tags=[]' >> "$GITHUB_OUTPUT"
fi
backfill-historical-builds:
needs: discover-backfill-tags
if: needs.discover-backfill-tags.outputs.tags != '[]'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
tag: ${{ fromJSON(needs.discover-backfill-tags.outputs.tags) }}
steps:
- name: Checkout ${{ matrix.tag }}
uses: actions/checkout@v4
with:
ref: ${{ matrix.tag }}
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '17'
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v4
with:
gradle-version: '7.6.4'
- name: Build plugin
run: |
cat > ci-init.gradle <<'EOF'
allprojects {
afterEvaluate { project ->
def intellijExt = project.extensions.findByName('intellij')
if (intellijExt != null) {
intellijExt.downloadSources = false
}
}
}
EOF
gradle -I ci-init.gradle buildPlugin --no-daemon --stacktrace
- name: Attach zip to release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ matrix.tag }}
files: build/distributions/*.zip
# Refresh release bodies of the backfilled historical releases from CHANGELOG.md.
# Triggered by pushing a tag named backfill-notes-*.
refresh-release-notes:
if: startsWith(github.ref, 'refs/tags/backfill-notes')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Delete stray backfill releases
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release list --repo "$GITHUB_REPOSITORY" --json tagName --jq '.[].tagName' \
| grep '^backfill-' \
| while read -r tag; do
gh release delete "$tag" --repo "$GITHUB_REPOSITORY" --yes --cleanup-tag
echo "Deleted stray release $tag"
done || true
- name: Fill release bodies from CHANGELOG.md
env:
GH_TOKEN: ${{ github.token }}
run: |
tags=$(gh api "repos/$GITHUB_REPOSITORY/tags?per_page=100" --paginate --jq '.[].name' | grep -E '^v[0-9]+(\.[0-9]+)+$' | sort -V)
for tag in $tags; do
version="${tag#v}"
body=$(awk -v ver="[$version]" '
index($0, "## " ver) == 1 { flag = 1; next }
flag && /^## \[/ { exit }
flag { print }
' CHANGELOG.md)
if gh release view "$tag" --repo "$GITHUB_REPOSITORY" > /dev/null 2>&1; then
gh release edit "$tag" --repo "$GITHUB_REPOSITORY" --notes "$body"
echo "Updated notes for $tag"
else
gh release create "$tag" --repo "$GITHUB_REPOSITORY" --verify-tag --title "$tag" --notes "$body"
echo "Created release for $tag"
fi
done