Skip to content

Commit 8324e20

Browse files
authored
Merge pull request #24 from Berkeley-CS61B/upgrade-build-dy
upgrade build workflow
2 parents 88ee92a + a17e97f commit 8324e20

File tree

3 files changed

+141
-79
lines changed

3 files changed

+141
-79
lines changed

.github/workflows/build.yml

Lines changed: 110 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,123 @@
1-
# GitHub Actions Workflow created for testing and preparing the plugin release in following steps:
2-
# - validate Gradle Wrapper,
3-
# - run 'test' and 'verifyPlugin' tasks,
4-
# - run Qodana inspections,
5-
# - run 'buildPlugin' task and prepare artifact for the further tests,
6-
# - run 'runPluginVerifier' task,
7-
# - create a draft release.
1+
# GitHub Actions Workflow is created for testing and preparing the plugin release in the following steps:
2+
# - Validate Gradle Wrapper.
3+
# - Run 'test' and 'verifyPlugin' tasks.
4+
# - Run Qodana inspections.
5+
# - Run the 'buildPlugin' task and prepare artifact for further tests.
6+
# - Run the 'runPluginVerifier' task.
7+
# - Create a draft release.
88
#
9-
# Workflow is triggered on push and pull_request events.
9+
# The workflow is triggered on push and pull_request events.
1010
#
1111
# GitHub Actions reference: https://help.github.com/en/actions
1212
#
1313
## JBIJPPTPL
1414

1515
name: Build
1616
on:
17-
# Trigger the workflow on pushes to only the 'main' branch (this avoids duplicate checks being run e.g. for dependabot pull requests)
17+
# Trigger the workflow on pushes to only the 'main' branch (this avoids duplicate checks being run e.g., for dependabot pull requests)
1818
push:
19-
branches: [master]
19+
branches: [ master ]
2020
# Trigger the workflow on any pull request
2121
pull_request:
2222

23+
concurrency:
24+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
25+
cancel-in-progress: true
26+
2327
jobs:
2428

25-
# Run Gradle Wrapper Validation Action to verify the wrapper's checksum
26-
# Run verifyPlugin, IntelliJ Plugin Verifier, and test Gradle tasks
27-
# Build plugin and provide the artifact for the next workflow jobs
29+
# Prepare environment and build the plugin
2830
build:
2931
name: Build
3032
runs-on: ubuntu-latest
3133
outputs:
3234
version: ${{ steps.properties.outputs.version }}
3335
changelog: ${{ steps.properties.outputs.changelog }}
36+
pluginVerifierHomeDir: ${{ steps.properties.outputs.pluginVerifierHomeDir }}
3437
steps:
3538

36-
37-
38-
# Check out current repository
39+
# Check out the current repository
3940
- name: Fetch Sources
4041
uses: actions/checkout@v4
4142

4243
# Validate wrapper
4344
- name: Gradle Wrapper Validation
44-
uses: gradle/wrapper-validation-action@v3
45+
uses: gradle/actions/wrapper-validation@v3
4546

46-
# Setup Java 17 environment for the next steps
47+
# Set up Java environment for the next steps
4748
- name: Setup Java
4849
uses: actions/setup-java@v4
4950
with:
5051
distribution: zulu
5152
java-version: 17
5253

