Skip to content

Commit 42bccbc

Browse files
committed
Add build GH action
1 parent a77d731 commit 42bccbc

File tree

1 file changed

+157
-0
lines changed

1 file changed

+157
-0
lines changed

Diff for: .github/workflows/build.yml

+157
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
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.
8+
#
9+
# Workflow is triggered on push and pull_request events.
10+
#
11+
# GitHub Actions reference: https://help.github.com/en/actions
12+
#
13+
## JBIJPPTPL
14+
15+
name: Build
16+
on:
17+
# Trigger the workflow on pushes to only the 'main' branch (this avoids duplicate checks being run e.g. for dependabot pull requests)
18+
push:
19+
branches: [main]
20+
# Trigger the workflow on any pull request
21+
pull_request:
22+
23+
jobs:
24+
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
28+
build:
29+
name: Build
30+
runs-on: ubuntu-latest
31+
outputs:
32+
version: ${{ steps.properties.outputs.version }}
33+
changelog: ${{ steps.properties.outputs.changelog }}
34+
steps:
35+
36+
# Check out current repository
37+
- name: Fetch Sources
38+
uses: actions/[email protected]
39+
40+
# Validate wrapper
41+
- name: Gradle Wrapper Validation
42+
uses: gradle/[email protected]
43+
44+
# Setup Java 11 environment for the next steps
45+
- name: Setup Java
46+
uses: actions/setup-java@v2
47+
with:
48+
distribution: zulu
49+
java-version: 11
50+
cache: gradle
51+
52+
# Set environment variables
53+
- name: Export Properties
54+
id: properties
55+
shell: bash
56+
run: |
57+
PROPERTIES="$(./gradlew properties --console=plain -q)"
58+
VERSION="$(echo "$PROPERTIES" | grep "^version:" | cut -f2- -d ' ')"
59+
NAME="$(echo "$PROPERTIES" | grep "^pluginName:" | cut -f2- -d ' ')"
60+
CHANGELOG="$(./gradlew getChangelog --unreleased --no-header --console=plain -q)"
61+
CHANGELOG="${CHANGELOG//'%'/'%25'}"
62+
CHANGELOG="${CHANGELOG//$'\n'/'%0A'}"
63+
CHANGELOG="${CHANGELOG//$'\r'/'%0D'}"
64+
65+
echo "::set-output name=version::$VERSION"
66+
echo "::set-output name=name::$NAME"
67+
echo "::set-output name=changelog::$CHANGELOG"
68+
echo "::set-output name=pluginVerifierHomeDir::~/.pluginVerifier"
69+
70+
./gradlew listProductsReleases # prepare list of IDEs for Plugin Verifier
71+
72+
# Run tests
73+
- name: Run Tests
74+
run: ./gradlew test
75+
76+
# Collect Tests Result of failed tests
77+
- name: Collect Tests Result
78+
if: ${{ failure() }}
79+
uses: actions/upload-artifact@v2
80+
with:
81+
name: tests-result
82+
path: ${{ github.workspace }}/build/reports/tests
83+
84+
# # Cache Plugin Verifier IDEs
85+
# - name: Setup Plugin Verifier IDEs Cache
86+
# uses: actions/[email protected]
87+
# with:
88+
# path: ${{ steps.properties.outputs.pluginVerifierHomeDir }}/ides
89+
# key: plugin-verifier-${{ hashFiles('build/listProductsReleases.txt') }}
90+
#
91+
# # Run Verify Plugin task and IntelliJ Plugin Verifier tool
92+
# - name: Run Plugin Verification tasks
93+
# run: ./gradlew runPluginVerifier -Pplugin.verifier.home.dir=${{ steps.properties.outputs.pluginVerifierHomeDir }}
94+
#
95+
# # Collect Plugin Verifier Result
96+
# - name: Collect Plugin Verifier Result
97+
# if: ${{ always() }}
98+
# uses: actions/upload-artifact@v2
99+
# with:
100+
# name: pluginVerifier-result
101+
# path: ${{ github.workspace }}/build/reports/pluginVerifier
102+
103+
# TODO: temp needed because verifier disabled
104+
- run: ./gradlew buildPlugin
105+
106+
# Prepare plugin archive content for creating artifact
107+
- name: Prepare Plugin Artifact
108+
id: artifact
109+
shell: bash
110+
run: |
111+
cd ${{ github.workspace }}/build/distributions
112+
FILENAME=`ls *.zip`
113+
unzip "$FILENAME" -d content
114+
115+
echo "::set-output name=filename::${FILENAME:0:-4}"
116+
117+
# Store already-built plugin as an artifact for downloading
118+
- name: Upload artifact
119+
uses: actions/[email protected]
120+
with:
121+
name: ${{ steps.artifact.outputs.filename }}
122+
path: ./build/distributions/content/*/*
123+
124+
# Prepare a draft release for GitHub Releases page for the manual verification
125+
# If accepted and published, release workflow would be triggered
126+
releaseDraft:
127+
name: Release Draft
128+
if: github.event_name != 'pull_request'
129+
needs: build
130+
runs-on: ubuntu-latest
131+
steps:
132+
133+
# Check out current repository
134+
- name: Fetch Sources
135+
uses: actions/[email protected]
136+
137+
# Remove old release drafts by using the curl request for the available releases with draft flag
138+
- name: Remove Old Release Drafts
139+
env:
140+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
141+
run: |
142+
gh api repos/{owner}/{repo}/releases \
143+
--jq '.[] | select(.draft == true) | .id' \
144+
| xargs -I '{}' gh api -X DELETE repos/{owner}/{repo}/releases/{}
145+
146+
# Create new release draft - which is not publicly visible and requires manual acceptance
147+
- name: Create Release Draft
148+
env:
149+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
150+
run: |
151+
gh release create v${{ needs.build.outputs.version }} \
152+
--draft \
153+
--title "v${{ needs.build.outputs.version }}" \
154+
--notes "$(cat << 'EOM'
155+
${{ needs.build.outputs.changelog }}
156+
EOM
157+
)"

0 commit comments

Comments
 (0)