Skip to content

Commit 5d80bde

Browse files
committed
build: github workflow to build, run tests and publish release draft
- builds the zip and runs the unit tests
1 parent 8e23671 commit 5d80bde

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed

.github/workflows/build.yml

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# GitHub Actions workflow for testing and preparing the plugin release.
2+
# GitHub Actions reference: https://help.github.com/en/actions
3+
4+
name: Coder Toolbox Plugin Build
5+
6+
on:
7+
push:
8+
branches:
9+
- main
10+
pull_request:
11+
12+
jobs:
13+
# Run plugin tests on every supported platform.
14+
test:
15+
strategy:
16+
matrix:
17+
platform:
18+
- ubuntu-latest
19+
- macos-latest
20+
- windows-latest
21+
runs-on: ${{ matrix.platform }}
22+
steps:
23+
- uses: actions/[email protected]
24+
25+
- uses: actions/setup-java@v4
26+
with:
27+
distribution: zulu
28+
java-version: 21
29+
cache: gradle
30+
31+
- uses: gradle/[email protected]
32+
33+
# Run tests
34+
- run: ./gradlew test --info
35+
36+
# Collect Tests Result of failed tests
37+
- if: ${{ failure() }}
38+
uses: actions/upload-artifact@v4
39+
with:
40+
name: tests-result
41+
path: ${{ github.workspace }}/build/reports/tests
42+
43+
build:
44+
name: Build
45+
needs: test
46+
runs-on: ubuntu-latest
47+
outputs:
48+
version: ${{ steps.properties.outputs.version }}
49+
changelog: ${{ steps.properties.outputs.changelog }}
50+
steps:
51+
# Check out current repository
52+
- name: Fetch Sources
53+
uses: actions/[email protected]
54+
55+
# Setup Java 21 environment for the next steps
56+
- name: Setup Java
57+
uses: actions/setup-java@v4
58+
with:
59+
distribution: zulu
60+
java-version: 21
61+
cache: gradle
62+
63+
# Set environment variables
64+
- name: Export Properties
65+
id: properties
66+
shell: bash
67+
run: |
68+
PROPERTIES="$(./gradlew properties --console=plain -q)"
69+
VERSION="$(echo "$PROPERTIES" | grep "^version:" | cut -f2- -d ' ')"
70+
NAME="$(echo "$PROPERTIES" | grep "^group:" | cut -f2- -d ' ')"
71+
CHANGELOG="$(./gradlew getChangelog --unreleased --no-header --console=plain -q)"
72+
CHANGELOG="${CHANGELOG//'%'/'%25'}"
73+
CHANGELOG="${CHANGELOG//$'\n'/'%0A'}"
74+
CHANGELOG="${CHANGELOG//$'\r'/'%0D'}"
75+
echo "::set-output name=version::$VERSION"
76+
echo "::set-output name=name::$NAME"
77+
echo "::set-output name=changelog::$CHANGELOG"
78+
79+
# Run plugin build
80+
- name: Run Build
81+
run: ./gradlew clean buildZip --info
82+
83+
# Prepare plugin archive content for creating artifact
84+
- name: Prepare Plugin Artifact
85+
id: artifact
86+
shell: bash
87+
run: |
88+
cd ${{ github.workspace }}/build/distributions
89+
FILENAME=`ls *.zip`
90+
unzip "$FILENAME" -d content
91+
echo "::set-output name=filename::${FILENAME:0:-4}"
92+
# Store already-built plugin as an artifact for downloading
93+
- name: Upload artifact
94+
uses: actions/upload-artifact@v4
95+
with:
96+
name: ${{ steps.artifact.outputs.filename }}
97+
path: ./build/distributions/content/*/*
98+
99+
# Prepare a draft release for GitHub Releases page for the manual verification
100+
# If accepted and published, release workflow would be triggered
101+
releaseDraft:
102+
name: Release Draft
103+
if: github.event_name != 'pull_request'
104+
needs: build
105+
runs-on: ubuntu-latest
106+
steps:
107+
108+
# Check out current repository
109+
- name: Fetch Sources
110+
uses: actions/[email protected]
111+
112+
# Remove old release drafts by using the curl request for the available releases with draft flag
113+
- name: Remove Old Release Drafts
114+
env:
115+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
116+
run: |
117+
gh api repos/{owner}/{repo}/releases \
118+
--jq '.[] | select(.draft == true) | .id' \
119+
| xargs -I '{}' gh api -X DELETE repos/{owner}/{repo}/releases/{}
120+
# Create new release draft - which is not publicly visible and requires manual acceptance
121+
- name: Create Release Draft
122+
env:
123+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
124+
run: |
125+
gh release create v${{ needs.build.outputs.version }} \
126+
--draft \
127+
--target ${GITHUB_REF_NAME} \
128+
--title "v${{ needs.build.outputs.version }}" \
129+
--notes "$(cat << 'EOM'
130+
${{ needs.build.outputs.changelog }}
131+
EOM
132+
)"

0 commit comments

Comments
 (0)