1+ name : ' Create Release'
2+
3+ on :
4+ push :
5+ branches :
6+ - master
7+
8+ jobs :
9+ create-release :
10+ runs-on : ubuntu-latest
11+ steps :
12+ - uses : actions/checkout@v4
13+ with :
14+ fetch-depth : 0
15+
16+ - name : Extract version
17+ id : extract_version
18+ run : |
19+ # First try to get version from commit message
20+ VERSION=$(echo "${{ github.event.head_commit.message }}" | grep -o 'v[0-9]\+\.[0-9]\+\.[0-9]\+' | sed 's/^v//')
21+
22+ # If no version in commit message, try to get it from gradle.properties
23+ if [ -z "$VERSION" ]; then
24+ if [ -f "gradle.properties" ]; then
25+ # Use dos2unix to handle line endings and remove any trailing whitespace
26+ VERSION=$(grep "^plugin_version=" gradle.properties | cut -d'=' -f2 | tr -d '\r' | xargs)
27+ if [ -z "$VERSION" ]; then
28+ echo "Error: No plugin_version found in gradle.properties"
29+ cat gradle.properties
30+ exit 1
31+ fi
32+ # Convert version format from v2.3.8.212.0 to v2.3.8
33+ VERSION=$(echo "$VERSION" | sed -E 's/^v?([0-9]+\.[0-9]+\.[0-9]+).*$/\1/')
34+ else
35+ echo "Error: gradle.properties file not found"
36+ exit 1
37+ fi
38+ fi
39+
40+ # Add 'v' prefix if not present
41+ if [[ ! "$VERSION" =~ ^v ]]; then
42+ VERSION="v$VERSION"
43+ fi
44+
45+ echo "Extracted version: $VERSION"
46+ echo "version=$VERSION" >> $GITHUB_OUTPUT
47+
48+ - name : Check if tag exists
49+ id : check_tag
50+ run : |
51+ if git tag -l "${{ steps.extract_version.outputs.version }}" | grep -q "${{ steps.extract_version.outputs.version }}"; then
52+ echo "Tag ${{ steps.extract_version.outputs.version }} already exists. Skipping release creation."
53+ echo "skip=true" >> $GITHUB_OUTPUT
54+ else
55+ echo "Tag ${{ steps.extract_version.outputs.version }} does not exist. Proceeding with release creation."
56+ echo "skip=false" >> $GITHUB_OUTPUT
57+ fi
58+
59+ - name : Set up JDK
60+ if : steps.check_tag.outputs.skip == 'false'
61+ uses : actions/setup-java@v4
62+ with :
63+ java-version : ' 11'
64+ distribution : ' zulu'
65+ cache : gradle
66+
67+ - name : Package Plugin
68+ if : steps.check_tag.outputs.skip == 'false'
69+ run : |
70+ chmod +x plugin-script/package_plugin.sh
71+ ./plugin-script/package_plugin.sh
72+
73+ - name : Generate Release Notes
74+ if : steps.check_tag.outputs.skip == 'false'
75+ id : generate_notes
76+ run : |
77+ # Get the previous tag
78+ PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "v0.0.0")
79+ CURRENT_TAG=${{ steps.extract_version.outputs.version }}
80+
81+ # Generate the release notes
82+ NOTES="**Full Changelog**: https://github.com/${{ github.repository }}/compare/${PREV_TAG}...${CURRENT_TAG}\n\n"
83+
84+ # Add commit messages since last tag
85+ COMMITS=$(git log --pretty=format:"* %s" $PREV_TAG..HEAD | grep -E '^\* (refactor|feat|fix)')
86+ NOTES="${NOTES}${COMMITS}\n\n"
87+
88+ # Add the plugin support table
89+ NOTES="${NOTES}---\n\n"
90+ NOTES="${NOTES}| plugin | support |\n"
91+ NOTES="${NOTES}| ------------ | ------------ |\n"
92+ # Remove 'v' prefix for the download link
93+ DOWNLOAD_VERSION=$(echo "$CURRENT_TAG" | sed 's/^v//')
94+ NOTES="${NOTES}| [easy-yapi-${DOWNLOAD_VERSION}.212.0.zip](https://github.com/${{ github.repository }}/releases/download/${CURRENT_TAG}/easy-yapi-${DOWNLOAD_VERSION}.212.0.zip) | idea 2021.2+ |\n"
95+
96+ echo "notes<<EOF" >> $GITHUB_OUTPUT
97+ echo -e "$NOTES" >> $GITHUB_OUTPUT
98+ echo "EOF" >> $GITHUB_OUTPUT
99+
100+ - name : Create Release
101+ uses : softprops/action-gh-release@v1
102+ if : contains(github.event.head_commit.message, 'release') && steps.check_tag.outputs.skip == 'false'
103+ env :
104+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
105+ with :
106+ tag_name : ${{ steps.extract_version.outputs.version }}
107+ name : ${{ steps.extract_version.outputs.version }}
108+ body : ${{ steps.generate_notes.outputs.notes }}
109+ draft : true
110+ prerelease : true
111+ files : |
112+ plugin/easy-yapi-*.zip
0 commit comments