54+
# Setup Gradle
55+
- name: Setup Gradle
56+
uses: gradle/actions/setup-gradle@v4
57+
5358
# Set environment variables
5459
- name: Export Properties
5560
id: properties
5661
shell: bash
5762
run: |
5863
PROPERTIES="$(./gradlew properties --console=plain -q)"
5964
VERSION="$(echo "$PROPERTIES" | grep "^version:" | cut -f2- -d ' ')"
60-
NAME="$(echo "$PROPERTIES" | grep "^pluginName:" | cut -f2- -d ' ')"
6165
CHANGELOG="$(./gradlew getChangelog --unreleased --no-header --console=plain -q)"
62-
CHANGELOG="${CHANGELOG//'%'/'%25'}"
63-
CHANGELOG="${CHANGELOG//$'\n'/'%0A'}"
64-
CHANGELOG="${CHANGELOG//$'\r'/'%0D'}"
6566
66-
echo "::set-output name=version::$VERSION"
67-
echo "::set-output name=name::$NAME"
68-
echo "::set-output name=changelog::$CHANGELOG"
69-
echo "::set-output name=pluginVerifierHomeDir::~/.pluginVerifier"
67+
echo "version=$VERSION" >> $GITHUB_OUTPUT
68+
echo "pluginVerifierHomeDir=~/.pluginVerifier" >> $GITHUB_OUTPUT
69+
70+
echo "changelog<<EOF" >> $GITHUB_OUTPUT
71+
echo "$CHANGELOG" >> $GITHUB_OUTPUT
72+
echo "EOF" >> $GITHUB_OUTPUT
7073
71-
./gradlew listProductsReleases # prepare list of IDEs for Plugin Verifier
74+
# Build plugin
75+
- name: Build plugin
76+
run: ./gradlew buildPlugin
77+
78+
# Prepare plugin archive content for creating artifact
79+
- name: Prepare Plugin Artifact
80+
id: artifact
81+
shell: bash
82+
run: |
83+
cd ${{ github.workspace }}/build/distributions
84+
FILENAME=`ls *.zip`
85+
unzip "$FILENAME" -d content
86+
87+
echo "filename=${FILENAME:0:-4}" >> $GITHUB_OUTPUT
88+
89+
# Store already-built plugin as an artifact for downloading
90+
- name: Upload artifact
91+
uses: actions/upload-artifact@v4
92+
with:
93+
name: ${{ steps.artifact.outputs.filename }}
94+
path: ./build/distributions/content/*/*
95+
96+
# Run tests and upload a code coverage report
97+
test:
98+
name: Test
99+
needs: [ build ]
100+
runs-on: ubuntu-latest
101+
steps:
102+
103+
# Check out the current repository
104+
- name: Fetch Sources
105+
uses: actions/checkout@v4
106+
107+
# Set up Java environment for the next steps
108+
- name: Setup Java
109+
uses: actions/setup-java@v4
110+
with:
111+
distribution: zulu
112+
java-version: 17
113+
114+
# Setup Gradle
115+
- name: Setup Gradle
116+
uses: gradle/actions/setup-gradle@v4
72117

73118
# Run tests
74119
- name: Run Tests
75-
run: ./gradlew test
120+
run: ./gradlew check
76121

77122
# Collect Tests Result of failed tests
78123
- name: Collect Tests Result
@@ -82,31 +127,51 @@ jobs:
82127
name: tests-result
83128
path: ${{ github.workspace }}/build/reports/tests
84129

130+
# Upload the Kover report to CodeCov
131+
- name: Upload Code Coverage Report
132+
uses: codecov/codecov-action@v4
133+
with:
134+
files: ${{ github.workspace }}/build/reports/kover/report.xml
135+
136+
# Run plugin structure verification along with IntelliJ Plugin Verifier
137+
verify:
138+
name: Verify plugin
139+
needs: [ build ]
140+
runs-on: ubuntu-latest
141+
steps:
142+
85143
# Free GitHub Actions Environment Disk Space
86144
- name: Maximize Build Space
87-
uses: jlumbroso/free-disk-space@v1.3.1
145+
uses: jlumbroso/free-disk-space@main
88146
with:
89147
tool-cache: false
90148
large-packages: false
91149

92-
- name: Clean up disk space
93-
run: |
94-
sudo rm -rf /usr/share/dotnet
95-
sudo rm -rf /usr/local/lib/android
96-
sudo rm -rf /opt/ghc
150+
# Check out the current repository
151+
- name: Fetch Sources
152+
uses: actions/checkout@v4
153+
154+
# Set up Java environment for the next steps
155+
- name: Setup Java
156+
uses: actions/setup-java@v4
157+
with:
158+
distribution: zulu
159+
java-version: 17
160+
161+
# Setup Gradle
162+
- name: Setup Gradle
163+
uses: gradle/actions/setup-gradle@v4
97164

98165
# Cache Plugin Verifier IDEs
99166
- name: Setup Plugin Verifier IDEs Cache
100167
uses: actions/cache@v4
101168
with:
102-
path: ${{ steps.properties.outputs.pluginVerifierHomeDir }}/ides
169+
path: ${{ needs.build.outputs.pluginVerifierHomeDir }}/ides
103170
key: plugin-verifier-${{ hashFiles('build/listProductsReleases.txt') }}
104171

105172
# Run Verify Plugin task and IntelliJ Plugin Verifier tool
106173
- name: Run Plugin Verification tasks
107-
run: |
108-
sudo df -h
109-
./gradlew runPluginVerifier -Pplugin.verifier.home.dir=${{ steps.properties.outputs.pluginVerifierHomeDir }}
174+
run: ./gradlew verifyPlugin -Dplugin.verifier.home.dir=${{ needs.build.outputs.pluginVerifierHomeDir }}
110175

111176
# Collect Plugin Verifier Result
112177
- name: Collect Plugin Verifier Result
@@ -116,40 +181,22 @@ jobs:
116181
name: pluginVerifier-result
117182
path: ${{ github.workspace }}/build/reports/pluginVerifier
118183

119-
# Prepare plugin archive content for creating artifact
120-
- name: Prepare Plugin Artifact
121-
id: artifact
122-
shell: bash
123-
run: |
124-
cd ${{ github.workspace }}/build/distributions
125-
FILENAME=`ls *.zip`
126-
unzip "$FILENAME" -d content
127-
128-
echo "::set-output name=filename::${FILENAME:0:-4}"
129-
130-
# Store already-built plugin as an artifact for downloading
131-
- name: Upload artifact
132-
uses: actions/upload-artifact@v4
133-
with:
134-
name: ${{ steps.artifact.outputs.filename }}
135-
path: ./build/distributions/content/*/*
136-
137184
# Prepare a draft release for GitHub Releases page for the manual verification
138185
# If accepted and published, release workflow would be triggered
139186
releaseDraft:
140-
name: Release Draft
187+
name: Release draft
141188
if: github.event_name != 'pull_request'
142-
needs: build
189+
needs: [ build, test, verify ]
143190
runs-on: ubuntu-latest
144191
permissions:
145192
contents: write
146193
steps:
147194

