-
-
Notifications
You must be signed in to change notification settings - Fork 29
203 lines (189 loc) · 6.59 KB
/
build.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
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
name: Build
on:
push:
branches: [ 'master' ]
pull_request:
workflow_dispatch:
jobs:
gradle-wrapper-validation:
name: Validate Gradle Wrapper
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v2
check:
name: Build project (JDK ${{ matrix.jdk }})
runs-on: ubuntu-latest
needs: gradle-wrapper-validation
strategy:
fail-fast: false
matrix:
jdk: [ 17 ]
include:
- jdk: 17
primary: true
steps:
# Setup environment
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.jdk }}
distribution: temurin
# Setup caches and collect metadata
- name: Setup cache for Gradle and dependencies
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: "gradle-\
${{runner.os}}-\
${{hashFiles('gradle/wrapper/gradle-wrapper.properties')}}-\
${{hashFiles('gradle.properties', '**/*.gradle.kts')}}"
- name: Collect metadata for upcoming steps and jobs
run: ./gradlew --stacktrace metadata listProductsReleases
- name: Setup cache for IntelliJ Plugin Verifier
uses: actions/cache@v4
with:
path: |
~/.pluginVerifier/ides
key: "pluginVerifier-\
${{runner.os}}-\
${{hashFiles('build/listProductsReleases.txt')}}"
# Build and test
- name: Build project
run: ./gradlew --stacktrace assemble
- name: Run linters and tests
run: ./gradlew --stacktrace check
- name: Package and verify plugin
run: ./gradlew --stacktrace verifyPlugin
- name: Check plugin compatibility
run: ./gradlew --stacktrace runPluginVerifier
# Upload artifacts
- name: Upload build reports
if: always()
uses: actions/upload-artifact@v4
with:
name: reports-jdk${{matrix.jdk}}
path: build/reports/
if-no-files-found: ignore
- name: Upload build result
if: ${{ matrix.primary }}
uses: actions/upload-artifact@v4
with:
name: build-result
path: build/distributions/
if-no-files-found: error
- name: Upload metadata
if: ${{ matrix.primary }}
uses: actions/upload-artifact@v4
with:
name: metadata
path: build/metadata/
if-no-files-found: error
release-draft:
name: Update drafts for GitHub releases
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
needs: check
steps:
# Remove old release drafts
- name: Remove old release drafts
uses: actions/github-script@v7
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const response = await github.rest.repos.listReleases({owner, repo});
for (const draft of response.data.filter(r => r.draft)) {
core.info(`Delete draft for '${draft.name}' (${draft.id})`);
await github.rest.repos.deleteRelease({owner, repo, release_id: draft.id});
}
# Download build artifacts
- name: Download build result
uses: actions/download-artifact@v4
with:
name: build-result
path: build/distributions/
- name: Download metadata
uses: actions/download-artifact@v4
with:
name: metadata
path: build/metadata/
# Read metadata
- name: Read metadata
id: metadata
run: |
echo "version=$(cat build/metadata/version.txt)" >> "$GITHUB_OUTPUT"
echo "zipfile=$(cat build/metadata/zipfile.txt)" >> "$GITHUB_OUTPUT"
echo "zipname=$(basename "$(cat build/metadata/zipfile.txt)")" >> "$GITHUB_OUTPUT"
# Fail job if the release tag already exists and points to a different commit
- name: Check release tag
uses: actions/github-script@v7
env:
TAG_NAME: v${{ steps.metadata.outputs.version }}
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const tagname = process.env.TAG_NAME;
try {
const ref = `tags/${tagname}`
const response = await github.rest.git.getRef({owner, repo, ref});
if (response.data.object.sha === context.sha) {
core.info(`Tag '${tagname}' is already defined and points to the right commit.`);
core.info(`Commit: ${context.sha}`);
}
else {
core.setFailed(
`Tag '${tagname}' already exists but points to a different commit.\n` +
`You probably need to bump the version number.\n` +
`Tag points to: ${response.data.object.sha}\n` +
`Release commit: ${context.sha}`);
}
}
catch (e) {
if (e.status === 404) {
core.info(`Tag '${tagname}' is not yet defined.`);
}
else {
throw e;
}
}
# Create GitHub release draft
- name: Create GitHub release draft
uses: actions/github-script@v7
env:
TAG_NAME: v${{ steps.metadata.outputs.version }}
ZIP_FILE: ${{ steps.metadata.outputs.zipfile }}
ZIP_NAME: ${{ steps.metadata.outputs.zipname }}
with:
script: |
const fs = require('fs');
const owner = context.repo.owner;
const repo = context.repo.repo;
const { TAG_NAME, ZIP_FILE, ZIP_NAME } = process.env;
core.info(`Create new draft for '${TAG_NAME}'`);
const createResponse = await github.rest.repos.createRelease({
owner,
repo,
name: TAG_NAME,
tag_name: TAG_NAME,
target_commitish: context.sha,
body: fs.readFileSync('build/metadata/latest_changelog.md', 'utf8'),
draft: true,
});
core.info(`Upload build result; upload_url: ${createResponse.data.upload_url}`);
const uploadResponse = await github.rest.repos.uploadReleaseAsset({
url: createResponse.data.upload_url,
headers: {'Content-Type': 'application/zip'},
name: ZIP_NAME,
label: ZIP_NAME,
data: fs.readFileSync(ZIP_FILE),
});
core.info(`Upload complete; download_url: ${uploadResponse.data.browser_download_url}`);
core.info(`You can find the release draft at ${createResponse.data.html_url}`);