Skip to content

Commit 23561cd

Browse files
Create gradle-publish.yml
1 parent 100e096 commit 23561cd

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

.github/workflows/gradle-publish.yml

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created
6+
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle
7+
8+
name: Gradle Package
9+
10+
on:
11+
release:
12+
types: [created] # 当创建 release 时触发
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
packages: write
20+
21+
steps:
22+
# Step 1: Checkout code
23+
- name: Checkout code
24+
uses: actions/checkout@v4
25+
26+
# Step 2: Set up JDK 17
27+
- name: Set up JDK 17
28+
uses: actions/setup-java@v4
29+
with:
30+
java-version: '17'
31+
distribution: 'temurin'
32+
server-id: github
33+
settings-path: ${{ github.workspace }}
34+
35+
# Step 3: Cache Gradle packages
36+
- name: Cache Gradle packages
37+
uses: actions/cache@v3
38+
with:
39+
path: |
40+
~/.gradle/caches
41+
~/.gradle/wrapper
42+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
43+
restore-keys: |
44+
${{ runner.os }}-gradle-
45+
46+
# Step 4: Setup Gradle
47+
- name: Setup Gradle
48+
uses: gradle/gradle-build-action@v2
49+
50+
# Step 5: Ensure gradlew is executable (add chmod)
51+
- name: Ensure gradlew is executable
52+
run: chmod +x ./gradlew
53+
54+
# Step 6: Build with Gradle
55+
- name: Build with Gradle
56+
run: ./gradlew build
57+
58+
# Step 7: Upload build artifacts
59+
- name: Upload Build Artifacts
60+
uses: actions/upload-artifact@v3
61+
with:
62+
name: build-artifacts
63+
path: ./build/libs/
64+
65+
# Step 8: Publish to GitHub Packages
66+
- name: Publish to GitHub Packages
67+
run: ./gradlew publish
68+
env:
69+
USERNAME: ${{ github.actor }}
70+
TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)