148-
# Check out current repository
195+
# Check out the current repository
149196
- name: Fetch Sources
150197
uses: actions/checkout@v4
151198

152-
# Remove old release drafts by using the curl request for the available releases with draft flag
199+
# Remove old release drafts by using the curl request for the available releases with a draft flag
153200
- name: Remove Old Release Drafts
154201
env:
155202
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -158,15 +205,15 @@ jobs:
158205
--jq '.[] | select(.draft == true) | .id' \
159206
| xargs -I '{}' gh api -X DELETE repos/{owner}/{repo}/releases/{}
160207
161-
# Create new release draft - which is not publicly visible and requires manual acceptance
208+
# Create a new release draft which is not publicly visible and requires manual acceptance
162209
- name: Create Release Draft
163210
env:
164211
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
165212
run: |
166-
gh release create v${{ needs.build.outputs.version }} \
213+
gh release create "v${{ needs.build.outputs.version }}" \
167214
--draft \
168215
--title "v${{ needs.build.outputs.version }}" \
169216
--notes "$(cat << 'EOM'
170217
${{ needs.build.outputs.changelog }}
171218
EOM
172-
)"
219+
)"

src/main/java/edu/berkeley/cs61b/plugin/CheckStyleAction.java

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
package edu.berkeley.cs61b.plugin;
22

3+
import java.io.BufferedReader;
4+
import java.io.File;
5+
import java.io.IOException;
6+
import java.io.InputStream;
7+
import java.io.InputStreamReader;
8+
import java.nio.file.Path;
9+
import java.nio.file.Paths;
10+
import java.util.ArrayList;
11+
import java.util.Collections;
12+
import java.util.LinkedList;
13+
import java.util.List;
14+
15+
import org.jetbrains.annotations.NotNull;
16+
import org.xml.sax.InputSource;
17+
318
import com.intellij.execution.filters.OpenFileHyperlinkInfo;
419
import com.intellij.execution.ui.ConsoleView;
520
import com.intellij.execution.ui.ConsoleViewContentType;
21+
import com.intellij.openapi.actionSystem.ActionUpdateThread;
622
import com.intellij.openapi.actionSystem.AnAction;
723
import com.intellij.openapi.actionSystem.AnActionEvent;
824
import com.intellij.openapi.actionSystem.CommonDataKeys;
@@ -20,19 +36,6 @@
2036
import com.puppycrawl.tools.checkstyle.api.AuditEvent;
2137
import com.puppycrawl.tools.checkstyle.api.AuditListener;
2238
import com.puppycrawl.tools.checkstyle.api.Configuration;
23-
import org.xml.sax.InputSource;
24-
25-
import java.io.BufferedReader;
26-
import java.io.File;
27-
import java.io.IOException;
28-
import java.io.InputStream;
29-
import java.io.InputStreamReader;
30-
import java.nio.file.Path;
31-
import java.nio.file.Paths;
32-
import java.util.ArrayList;
33-
import java.util.Collections;
34-
import java.util.LinkedList;
35-
import java.util.List;
3639

3740
public class CheckStyleAction extends AnAction {
3841
private static final String CONFIG_ROOT = "style_config/";
@@ -84,6 +87,11 @@ public void actionPerformed(AnActionEvent event) {
8487
}
8588
}
8689

90+
@Override
91+
public @NotNull ActionUpdateThread getActionUpdateThread() {
92+
return ActionUpdateThread.BGT;
93+
}
94+
8795
private void collectFiles(VirtualFile[] parent, List<File> list) {
8896
LinkedList<VirtualFile> sources = new LinkedList<>();
8997
Collections.addAll(sources, parent);
@@ -222,4 +230,4 @@ public void addError(AuditEvent e) {
222230
public void addException(AuditEvent e, Throwable throwable) {
223231
}
224232
}
225-
}
233+
}

src/main/java/edu/berkeley/cs61b/plugin/SettingsAction.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package edu.berkeley.cs61b.plugin;
22

3+
import org.jetbrains.annotations.NotNull;
4+
35
import com.intellij.ide.util.PropertiesComponent;
6+
import com.intellij.openapi.actionSystem.ActionUpdateThread;
47
import com.intellij.openapi.actionSystem.AnAction;
58
import com.intellij.openapi.actionSystem.AnActionEvent;
69
import com.intellij.openapi.ui.DialogWrapper;
7-
import org.jetbrains.annotations.NotNull;
810

911
public class SettingsAction extends AnAction {
1012
@Override
@@ -19,4 +21,9 @@ public void actionPerformed(@NotNull AnActionEvent e) {
1921
props.setValue(PluginUtils.KEY_SEMESTER, form.getSemesterField().getText());
2022
}
2123
}
22-
}
24+
25+
@Override
26+
public @NotNull ActionUpdateThread getActionUpdateThread() {
27+
return ActionUpdateThread.BGT;
28+
}
29+
}

0 commit comments

Comments
 (0)