11# GitHub Actions Workflow is created for testing and preparing the plugin release in the following steps:
22# - Validate Gradle Wrapper.
33# - Run 'test' and 'verifyPlugin' tasks.
4- # - Run Qodana inspections.
54# - Run the 'buildPlugin' task and prepare artifact for further tests.
65# - Run the 'runPluginVerifier' task.
7- # - Create a draft release.
86#
97# The workflow is triggered on push and pull_request events.
108#
1412
1513name : Build
1614on :
17- # Trigger the workflow on pushes to only the 'main' branch (this avoids duplicate checks being run e.g., for dependabot pull requests)
1815 push :
19- branches : [ feture/sql-formatter, main ]
20- # Trigger the workflow on any pull request
16+ branches :
17+ - ' main'
18+ - ' feture/sql-formatter'
2119 pull_request :
2220
2321concurrency :
2422 group : ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
2523 cancel-in-progress : true
26-
24+
2725jobs :
2826
29- # Prepare environment and build the plugin
3027 build :
3128 name : Build
3229 runs-on : ubuntu-24.04
3330 outputs :
34- version : ${{ steps.properties.outputs.version }}
35- changelog : ${{ steps.properties.outputs.changelog }}
3631 pluginVerifierHomeDir : ${{ steps.properties.outputs.pluginVerifierHomeDir }}
3732 steps :
38-
39- # Check out the current repository
4033 - name : Fetch Sources
4134 uses : actions/checkout@v4
4235
43- # Validate wrapper
4436 - name : Gradle Wrapper Validation
4537 uses : gradle/actions/wrapper-validation@v4
4638
47- # Set up Java environment for the next steps
4839 - name : Setup Java
4940 uses : actions/setup-java@v4
5041 with :
5142 distribution : zulu
5243 java-version : 17
5344
54- # Setup Gradle
5545 - name : Setup Gradle
5646 uses : gradle/actions/setup-gradle@v4
5747
58- # Set environment variables
5948 - name : Export Properties
6049 id : properties
6150 shell : bash
6251 run : |
6352 PROPERTIES="$(./gradlew properties --console=plain -q)"
64- VERSION="$(echo "$PROPERTIES" | grep "^version:" | cut -f2- -d ' ')"
65- CHANGELOG="$(./gradlew getChangelog --unreleased --no-header --console=plain -q)"
66-
67- echo "version=$VERSION" >> $GITHUB_OUTPUT
6853 echo "pluginVerifierHomeDir=~/.pluginVerifier" >> $GITHUB_OUTPUT
69-
70- echo "changelog<<EOF" >> $GITHUB_OUTPUT
71- echo "$CHANGELOG" >> $GITHUB_OUTPUT
72- echo "EOF" >> $GITHUB_OUTPUT
7354
74- # Generate Lexer and Parser
55+ - name : Cache Lexer and Parser
56+ uses : actions/cache@v4
57+ id : cache-lexer-parser
58+ with :
59+ path : ${{ github.workspace }}/src/main/gen
60+ key : lexer-parser-${{ hashFiles('**/Sql.bnf','**/Sql.flex') }}
61+ restore-keys : |
62+ lexer-parser-
63+
7564 - name : Generate Lexer
65+ if : steps.cache-lexer-parser.outputs.cache-hit != 'true'
7666 run : ./gradlew generateLexer
7767
7868 - name : Generate Parser
69+ if : steps.cache-lexer-parser.outputs.cache-hit != 'true'
7970 run : ./gradlew generateParser
8071
81- # Build plugin
72+ - name : Build Gradle
73+ run : ./gradlew build -x test
74+
8275 - name : Build plugin
8376 run : ./gradlew buildPlugin -PpluginVersion=0.4.0-${{ github.run_number }}
8477
@@ -121,12 +114,24 @@ jobs:
121114 # Setup Gradle
122115 - name : Setup Gradle
123116 uses : gradle/actions/setup-gradle@v4
117+ with :
118+ cache-read-only : true
119+
120+ - name : Cache Lexer and Parser
121+ uses : actions/cache@v4
122+ id : cache-lexer-parser
123+ with :
124+ path : ${{ github.workspace }}/src/main/gen
125+ key : lexer-parser-${{ hashFiles('**/Sql.bnf','**/Sql.flex') }}
126+ restore-keys : |
127+ lexer-parser-
124128
125- # Generate Lexer and Parser
126129 - name : Generate Lexer
130+ if : steps.cache-lexer-parser.outputs.cache-hit != 'true'
127131 run : ./gradlew generateLexer
128132
129133 - name : Generate Parser
134+ if : steps.cache-lexer-parser.outputs.cache-hit != 'true'
130135 run : ./gradlew generateParser
131136
132137 # Run tests
@@ -147,53 +152,6 @@ jobs:
147152 with :
148153 files : ${{ github.workspace }}/build/reports/kover/report.xml
149154
150- # Run Qodana inspections and provide report
151- inspectCode :
152- name : Inspect code
153- needs : [ build ]
154- runs-on : ubuntu-24.04
155- permissions :
156- contents : write
157- checks : write
158- pull-requests : write
159- steps :
160-
161- # Free GitHub Actions Environment Disk Space
162- - name : Maximize Build Space
163- uses : jlumbroso/free-disk-space@main
164- with :
165- tool-cache : false
166- large-packages : false
167-
168- # Check out the current repository
169- - name : Fetch Sources
170- uses : actions/checkout@v4
171- with :
172- ref : ${{ github.event.pull_request.head.sha }} # to check out the actual pull request commit, not the merge commit
173- fetch-depth : 0 # a full history is required for pull request analysis
174-
175- # Set up Java environment for the next steps
176- - name : Setup Java
177- uses : actions/setup-java@v4
178- with :
179- distribution : zulu
180- java-version : 17
181-
182- # Generate Lexer and Parser
183- - name : Generate Lexer
184- run : ./gradlew generateLexer
185-
186- - name : Generate Parser
187- run : ./gradlew generateParser
188-
189- # Run Qodana inspections
190- - name : Qodana - Code Inspection
191- 192- with :
193- cache-default-branch-only : true
194- upload-result : true
195-
196- # Run plugin structure verification along with IntelliJ Plugin Verifier
197155 verify :
198156 name : Verify plugin
199157 needs : [ build ]
@@ -221,12 +179,24 @@ jobs:
221179 # Setup Gradle
222180 - name : Setup Gradle
223181 uses : gradle/actions/setup-gradle@v4
182+ with :
183+ cache-read-only : true
184+
185+ - name : Cache Lexer and Parser
186+ uses : actions/cache@v4
187+ id : cache-lexer-parser
188+ with :
189+ path : ${{ github.workspace }}/src/main/gen
190+ key : lexer-parser-${{ hashFiles('**/Sql.bnf','**/Sql.flex') }}
191+ restore-keys : |
192+ lexer-parser-
224193
225- # Generate Lexer and Parser
226194 - name : Generate Lexer
195+ if : steps.cache-lexer-parser.outputs.cache-hit != 'true'
227196 run : ./gradlew generateLexer
228197
229198 - name : Generate Parser
199+ if : steps.cache-lexer-parser.outputs.cache-hit != 'true'
230200 run : ./gradlew generateParser
231201
232202 # Cache Plugin Verifier IDEs
@@ -246,41 +216,4 @@ jobs:
246216 uses : actions/upload-artifact@v4
247217 with :
248218 name : pluginVerifier-result
249- path : ${{ github.workspace }}/build/reports/pluginVerifier
250-
251- # Prepare a draft release for GitHub Releases page for the manual verification
252- # If accepted and published, release workflow would be triggered
253- releaseDraft :
254- name : Release draft
255- if : github.event_name != 'pull_request'
256- needs : [ build, test, inspectCode, verify ]
257- runs-on : ubuntu-24.04
258- permissions :
259- contents : write
260- steps :
261-
262- # Check out the current repository
263- - name : Fetch Sources
264- uses : actions/checkout@v4
265-
266- # Remove old release drafts by using the curl request for the available releases with a draft flag
267- - name : Remove Old Release Drafts
268- env :
269- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
270- run : |
271- gh api repos/{owner}/{repo}/releases \
272- --jq '.[] | select(.draft == true) | .id' \
273- | xargs -I '{}' gh api -X DELETE repos/{owner}/{repo}/releases/{}
274-
275- # Create a new release draft which is not publicly visible and requires manual acceptance
276- - name : Create Release Draft
277- env :
278- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
279- run : |
280- gh release create "v${{ needs.build.outputs.version }}" \
281- --draft \
282- --title "v${{ needs.build.outputs.version }}" \
283- --notes "$(cat << 'EOM'
284- ${{ needs.build.outputs.changelog }}
285- EOM
286- )"
219+ path : ${{ github.workspace }}/build/reports/pluginVerifier
0 commit comments