-
Notifications
You must be signed in to change notification settings - Fork 22
90 lines (79 loc) · 2.83 KB
/
gradle-publish.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: Gradle Plugin Release
on:
release:
types: [created]
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Build Plugin with Gradle
run: ./gradlew buildPlugin
- name: Get Previous Tag
id: previous_tag
uses: actions/github-script@v6
with:
script: |
const { data: tags } = await github.rest.repos.listTags({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 2,
});
if (tags.length < 2) {
core.setFailed("Not enough tags to generate release notes.");
} else {
core.setOutput("previous_tag", tags[1].name);
}
- name: Generate Release Notes
id: generate_notes
uses: actions/github-script@v6
with:
script: |
const previousTag = "${{ steps.previous_tag.outputs.previous_tag }}";
const currentTag = "${{ github.event.release.tag_name }}";
const { data: commits } = await github.rest.repos.compareCommits({
owner: context.repo.owner,
repo: context.repo.repo,
base: previousTag,
head: currentTag,
});
let releaseNotes = '### Changelog\n\n';
commits.commits.forEach(commit => {
releaseNotes += `- ${commit.commit.message}\n`;
});
core.setOutput("notes", releaseNotes);
- name: Update Release with Notes
uses: actions/github-script@v6
with:
script: |
const { data: release } = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: context.payload.release.tag_name,
});
await github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.id,
body: `${{ steps.generate_notes.outputs.notes }}`,
});
- name: Upload Plugin to GitHub Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./build/libs/SecurityInspector-${{ github.event.release.tag_name }}.jar
asset_name: SecurityInspector-${{ github.event.release.tag_name }}.jar
asset_content_type: application/java-archive